diff --git a/addons/product/models/product_template.py b/addons/product/models/product_template.py index 437c193446b..2b2508cce9d 100644 --- a/addons/product/models/product_template.py +++ b/addons/product/models/product_template.py @@ -368,14 +368,7 @@ class ProductTemplate(models.Model): @api.multi def create_variant_ids(self): Product = self.env["product.product"] - for tmpl_id in self.with_context(active_test=False): - # list of values combination - existing_variants = [set(variant.attribute_value_ids.ids) for variant in tmpl_id.product_variant_ids] - variant_matrix = itertools.product(*(line.value_ids for line in tmpl_id.attribute_line_ids if line.value_ids and line.value_ids[0].attribute_id.create_variant)) - variant_matrix = map(lambda record_list: reduce(lambda x, y: x+y, record_list, self.env['product.attribute.value']), variant_matrix) - to_create_variants = filter(lambda rec_set: set(rec_set.ids) not in existing_variants, variant_matrix) - # adding an attribute with only one value should not recreate product # write this attribute on every product to make sure we don't lose them variant_alone = tmpl_id.attribute_line_ids.filtered(lambda line: len(line.value_ids) == 1).mapped('value_ids') @@ -383,6 +376,12 @@ class ProductTemplate(models.Model): updated_products = tmpl_id.product_variant_ids.filtered(lambda product: value_id.attribute_id not in product.mapped('attribute_value_ids.attribute_id')) updated_products.write({'attribute_value_ids': [(4, value_id.id)]}) + # list of values combination + existing_variants = [set(variant.attribute_value_ids.ids) for variant in tmpl_id.product_variant_ids] + variant_matrix = itertools.product(*(line.value_ids for line in tmpl_id.attribute_line_ids if line.value_ids and line.value_ids[0].attribute_id.create_variant)) + variant_matrix = map(lambda record_list: reduce(lambda x, y: x+y, record_list, self.env['product.attribute.value']), variant_matrix) + to_create_variants = filter(lambda rec_set: set(rec_set.ids) not in existing_variants, variant_matrix) + # check product variants_to_activate = self.env['product.product'] variants_to_unlink = self.env['product.product']