From 89360f9d9bcbf8a83d0870d305aba6c863a4e935 Mon Sep 17 00:00:00 2001 From: Goffin Simon Date: Wed, 2 Aug 2017 16:21:12 +0200 Subject: [PATCH] [FIX] product: Two product.price.history created for one variant When a unique variant was created from a product template with function create_variant_ids, two product price history were created: -One was created from function create on product.product -The other one was created from function _set_standard_price on product.template The first product.price.history created in this situation was all the time set to 0 and it lead to some problems in the report inventory date. This first product.price.history doesn't have to be created. opw:747857 --- addons/product/models/product.py | 4 +++- addons/product/models/product_template.py | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/addons/product/models/product.py b/addons/product/models/product.py index a2acba254ef..6b0c04275bc 100644 --- a/addons/product/models/product.py +++ b/addons/product/models/product.py @@ -314,7 +314,9 @@ class ProductProduct(models.Model): @api.model def create(self, vals): product = super(ProductProduct, self.with_context(create_product_product=True)).create(vals) - product._set_standard_price(vals.get('standard_price', 0.0)) + # When a unique variant is created from tmpl then the standard price is set by _set_standard_price + if not (self.env.context.get('create_from_tmpl') and len(product.product_tmpl_id.product_variant_ids) == 1): + product._set_standard_price(vals.get('standard_price') or 0.0) return product @api.multi diff --git a/addons/product/models/product_template.py b/addons/product/models/product_template.py index d56aef35cfa..16ac91ce034 100644 --- a/addons/product/models/product_template.py +++ b/addons/product/models/product_template.py @@ -264,7 +264,7 @@ class ProductTemplate(models.Model): tools.image_resize_images(vals) template = super(ProductTemplate, self).create(vals) if "create_product_product" not in self._context: - template.create_variant_ids() + template.with_context(create_from_tmpl=True).create_variant_ids() # This is needed to set given values to first variant after creation related_vals = {}