[FIX] product: error during migration

Barcode, default_code (Internal Reference), standard_price,
volume, weight fields are not saved when we create a new product.

This is due to the fact that these fields need the product_variant_ids
field to be set, in order to compute their values.

Due to migration in rev https://github.com/odoo-dev/odoo/commit/1aa5bc0fdfa402ac7cccbc3a7203ec5050f6339b
This commit is contained in:
Vipul Bhatt
2016-09-01 17:20:26 +02:00
committed by Pierre Masereel
parent e59a7fe3ff
commit c3f81c527d
+15
View File
@@ -265,6 +265,21 @@ class ProductTemplate(models.Model):
template = super(ProductTemplate, self).create(vals)
if "create_product_product" not in self._context:
template.create_variant_ids()
# This is needed to set given values to first variant after creation
related_vals = {}
if vals.get('barcode'):
related_vals['barcode'] = vals['barcode']
if vals.get('default_code'):
related_vals['default_code'] = vals['default_code']
if vals.get('standard_price'):
related_vals['standard_price'] = vals['standard_price']
if vals.get('volume'):
related_vals['volume'] = vals['volume']
if vals.get('weight'):
related_vals['weight'] = vals['weight']
if related_vals:
template.write(related_vals)
return template
@api.multi