From c3f81c527ddb5153f5a1eceb5e87efeb533129b0 Mon Sep 17 00:00:00 2001
From: Vipul Bhatt <vbh@odoo.com>
Date: Mon, 29 Aug 2016 17:00:47 +0530
Subject: [PATCH] [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
---
 addons/product/models/product_template.py | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/addons/product/models/product_template.py b/addons/product/models/product_template.py
index 102715845793..166524b02d18 100644
--- a/addons/product/models/product_template.py
+++ b/addons/product/models/product_template.py
@@ -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
-- 
GitLab