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 ++++++++++++++++++++++++- indoteknik_custom/models/purchase_pricelist.py | 23 +++++ indoteknik_custom/views/purchase_pricelist.xml | 2 +- 3 files changed, 142 insertions(+), 2 deletions(-) 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): diff --git a/indoteknik_custom/models/purchase_pricelist.py b/indoteknik_custom/models/purchase_pricelist.py index 419ca8e0..5d077e04 100755 --- a/indoteknik_custom/models/purchase_pricelist.py +++ b/indoteknik_custom/models/purchase_pricelist.py @@ -27,3 +27,26 @@ class PurchasePricelist(models.Model): self.system_last_update = current_time else: self.human_last_update = current_time + + @api.constrains('vendor_id', 'product_id','human_last_update','write_date') + def _check_duplicate_purchase_pricelist(self): + for price in self: + if price.write_date == price.create_date: + domain = [ + ('product_id', '=', price.product_id.id), + ('vendor_id', '=', price.vendor_id.id) + ] + + domain.append(('id', '!=', price.id)) + massage="Product dan vendor yang anda gunakan sudah ada di purchase pricelist" + existing_purchase = self.search(domain, limit=1) + if existing_purchase: + raise UserError(massage) + else: + domain = [ + ('id', '=', price.id) + ] + massage="Tidak Dapat Merubah Product" + existing_purchase = self.search(domain, limit=1) + if existing_purchase: + raise UserError(massage) \ No newline at end of file diff --git a/indoteknik_custom/views/purchase_pricelist.xml b/indoteknik_custom/views/purchase_pricelist.xml index f9fd52ba..5c63676d 100755 --- a/indoteknik_custom/views/purchase_pricelist.xml +++ b/indoteknik_custom/views/purchase_pricelist.xml @@ -19,7 +19,7 @@ purchase.pricelist.form purchase.pricelist -
+ -- 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(-) 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