From 61c89397e839f546c796a596a1fbbc840aa85311 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Mon, 28 Aug 2023 15:04:51 +0700 Subject: Validate Data Product & Purchase Pricelist --- indoteknik_custom/models/product_template.py | 119 ++++++++++++++++++++++++++- 1 file changed, 118 insertions(+), 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 52f72729..3352c6b0 100755 --- a/indoteknik_custom/models/product_template.py +++ b/indoteknik_custom/models/product_template.py @@ -51,7 +51,67 @@ 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_edit = fields.Boolean(string="Update Counter", default=True) + # 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', + 'sequence', + 'responsible_id', + 'list_price', + 'standard_price', + 'qty_available', + 'virtual_available', + 'uom_id', + 'activity_exception_decoration', + 'web_tax_id', + 'categ_id', + 'taxes_id', + 'barcode', + 'x_manufacture', + 'x_model_product', + 'x_studio_field_tGhJR', + 'attribute_line_ids',) + 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', '=', 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) + 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) + + @api.constrains('name') def _validate_name(self): pattern = r'^[a-zA-Z0-9\[\]\(\)\.\s/%]+$' @@ -59,7 +119,7 @@ class ProductTemplate(models.Model): pattern_suggest = r'[a-zA-Z0-9\[\]\(\)\.\s/%]+' suggest = ''.join(re.findall(pattern_suggest, self.name)) raise UserError(f'Nama hanya bisa menggunakan angka, huruf kecil, huruf besar, titik, kurung lengkung, kurung siku, garis miring. Contoh: {suggest}') - + # def write(self, vals): # if 'solr_flag' not in vals and self.solr_flag == 1: # vals['solr_flag'] = 2 @@ -287,6 +347,63 @@ 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_edit = fields.Boolean(string="Update Counter", default=True) + + # 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', + 'product_template_attribute_value_ids', + 'lst_price', + 'standard_price', + 'qty_available', + 'outgoing_qty', + 'incoming_qty', + 'virtual_available', + 'web_tax_id', + 'categ_id', + 'taxes_id', + 'barcode', + 'x_manufacture', + 'x_model_product', + 'x_studio_field_tGhJR', + ) + 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', '=', 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) + 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) @api.constrains('name') def _validate_name(self): -- cgit v1.2.3 From 76e97903641e6dc35f4158f2a08cfa70bed50afe Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Wed, 30 Aug 2023 10:33:01 +0700 Subject: change constraint product template --- indoteknik_custom/models/product_template.py | 37 ++-------------------------- 1 file changed, 2 insertions(+), 35 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 3352c6b0..c2cf3bb9 100755 --- a/indoteknik_custom/models/product_template.py +++ b/indoteknik_custom/models/product_template.py @@ -69,24 +69,7 @@ class ProductTemplate(models.Model): # raise UserError("Hanya Pak Tyas yang bisa mengedit product") # return super(ProductTemplate, self).write(vals) - @api.constrains('name', - 'default_code', - 'sequence', - 'responsible_id', - 'list_price', - 'standard_price', - 'qty_available', - 'virtual_available', - 'uom_id', - 'activity_exception_decoration', - 'web_tax_id', - 'categ_id', - 'taxes_id', - 'barcode', - 'x_manufacture', - 'x_model_product', - 'x_studio_field_tGhJR', - 'attribute_line_ids',) + @api.constrains('name','default_code',) def _check_duplicate_product(self): if not self.env.user.is_purchasing_manager: for product in self: @@ -364,23 +347,7 @@ class ProductProduct(models.Model): # raise UserError("Hanya Pak Tyas yang bisa mengedit product") # return super(ProductProduct, self).write(vals) - @api.constrains('name', - 'default_code', - 'product_template_attribute_value_ids', - 'lst_price', - 'standard_price', - 'qty_available', - 'outgoing_qty', - 'incoming_qty', - 'virtual_available', - 'web_tax_id', - 'categ_id', - 'taxes_id', - 'barcode', - 'x_manufacture', - 'x_model_product', - 'x_studio_field_tGhJR', - ) + @api.constrains('name','default_code',) def _check_duplicate_product(self): if not self.env.user.is_purchasing_manager: for product in self: -- cgit v1.2.3 From 3f9ee6e5297afbd7aad670eb061c069621af888e Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Thu, 31 Aug 2023 13:40:38 +0700 Subject: refactor validate product --- indoteknik_custom/models/product_template.py | 6 ++---- 1 file changed, 2 insertions(+), 4 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 707a8381..e9d57dc3 100755 --- a/indoteknik_custom/models/product_template.py +++ b/indoteknik_custom/models/product_template.py @@ -51,7 +51,6 @@ 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_edit = fields.Boolean(string="Update Counter", default=True) # def write(self, vals): # if not self.env.user.is_purchasing_manager: @@ -69,7 +68,7 @@ class ProductTemplate(models.Model): # 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: @@ -332,7 +331,6 @@ 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_edit = fields.Boolean(string="Update Counter", default=True) # def write(self, vals): # if not self.env.user.is_purchasing_manager: @@ -349,7 +347,7 @@ class ProductProduct(models.Model): # raise UserError("Hanya Pak Tyas yang bisa mengedit product") # return super(ProductProduct, 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: -- cgit v1.2.3 From fb2ee6f00d4b8caf351b05db92af7bf0e4774ec8 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Fri, 1 Sep 2023 08:39:17 +0700 Subject: fix product template variants --- indoteknik_custom/models/product_template.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 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 e9d57dc3..b44f585e 100755 --- a/indoteknik_custom/models/product_template.py +++ b/indoteknik_custom/models/product_template.py @@ -51,6 +51,7 @@ 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') # def write(self, vals): # if not self.env.user.is_purchasing_manager: @@ -331,6 +332,7 @@ 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') # def write(self, vals): # if not self.env.user.is_purchasing_manager: @@ -365,12 +367,15 @@ class ProductProduct(models.Model): raise UserError(massage) else: domain = [ - ('id', '=', product.id) + ('id', '=', product.id), + ('is_edited', '=', True), ] - massage="Hanya Pak Tyas Yang Dapat Merubah Data Product" - existing_purchase = self.search(domain, limit=1) + existing_purchase = self.search(domain) if existing_purchase: - raise UserError(massage) + 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): -- cgit v1.2.3 From 513bce9e13dee0453ce24b41a54d3b408e58c7f0 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Tue, 5 Sep 2023 14:45:18 +0700 Subject: Fix bug solr product variants, add analytic tags to jurnal entries line, remove validation edit di purchase pricelist --- indoteknik_custom/models/product_template.py | 85 ++++++++++------------------ 1 file changed, 30 insertions(+), 55 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 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" -- cgit v1.2.3