summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2022-11-17 10:01:35 +0700
committerstephanchrst <stephanchrst@gmail.com>2022-11-17 10:01:35 +0700
commit390cc9e5b2e2b02eecb37472d4362c829a3745db (patch)
tree9bb58c282b89f5fee0a14bafb970356b408480ea
parent0195aeb8b16a46792eabc3491e186ee869b814ee (diff)
add method for auto generate blank item code / internal reference
-rwxr-xr-xindoteknik_custom/models/product_template.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/indoteknik_custom/models/product_template.py b/indoteknik_custom/models/product_template.py
index 114899e6..743667cc 100755
--- a/indoteknik_custom/models/product_template.py
+++ b/indoteknik_custom/models/product_template.py
@@ -40,6 +40,30 @@ class ProductTemplate(models.Model):
# vals['solr_flag'] = 2
# return super().write(vals)
+ def update_internal_reference(self):
+ templates_without_variant = self.env['product.template'].search([
+ ('default_code', '=', False),
+ ('type', '=', 'product'),
+ ('active', '=', True),
+ ('product_variant_ids', '=', False),
+ ])
+ 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),
+ ])
+ 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):
for tmpl in self: