summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAzka Nathan <darizkyfaz@gmail.com>2024-01-17 17:01:20 +0700
committerAzka Nathan <darizkyfaz@gmail.com>2024-01-17 17:01:20 +0700
commit37bb5cfca00b841f8204ebbc9dd5f88bbd6cc022 (patch)
tree243146f5d325fcebbbf8a980fe5d23cad920aec6
parentda4ec7e5513cd9975a0b503857e49598a2dee158 (diff)
fix function update_internal_reference
-rwxr-xr-xindoteknik_custom/models/product_template.py50
1 files changed, 28 insertions, 22 deletions
diff --git a/indoteknik_custom/models/product_template.py b/indoteknik_custom/models/product_template.py
index 34aff4fa..4beef751 100755
--- a/indoteknik_custom/models/product_template.py
+++ b/indoteknik_custom/models/product_template.py
@@ -74,7 +74,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 and not self.env.user.is_editor_product:
+ if not self.env.user.is_purchasing_manager and not self.env.user.is_editor_product and self.env.user.id not in [1, 25]:
domain = [('default_code', '!=', False)]
if product.product_variant_ids:
@@ -157,28 +157,34 @@ class ProductTemplate(models.Model):
_logger.info('Updated New Product %s' % product.name)
def update_internal_reference(self, limit=100):
- templates_without_variant = self.env['product.template'].search([
+ templates = self.env['product.template'].search([
('default_code', '=', False),
+ ('product_variant_ids.default_code', '=', False),
('type', '=', 'product'),
- ('active', '=', True),
- ('product_variant_ids', '=', False),
- ], limit=limit)
- for template_without_variant in templates_without_variant:
- template_without_variant.default_code = 'IT.'+str(template_without_variant.id)
- _logger.info('Updated Template %s' % template_without_variant.name)
-
- templates_with_variant = self.env['product.template'].search([
- ('default_code', '=', False),
- ('type', '=', 'product'),
- ('active', '=', True),
- ('product_variant_ids', '!=', False),
- ], limit=limit)
- for template_with_variant in templates_with_variant:
- for product in template_with_variant.product_variant_ids:
- if product.default_code:
- continue
- product.default_code = 'ITV.'+str(product.id)
- _logger.info('Updated Variant %s' % product.name)
+ ('active', '=', True)
+ ], limit=limit, order='write_date desc')
+ for template in templates:
+ if not template.default_code:
+ template.default_code = 'IT.'+str(template.id)
+
+ for variant in template.product_variant_ids:
+ if not variant.default_code:
+ variant.default_code = 'ITV.%s' % str(variant.id)
+
+ _logger.info('Updated Template %s' % template.name)
+
+ # templates_with_variant = self.env['product.product'].search([
+ # ('default_code', '=', False),
+ # ('type', '=', 'product'),
+ # ('active', '=', True),
+ # ('product_tmpl_id', '!=', False),
+ # ], limit=limit, order='write_date desc')
+ # for template_with_variant in templates_with_variant:
+ # for product in template_with_variant.product_variant_ids:
+ # if product.default_code:
+ # continue
+ # product.default_code = 'ITV.'+str(product.id)
+ # _logger.info('Updated Variant %s' % product.name)
@api.onchange('name','default_code','x_manufacture','product_rating','website_description','image_1920','weight','public_categ_ids')
def update_solr_flag(self):
@@ -372,7 +378,7 @@ class ProductProduct(models.Model):
@api.constrains('name','default_code')
def _check_duplicate_product(self):
for product in self:
- if not self.env.user.is_purchasing_manager and not self.env.user.is_editor_product:
+ if not self.env.user.is_purchasing_manager and not self.env.user.is_editor_product and self.env.user.id not in [1, 25]:
if product.write_date == product.create_date:
domain = [
('default_code', '!=', False),