[FIX] product: recursion error when active field on product.template is modified

This commit is contained in:
Christophe Matthieu 2014-05-28 11:29:20 +02:00
parent c6f0699435
commit 3f69628f96
1 changed files with 13 additions and 9 deletions

View File

@ -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):