[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
This commit is contained in:
Nicolas Martinelli
2016-10-28 08:21:55 +02:00
parent dc62cd8e00
commit e4762229ba
2 changed files with 8 additions and 10 deletions
+6 -8
View File
@@ -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):
+2 -2
View File
@@ -33,8 +33,8 @@
<field name="arch" type="xml">
<data>
<field name="list_price" position="after">
<field name="valuation" invisible="1"/>
<field name="cost_method" invisible="1"/>
<field name="valuation" invisible="1" readonly="1"/>
<field name="cost_method" invisible="1" readonly="1"/>
<field name="property_cost_method" groups="stock_account.group_inventory_valuation" invisible="1"/>
</field>
<field name="standard_price" position="replace">