From 1ea160934c67dd9e4ff2a160385f79cd5ad24946 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Tue, 19 Sep 2023 13:23:57 +0700 Subject: add field email to so and sync email so with email partner_id, add field publish to product --- indoteknik_custom/models/product_template.py | 10 ++++++++++ 1 file changed, 10 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 4c11dcef..f186c2bf 100755 --- a/indoteknik_custom/models/product_template.py +++ b/indoteknik_custom/models/product_template.py @@ -52,6 +52,16 @@ class ProductTemplate(models.Model): 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') + publish = fields.Boolean(string='Publish', default=True) + + @api.constrains('active') + def constrains_active_publish(self): + if not self.active or self.type != 'product': + self.publish = False + else: + self.publish = True + + self._create_solr_queue('_sync_product_template_to_solr') @api.constrains('name', 'default_code') def _check_duplicate_product(self): -- cgit v1.2.3 From 5383121fbdc4e2f899e6bbe7e0402402a8f8eaf4 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Tue, 19 Sep 2023 15:28:49 +0700 Subject: fix required field email so --- indoteknik_custom/models/product_template.py | 36 ++++++++++++++++++---------- 1 file changed, 23 insertions(+), 13 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 f186c2bf..cf3df153 100755 --- a/indoteknik_custom/models/product_template.py +++ b/indoteknik_custom/models/product_template.py @@ -1,5 +1,5 @@ from odoo import fields, models, api -from datetime import datetime, timedelta +from datetime import datetime, timedelta, date from odoo.exceptions import UserError import logging import requests @@ -63,6 +63,15 @@ class ProductTemplate(models.Model): self._create_solr_queue('_sync_product_template_to_solr') + def day_product_to_edit(self): + day_products = [] + + for product in self: + day_product = (product.write_date - product.create_date).days + day_products.append(day_product) + + return day_products + @api.constrains('name', 'default_code') def _check_duplicate_product(self): for product in self: @@ -86,12 +95,10 @@ class ProductTemplate(models.Model): if product.write_date == product.create_date: message = "SKU atau Name yang Anda gunakan sudah digunakan di produk lain" - else: + elif all(day_product > 0 for day_product in product.day_product_to_edit()): 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) @@ -334,6 +341,15 @@ class ProductProduct(models.Model): sla_version = fields.Integer(string="SLA Version", default=0) is_edited = fields.Boolean(string='Is Edited') + def day_product_to_edit(self): + day_products = [] + + for product in self: + day_product = (product.write_date - product.create_date).days + day_products.append(day_product) + + return day_products + @api.constrains('name','default_code') def _check_duplicate_product(self): if not self.env.user.is_purchasing_manager: @@ -350,18 +366,12 @@ class ProductProduct(models.Model): existing_purchase = self.search(domain, limit=1) if existing_purchase: raise UserError(massage) - else: - domain = [ - ('id', '=', product.id), - ('is_edited', '=', True), - ] + elif all(day_product > 0 for day_product in product.day_product_to_edit()): + domain = [('id', '=', product.id)] 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): pattern = r'^[a-zA-Z0-9\[\]\(\)\.\s/%-]+$' -- cgit v1.2.3 From 6481b0748f6872a37961252a213e55cec8227ed5 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Wed, 20 Sep 2023 09:42:33 +0700 Subject: fix product attribute name --- indoteknik_custom/models/product_template.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 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 cf3df153..2ce2c185 100755 --- a/indoteknik_custom/models/product_template.py +++ b/indoteknik_custom/models/product_template.py @@ -104,11 +104,12 @@ class ProductTemplate(models.Model): @api.constrains('name') def _validate_name(self): - pattern = r'^[a-zA-Z0-9\[\]\(\)\.\s/%-]+$' + rule_regex = self.env['ir.config_parameter'].sudo().get_param('product.product.rule_name_regex') or '' + pattern = rf'^{rule_regex}$' if not re.match(pattern, self.name): - pattern_suggest = r'[a-zA-Z0-9\[\]\(\)\.\s/%-]+' + pattern_suggest = rf"{rule_regex}" suggest = ''.join(re.findall(pattern_suggest, self.name)) - raise UserError(f'Nama hanya bisa menggunakan angka, strip, huruf kecil, huruf besar, titik, kurung lengkung, kurung siku, garis miring. Contoh: {suggest}') + raise UserError(f'Contoh yang benar adalah {suggest}') # def write(self, vals): # if 'solr_flag' not in vals and self.solr_flag == 1: @@ -374,11 +375,12 @@ class ProductProduct(models.Model): @api.constrains('name') def _validate_name(self): - pattern = r'^[a-zA-Z0-9\[\]\(\)\.\s/%-]+$' + rule_regex = self.env['ir.config_parameter'].sudo().get_param('product.product.rule_name_regex') or '' + pattern = rf'^{rule_regex}$' if not re.match(pattern, self.name): - pattern_suggest = r'[a-zA-Z0-9\[\]\(\)\.\s/%-]+' + pattern_suggest = rf"{rule_regex}" suggest = ''.join(re.findall(pattern_suggest, self.name)) - raise UserError(f'Nama hanya bisa menggunakan angka, strip, huruf kecil, huruf besar, titik, kurung lengkung, kurung siku, garis miring. Contoh: {suggest}') + raise UserError(f'Contoh yang benar adalah {suggest}') def _get_qty_incoming_bandengan(self): for product in self: -- cgit v1.2.3 From aeadcc9b170ae8585844d4b4986971ed028b7897 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Wed, 20 Sep 2023 13:21:38 +0700 Subject: add new role user to edit product --- indoteknik_custom/models/product_template.py | 6 +++--- 1 file changed, 3 insertions(+), 3 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 2ce2c185..7effc109 100755 --- a/indoteknik_custom/models/product_template.py +++ b/indoteknik_custom/models/product_template.py @@ -75,7 +75,7 @@ class ProductTemplate(models.Model): @api.constrains('name', 'default_code') def _check_duplicate_product(self): for product in self: - if not self.env.user.is_purchasing_manager: + if not self.env.user.is_purchasing_manager and not self.env.user.is_editor_product: domain = [('default_code', '!=', False)] if product.product_variant_ids: @@ -353,8 +353,8 @@ class ProductProduct(models.Model): @api.constrains('name','default_code') def _check_duplicate_product(self): - if not self.env.user.is_purchasing_manager: - for product in self: + for product in self: + if not self.env.user.is_purchasing_manager and not self.env.user.is_editor_product: if product.write_date == product.create_date: domain = [ ('default_code', '!=', False), -- cgit v1.2.3 From 33166b60a9e0e6b236f39b26e53d925d2790e9db Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Thu, 21 Sep 2023 08:09:39 +0700 Subject: fix pricelist get id static --- indoteknik_custom/models/product_template.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 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 7effc109..ed722d5e 100755 --- a/indoteknik_custom/models/product_template.py +++ b/indoteknik_custom/models/product_template.py @@ -411,8 +411,16 @@ class ProductProduct(models.Model): def _compute_web_price(self): for product in self: - product_pricelist_item = self.env['product.pricelist.item'].search( - [('pricelist_id', '=', 1), ('product_id', '=', product.id)], limit=1) + pricelist_id = self.env.context.get('pricelist') + + domain = [('pricelist_id', '=', pricelist_id or 1), ('product_id', '=', product.id)] + product_pricelist_item = self.env['product.pricelist.item'].search(domain, limit=1) + + if product_pricelist_item.base_pricelist_id: + base_pricelist_id = product_pricelist_item.base_pricelist_id.id + domain = [('pricelist_id', '=', base_pricelist_id), ('product_id', '=', product.id)] + product_pricelist_item = self.env['product.pricelist.item'].search(domain, limit=1) + product.web_price = product_pricelist_item.fixed_price def _compute_stock_vendor(self): -- cgit v1.2.3 From a74adc5dc9bfbbd87c308aa040b605e4160e0d17 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Sat, 23 Sep 2023 12:35:22 +0700 Subject: fix bug pricelist --- indoteknik_custom/models/product_template.py | 8 +------- 1 file changed, 1 insertion(+), 7 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 ed722d5e..d35188b4 100755 --- a/indoteknik_custom/models/product_template.py +++ b/indoteknik_custom/models/product_template.py @@ -193,13 +193,7 @@ class ProductTemplate(models.Model): def _compute_web_price(self): for template in self: - # product = self.env['product.product'].search([('product_tmpl_id', '=', template.id)], limit=1) - - product_pricelist_item = self.env['product.pricelist.item'].search([ - ('pricelist_id', '=', 1), - ('product_id', '=', template.product_variant_id.id)], limit=1) - price = product_pricelist_item.fixed_price - template.web_price = price + template.web_price = template.product_variant_ids[0].web_price def _have_promotion_program(self): for template in self: -- cgit v1.2.3