From e4762229ba6b7bca7c7725504d2d43e15fc38892 Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Thu, 27 Oct 2016 16:46:24 +0200 Subject: [PATCH] [FIX] stock_account: valuation and costing method In v9, the creation of a product doesn't set a `valuation` or a `cost_method` by default. It means that the corresponding fields of the product category is selected instead. In v10, this is the other way around: a default value is set on these fields, and therefore the value on the product is selected. This is obviously a change in behavior, and moreover the field is invisible in the product view, meaning that it cannot be changed. This is due to the new API conversion. In the new API, the methods `_compute_valuation_type` and `_compute_cost_method` are called through the 'onchange' mechanism. This sets the associated fields, which are then copied in their `property_` counterpart thanks to the inverse function. opw-691231 --- addons/stock_account/models/product.py | 14 ++++++-------- addons/stock_account/views/product_views.xml | 4 ++-- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/addons/stock_account/models/product.py b/addons/stock_account/models/product.py index a81b0260253..6f0c4e7a351 100644 --- a/addons/stock_account/models/product.py +++ b/addons/stock_account/models/product.py @@ -40,7 +40,7 @@ class ProductTemplate(models.Model): @api.one @api.depends('property_valuation', 'categ_id.property_valuation') def _compute_valuation_type(self): - self.valuation = self.property_valuation if self.property_valuation else self.categ_id.property_valuation + self.valuation = self.property_valuation or self.categ_id.property_valuation @api.one def _set_valuation_type(self): @@ -49,7 +49,7 @@ class ProductTemplate(models.Model): @api.one @api.depends('property_cost_method', 'categ_id.property_cost_method') def _compute_cost_method(self): - self.cost_method = self.property_cost_method if self.property_cost_method else self.categ_id.property_cost_method + self.cost_method = self.property_cost_method or self.categ_id.property_cost_method @api.one def _set_cost_method(self): @@ -57,9 +57,8 @@ class ProductTemplate(models.Model): @api.onchange('type') def onchange_type_valuation(self): - if self.type != 'product': - self.valuation = 'manual_periodic' - return {} + # TO REMOVE IN MASTER + pass @api.multi def _get_product_accounts(self): @@ -90,9 +89,8 @@ class ProductProduct(models.Model): @api.onchange('type') def onchange_type_valuation(self): - if self.type != 'product': - self.valuation = 'manual_periodic' - return {} + # TO REMOVE IN MASTER + pass @api.multi def do_change_standard_price(self, new_price, account_id): diff --git a/addons/stock_account/views/product_views.xml b/addons/stock_account/views/product_views.xml index ef1ef186508..dc831fc9bba 100644 --- a/addons/stock_account/views/product_views.xml +++ b/addons/stock_account/views/product_views.xml @@ -33,8 +33,8 @@ - - + +