[FIX] stock: stock_inventory_line onchange product

If you make an inventory adjustement in mode 'select products manually'
and you add a new line with a product having a different unit of mesure
than the default one, but in the same unit of mesure category than the
default one, the unit of mesure on the line doesn't change because both
are in the same category.

This bug is caused by an 'onchange' which is triggered when the
'product_id' or 'product_uom_id' has been changed. And so we cannot
force to change the value to the product one, because we should still be
able to make an inventory in 'kg', if the unit of mesure is in 'g'.

So to fix this bug, we have set the 'onchange' only on the product_id to
set the unit of mesure set on the product when we create a new line or
change the product of a line. We removed the onchange ont the unit of
mesure, because it was only checking that the unit of mesure is in the
category of the product unit of mesure category, but it's always true
has there is a domain set on the field unit on mesure by the onchange
on product_id
This commit is contained in:
Pierre Masereel
2017-01-25 13:45:29 +01:00
parent 74c6e895f6
commit f23394b83a
+3 -3
View File
@@ -274,11 +274,11 @@ class InventoryLine(models.Model):
theoretical_qty = self.env["product.uom"]._compute_qty_obj(self.product_id.uom_id, theoretical_qty, self.product_uom_id)
self.theoretical_qty = theoretical_qty
@api.onchange('product_id', 'product_uom_id')
def onchange_product_or_uom(self):
@api.onchange('product_id')
def onchange_product(self):
res = {}
# If no UoM or incorrect UoM put default one from product
if self.product_id and (not self.product_uom_id or self.product_id.uom_id.category_id != self.product_uom_id.category_id):
if self.product_id:
self.product_uom_id = self.product_id.uom_id
res['domain'] = {'product_uom_id': [('category_id', '=', self.product_id.uom_id.category_id.id)]}
return res