From 3f69628f969e54069fa4d13afb056a0add9d3e64 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Wed, 28 May 2014 11:29:20 +0200 Subject: [PATCH] [FIX] product: recursion error when active field on product.template is modified --- addons/product/product.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/addons/product/product.py b/addons/product/product.py index cff70c9e6b9..ea62786fd40 100644 --- a/addons/product/product.py +++ b/addons/product/product.py @@ -628,6 +628,7 @@ class product_template(osv.osv): all_variants = temp_variants # check product + variants_ids_to_active = [] variants_active_ids = [] variants_inactive = [] for product_id in tmpl_id.product_variant_ids: @@ -635,11 +636,12 @@ class product_template(osv.osv): if variants in all_variants: variants_active_ids.append(product_id.id) all_variants.pop(all_variants.index(variants)) - # TODO all write in same time - if product_id.active: - product_id.write({'active': True}, context=ctx) + if not product_id.active: + variants_ids_to_active.append(product_id.id) else: variants_inactive.append(product_id) + if variants_ids_to_active: + product_obj.write(cr, uid, variants_ids_to_active, {'active': True}, context=ctx) # create new product for variant_ids in all_variants: @@ -681,14 +683,16 @@ class product_template(osv.osv): if 'standard_price' in vals: for prod_template_id in ids: self._set_standard_price(cr, uid, prod_template_id, vals['standard_price'], context=context) - if 'active' in vals: - product_ids = [] - for product in self.browse(cr, uid, ids, context=context): - product_ids = map(int, product.product_variant_ids) - self.write(cr, uid, product_ids, {'active': vals.get('active')}, context=context) res = super(product_template, self).write(cr, uid, ids, vals, context=context) - if 'variant_ids' in vals: + if 'variant_ids' in vals or vals.get('active'): self.create_variant_ids(cr, uid, ids, context=context) + if 'active' in vals and not vals.get('active'): + ctx = context and context.copy() or {} + ctx.update(active_test=False) + product_ids = [] + for product in self.browse(cr, uid, ids, context=ctx): + product_ids = map(int,product.product_variant_ids) + self.pool.get("product.product").write(cr, uid, product_ids, {'active': vals.get('active')}, context=ctx) return res def copy(self, cr, uid, id, default=None, context=None):