diff options
| author | Azka Nathan <darizkyfaz@gmail.com> | 2023-09-05 14:45:18 +0700 |
|---|---|---|
| committer | Azka Nathan <darizkyfaz@gmail.com> | 2023-09-05 14:45:18 +0700 |
| commit | 513bce9e13dee0453ce24b41a54d3b408e58c7f0 (patch) | |
| tree | 21426e7af98ad3fcb34101e42ce0979d4472958a /indoteknik_custom/models/product_template.py | |
| parent | a1137c5bb22734eff9585b7b95607983f23d2de9 (diff) | |
Fix bug solr product variants, add analytic tags to jurnal entries line, remove validation edit di purchase pricelist
Diffstat (limited to 'indoteknik_custom/models/product_template.py')
| -rwxr-xr-x | indoteknik_custom/models/product_template.py | 85 |
1 files changed, 30 insertions, 55 deletions
diff --git a/indoteknik_custom/models/product_template.py b/indoteknik_custom/models/product_template.py index b44f585e..8daa0b7a 100755 --- a/indoteknik_custom/models/product_template.py +++ b/indoteknik_custom/models/product_template.py @@ -53,47 +53,37 @@ class ProductTemplate(models.Model): seq_new_product = fields.Integer(string='Seq New Product', help='Urutan Sequence New Product') is_edited = fields.Boolean(string='Is Edited') - # def write(self, vals): - # if not self.env.user.is_purchasing_manager: - # for product in self: - - # domain = [ - # ('id', '=', product.id), - # ('create_date', '<=', product.write_date), - # ('name', '=', product.name), - # ('default_code', '=', product.default_code) - # ] - - # existing_purchase = self.search(domain, limit=1) - # if existing_purchase: - # raise UserError("Hanya Pak Tyas yang bisa mengedit product") - # return super(ProductTemplate, self).write(vals) - - @api.constrains('name','default_code') + @api.constrains('name', 'default_code') def _check_duplicate_product(self): - if not self.env.user.is_purchasing_manager: - for product in self: - if product.write_date == product.create_date: - domain = [ - ('default_code', '!=', False), + for product in self: + if not self.env.user.is_purchasing_manager: + domain = [('default_code', '!=', False)] + + if product.product_variant_ids: + domain.extend([ '|', - ('name', '=', product.name), - ('default_code', '=', product.default_code)] - - domain.append(('id', '!=', product.id)) - massage="SKU atau Name yang anda pakai sudah digunakan di product lain" - existing_purchase = self.search(domain, limit=1) - if existing_purchase: - raise UserError(massage) + ('name', 'in', [variants.name for variants in product.product_variant_ids]), + ('default_code', 'in', [variants.default_code for variants in product.product_variant_ids]) + ]) else: - domain = [ - ('id', '=', product.id) - ] - massage="Hanya Pak Tyas Yang Dapat Merubah Data Product" - existing_purchase = self.search(domain, limit=1) - if existing_purchase: - raise UserError(massage) - + domain.extend([ + '|', + ('name', 'in', [product.name]), + ('default_code', 'in', [product.default_code]) + ]) + + domain.append(('id', '!=', product.id)) + + if product.write_date == product.create_date: + message = "SKU atau Name yang Anda gunakan sudah digunakan di produk lain" + else: + domain = [('id', '=', product.id)] + message = "Hanya Pak Tyas yang dapat merubah data produk" + + existing_purchase = self.search(domain, limit=1) + + if existing_purchase: + raise UserError(message) @api.constrains('name') def _validate_name(self): @@ -334,21 +324,6 @@ class ProductProduct(models.Model): sla_version = fields.Integer(string="SLA Version", default=0) is_edited = fields.Boolean(string='Is Edited') - # def write(self, vals): - # if not self.env.user.is_purchasing_manager: - # for product in self: - # domain = [ - # ('id', '=', product.id), - # ('create_date', '<=', product.write_date), - # ('name', '=', product.name), - # ('default_code', '=', product.default_code) - # ] - - # existing_purchase = self.search(domain, limit=1) - # if existing_purchase: - # raise UserError("Hanya Pak Tyas yang bisa mengedit product") - # return super(ProductProduct, self).write(vals) - @api.constrains('name','default_code') def _check_duplicate_product(self): if not self.env.user.is_purchasing_manager: @@ -357,8 +332,8 @@ class ProductProduct(models.Model): domain = [ ('default_code', '!=', False), '|', - ('name', '=', product.name), - ('default_code', '=', product.default_code)] + ('name', 'in', [template.name for template in product.product_tmpl_id] or [product.name]), + ('default_code', 'in', [template.default_code for template in product.product_tmpl_id] or [product.default_code])] domain.append(('id', '!=', product.id)) massage="SKU atau Name yang anda pakai sudah digunakan di product lain" |
