diff options
| -rwxr-xr-x | indoteknik_custom/models/product_template.py | 24 |
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: |
