diff options
| author | Rafi Zadanly <zadanlyr@gmail.com> | 2023-09-06 13:59:28 +0700 |
|---|---|---|
| committer | Rafi Zadanly <zadanlyr@gmail.com> | 2023-09-06 13:59:28 +0700 |
| commit | 4986c63d2a6bd8e2feadbd2403a211b0b0cf405f (patch) | |
| tree | b80d2d415b887a7ab66c9d55d5a4857d34142bea /indoteknik_custom/models/product_template.py | |
| parent | ea48748650d1abe7b9c09f961eaa3762750e21be (diff) | |
| parent | e07379886024a313695a56ebdd072bfd87b6626a (diff) | |
Merge branch 'production' into feature/voucher-group
Diffstat (limited to 'indoteknik_custom/models/product_template.py')
| -rwxr-xr-x | indoteknik_custom/models/product_template.py | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/indoteknik_custom/models/product_template.py b/indoteknik_custom/models/product_template.py index 019d229c..8daa0b7a 100755 --- a/indoteknik_custom/models/product_template.py +++ b/indoteknik_custom/models/product_template.py @@ -51,7 +51,40 @@ class ProductTemplate(models.Model): is_new_product = fields.Boolean(string='Produk Baru', help='Centang jika ingin ditammpilkan di website sebagai segment Produk Baru') seq_new_product = fields.Integer(string='Seq New Product', help='Urutan Sequence New Product') + is_edited = fields.Boolean(string='Is Edited') + @api.constrains('name', 'default_code') + def _check_duplicate_product(self): + for product in self: + if not self.env.user.is_purchasing_manager: + domain = [('default_code', '!=', False)] + + if product.product_variant_ids: + domain.extend([ + '|', + ('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.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): pattern = r'^[a-zA-Z0-9\[\]\(\)\.\s/%-]+$' @@ -289,6 +322,35 @@ class ProductProduct(models.Model): qty_onhand_bandengan = fields.Float(string='Qty Incoming Bandengan', compute='_get_qty_onhand_bandengan') qty_incoming_bandengan = fields.Float(string='Qty Incoming Bandengan', compute='_get_qty_incoming_bandengan') sla_version = fields.Integer(string="SLA Version", default=0) + is_edited = fields.Boolean(string='Is Edited') + + @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), + '|', + ('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" + existing_purchase = self.search(domain, limit=1) + if existing_purchase: + raise UserError(massage) + else: + domain = [ + ('id', '=', product.id), + ('is_edited', '=', True), + ] + existing_purchase = self.search(domain) + if existing_purchase: + raise UserError('Hanya Pak Tyas Yang Dapat Merubah Data Product') + if not existing_purchase: + true = True + self.is_edited = true @api.constrains('name') def _validate_name(self): |
