From 6424192cdcb34ff2ea57a19b5ee41bf4bf68870c Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Thu, 16 Jan 2025 13:29:35 +0700 Subject: push --- indoteknik_custom/models/product_template.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indoteknik_custom/models/product_template.py') diff --git a/indoteknik_custom/models/product_template.py b/indoteknik_custom/models/product_template.py index 5bedae13..29608297 100755 --- a/indoteknik_custom/models/product_template.py +++ b/indoteknik_custom/models/product_template.py @@ -416,7 +416,7 @@ class ProductProduct(models.Model): box_size=5, border=4, ) - qr.add_data(rec.default_code) + qr.add_data(rec.barcode if rec.barcode else rec.default_code) qr.make(fit=True) img = qr.make_image(fill_color="black", back_color="white") -- cgit v1.2.3 From dcbd88ea9ea1977c047425e31559fb2e5cee3de2 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Thu, 30 Jan 2025 10:53:45 +0700 Subject: add validation on write and create function --- indoteknik_custom/models/product_template.py | 34 ++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'indoteknik_custom/models/product_template.py') diff --git a/indoteknik_custom/models/product_template.py b/indoteknik_custom/models/product_template.py index 29608297..d4b0abf4 100755 --- a/indoteknik_custom/models/product_template.py +++ b/indoteknik_custom/models/product_template.py @@ -67,6 +67,23 @@ class ProductTemplate(models.Model): print_barcode = fields.Boolean(string='Print Barcode', default=True) # qr_code = fields.Binary("QR Code", compute='_compute_qr_code') + @api.model + def create(self, vals): + group_id = self.env.ref('indoteknik_custom.group_role_merchandiser').id + users_in_group = self.env['res.users'].search([('groups_id', 'in', [group_id])]) + if self.env.user.id not in users_in_group.mapped('id'): + raise UserError('Hanya MD yang bisa membuat Product') + result = super(ProductTemplate, self).create(vals) + return result + + def write(self, values): + group_id = self.env.ref('indoteknik_custom.group_role_merchandiser').id + users_in_group = self.env['res.users'].search([('groups_id', 'in', [group_id])]) + if self.env.user.id not in users_in_group.mapped('id'): + raise UserError('Hanya MD yang bisa mengedit Product') + result = super(ProductTemplate, self).write(values) + return result + # def _compute_qr_code(self): # for rec in self.product_variant_ids: # qr = qrcode.QRCode( @@ -403,6 +420,23 @@ class ProductProduct(models.Model): merchandise_ok = fields.Boolean(string='Product Promotion') qr_code_variant = fields.Binary("QR Code Variant", compute='_compute_qr_code_variant') + @api.model + def create(self, vals): + group_id = self.env.ref('indoteknik_custom.group_role_merchandiser').id + users_in_group = self.env['res.users'].search([('groups_id', 'in', [group_id])]) + if self.env.user.id not in users_in_group.mapped('id'): + raise UserError('Hanya MD yang bisa membuat Product') + result = super(ProductProduct, self).create(vals) + return result + + def write(self, values): + group_id = self.env.ref('indoteknik_custom.group_role_merchandiser').id + users_in_group = self.env['res.users'].search([('groups_id', 'in', [group_id])]) + if self.env.user.id not in users_in_group.mapped('id'): + raise UserError('Hanya MD yang bisa mengedit Product') + result = super(ProductProduct, self).write(values) + return result + def _compute_qr_code_variant(self): for rec in self: # Skip inactive variants -- cgit v1.2.3 From f50f7d570eaa66552e6e91cfd9a29942a7ea3c36 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Thu, 30 Jan 2025 11:00:36 +0700 Subject: fix bug --- indoteknik_custom/models/product_template.py | 60 ++++++++++++++-------------- 1 file changed, 30 insertions(+), 30 deletions(-) (limited to 'indoteknik_custom/models/product_template.py') diff --git a/indoteknik_custom/models/product_template.py b/indoteknik_custom/models/product_template.py index d4b0abf4..151513e8 100755 --- a/indoteknik_custom/models/product_template.py +++ b/indoteknik_custom/models/product_template.py @@ -67,22 +67,22 @@ class ProductTemplate(models.Model): print_barcode = fields.Boolean(string='Print Barcode', default=True) # qr_code = fields.Binary("QR Code", compute='_compute_qr_code') - @api.model - def create(self, vals): - group_id = self.env.ref('indoteknik_custom.group_role_merchandiser').id - users_in_group = self.env['res.users'].search([('groups_id', 'in', [group_id])]) - if self.env.user.id not in users_in_group.mapped('id'): - raise UserError('Hanya MD yang bisa membuat Product') - result = super(ProductTemplate, self).create(vals) - return result + # @api.model + # def create(self, vals): + # group_id = self.env.ref('indoteknik_custom.group_role_merchandiser').id + # users_in_group = self.env['res.users'].search([('groups_id', 'in', [group_id])]) + # if self.env.user.id not in users_in_group.mapped('id'): + # raise UserError('Hanya MD yang bisa membuat Product') + # result = super(ProductTemplate, self).create(vals) + # return result - def write(self, values): - group_id = self.env.ref('indoteknik_custom.group_role_merchandiser').id - users_in_group = self.env['res.users'].search([('groups_id', 'in', [group_id])]) - if self.env.user.id not in users_in_group.mapped('id'): - raise UserError('Hanya MD yang bisa mengedit Product') - result = super(ProductTemplate, self).write(values) - return result + # def write(self, values): + # group_id = self.env.ref('indoteknik_custom.group_role_merchandiser').id + # users_in_group = self.env['res.users'].search([('groups_id', 'in', [group_id])]) + # if self.env.user.id not in users_in_group.mapped('id'): + # raise UserError('Hanya MD yang bisa mengedit Product') + # result = super(ProductTemplate, self).write(values) + # return result # def _compute_qr_code(self): # for rec in self.product_variant_ids: @@ -420,22 +420,22 @@ class ProductProduct(models.Model): merchandise_ok = fields.Boolean(string='Product Promotion') qr_code_variant = fields.Binary("QR Code Variant", compute='_compute_qr_code_variant') - @api.model - def create(self, vals): - group_id = self.env.ref('indoteknik_custom.group_role_merchandiser').id - users_in_group = self.env['res.users'].search([('groups_id', 'in', [group_id])]) - if self.env.user.id not in users_in_group.mapped('id'): - raise UserError('Hanya MD yang bisa membuat Product') - result = super(ProductProduct, self).create(vals) - return result + # @api.model + # def create(self, vals): + # group_id = self.env.ref('indoteknik_custom.group_role_merchandiser').id + # users_in_group = self.env['res.users'].search([('groups_id', 'in', [group_id])]) + # if self.env.user.id not in users_in_group.mapped('id'): + # raise UserError('Hanya MD yang bisa membuat Product') + # result = super(ProductProduct, self).create(vals) + # return result - def write(self, values): - group_id = self.env.ref('indoteknik_custom.group_role_merchandiser').id - users_in_group = self.env['res.users'].search([('groups_id', 'in', [group_id])]) - if self.env.user.id not in users_in_group.mapped('id'): - raise UserError('Hanya MD yang bisa mengedit Product') - result = super(ProductProduct, self).write(values) - return result + # def write(self, values): + # group_id = self.env.ref('indoteknik_custom.group_role_merchandiser').id + # users_in_group = self.env['res.users'].search([('groups_id', 'in', [group_id])]) + # if self.env.user.id not in users_in_group.mapped('id'): + # raise UserError('Hanya MD yang bisa mengedit Product') + # result = super(ProductProduct, self).write(values) + # return result def _compute_qr_code_variant(self): for rec in self: -- cgit v1.2.3 From 2ceef7e7e73a91ee513787071ba4537c7c263349 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Thu, 30 Jan 2025 11:37:15 +0700 Subject: fix bug validation create and write --- indoteknik_custom/models/product_template.py | 64 +++++++++++++++------------- 1 file changed, 34 insertions(+), 30 deletions(-) (limited to 'indoteknik_custom/models/product_template.py') diff --git a/indoteknik_custom/models/product_template.py b/indoteknik_custom/models/product_template.py index 151513e8..99a89d74 100755 --- a/indoteknik_custom/models/product_template.py +++ b/indoteknik_custom/models/product_template.py @@ -67,22 +67,24 @@ class ProductTemplate(models.Model): print_barcode = fields.Boolean(string='Print Barcode', default=True) # qr_code = fields.Binary("QR Code", compute='_compute_qr_code') - # @api.model - # def create(self, vals): - # group_id = self.env.ref('indoteknik_custom.group_role_merchandiser').id - # users_in_group = self.env['res.users'].search([('groups_id', 'in', [group_id])]) - # if self.env.user.id not in users_in_group.mapped('id'): - # raise UserError('Hanya MD yang bisa membuat Product') - # result = super(ProductTemplate, self).create(vals) - # return result + @api.model + def create(self, vals): + group_id = self.env.ref('indoteknik_custom.group_role_merchandiser').id + users_in_group = self.env['res.users'].search([('groups_id', 'in', [group_id])]) + active_model = self.env.context.get('active_model') + if self.env.user.id not in users_in_group.mapped('id') and active_model == None: + raise UserError('Hanya MD yang bisa membuat Product') + result = super(ProductTemplate, self).create(vals) + return result - # def write(self, values): - # group_id = self.env.ref('indoteknik_custom.group_role_merchandiser').id - # users_in_group = self.env['res.users'].search([('groups_id', 'in', [group_id])]) - # if self.env.user.id not in users_in_group.mapped('id'): - # raise UserError('Hanya MD yang bisa mengedit Product') - # result = super(ProductTemplate, self).write(values) - # return result + def write(self, values): + group_id = self.env.ref('indoteknik_custom.group_role_merchandiser').id + users_in_group = self.env['res.users'].search([('groups_id', 'in', [group_id])]) + active_model = self.env.context.get('active_model') + if self.env.user.id not in users_in_group.mapped('id') and active_model == None: + raise UserError('Hanya MD yang bisa mengedit Product') + result = super(ProductTemplate, self).write(values) + return result # def _compute_qr_code(self): # for rec in self.product_variant_ids: @@ -420,22 +422,24 @@ class ProductProduct(models.Model): merchandise_ok = fields.Boolean(string='Product Promotion') qr_code_variant = fields.Binary("QR Code Variant", compute='_compute_qr_code_variant') - # @api.model - # def create(self, vals): - # group_id = self.env.ref('indoteknik_custom.group_role_merchandiser').id - # users_in_group = self.env['res.users'].search([('groups_id', 'in', [group_id])]) - # if self.env.user.id not in users_in_group.mapped('id'): - # raise UserError('Hanya MD yang bisa membuat Product') - # result = super(ProductProduct, self).create(vals) - # return result + @api.model + def create(self, vals): + group_id = self.env.ref('indoteknik_custom.group_role_merchandiser').id + active_model = self.env.context.get('active_model') + users_in_group = self.env['res.users'].search([('groups_id', 'in', [group_id])]) + if self.env.user.id not in users_in_group.mapped('id') and active_model == None: + raise UserError('Hanya MD yang bisa membuat Product') + result = super(ProductProduct, self).create(vals) + return result - # def write(self, values): - # group_id = self.env.ref('indoteknik_custom.group_role_merchandiser').id - # users_in_group = self.env['res.users'].search([('groups_id', 'in', [group_id])]) - # if self.env.user.id not in users_in_group.mapped('id'): - # raise UserError('Hanya MD yang bisa mengedit Product') - # result = super(ProductProduct, self).write(values) - # return result + def write(self, values): + group_id = self.env.ref('indoteknik_custom.group_role_merchandiser').id + active_model = self.env.context.get('active_model') + users_in_group = self.env['res.users'].search([('groups_id', 'in', [group_id])]) + if self.env.user.id not in users_in_group.mapped('id') and active_model == None: + raise UserError('Hanya MD yang bisa mengedit Product') + result = super(ProductProduct, self).write(values) + return result def _compute_qr_code_variant(self): for rec in self: -- cgit v1.2.3 From f1927a4220d546756bc3a1cc5666aa2ef2c8d816 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Thu, 30 Jan 2025 14:59:15 +0700 Subject: fix bug --- indoteknik_custom/models/product_template.py | 32 ++++++++++++++-------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'indoteknik_custom/models/product_template.py') diff --git a/indoteknik_custom/models/product_template.py b/indoteknik_custom/models/product_template.py index 99a89d74..efacb95f 100755 --- a/indoteknik_custom/models/product_template.py +++ b/indoteknik_custom/models/product_template.py @@ -77,14 +77,14 @@ class ProductTemplate(models.Model): result = super(ProductTemplate, self).create(vals) return result - def write(self, values): - group_id = self.env.ref('indoteknik_custom.group_role_merchandiser').id - users_in_group = self.env['res.users'].search([('groups_id', 'in', [group_id])]) - active_model = self.env.context.get('active_model') - if self.env.user.id not in users_in_group.mapped('id') and active_model == None: - raise UserError('Hanya MD yang bisa mengedit Product') - result = super(ProductTemplate, self).write(values) - return result + # def write(self, values): + # group_id = self.env.ref('indoteknik_custom.group_role_merchandiser').id + # users_in_group = self.env['res.users'].search([('groups_id', 'in', [group_id])]) + # active_model = self.env.context.get('active_model') + # if self.env.user.id not in users_in_group.mapped('id') and active_model == None: + # raise UserError('Hanya MD yang bisa mengedit Product') + # result = super(ProductTemplate, self).write(values) + # return result # def _compute_qr_code(self): # for rec in self.product_variant_ids: @@ -432,14 +432,14 @@ class ProductProduct(models.Model): result = super(ProductProduct, self).create(vals) return result - def write(self, values): - group_id = self.env.ref('indoteknik_custom.group_role_merchandiser').id - active_model = self.env.context.get('active_model') - users_in_group = self.env['res.users'].search([('groups_id', 'in', [group_id])]) - if self.env.user.id not in users_in_group.mapped('id') and active_model == None: - raise UserError('Hanya MD yang bisa mengedit Product') - result = super(ProductProduct, self).write(values) - return result + # def write(self, values): + # group_id = self.env.ref('indoteknik_custom.group_role_merchandiser').id + # active_model = self.env.context.get('active_model') + # users_in_group = self.env['res.users'].search([('groups_id', 'in', [group_id])]) + # if self.env.user.id not in users_in_group.mapped('id') and active_model == None: + # raise UserError('Hanya MD yang bisa mengedit Product') + # result = super(ProductProduct, self).write(values) + # return result def _compute_qr_code_variant(self): for rec in self: -- cgit v1.2.3