[FIX] sale_stock: fix onchange product_uom_qty

opw-1916064

Have a sales order line on which you decrease the quantity.
Before, this commit, the warning message that says to update the
delivery order did not show. This was because, the onchange in the
python side compared the new quantity against the saved one, and did
not find any difference. This is caused by the onchange itself, which,
in a o2m setting, received from the JS, the changed order
(already containing the changed line) and only then proceeded to the
onchange of the line. The first operation wrote onto _origin the new
line value, which corresponded subsequently to the new value.

After this commit, we compare the real value explicitly retrieved from
the database to the one just entered by the user as an onchange.
The warning message works as expected.

Long story short, _origin in an onchange doesn't guarantee to yield
persisted values in all cases.

closes odoo/odoo#29582
This commit is contained in:
Jorge Pinna Puissant
2018-12-17 14:31:47 +00:00
parent a473a1bb88
commit 8fe7229e19
+8 -1
View File
@@ -188,7 +188,14 @@ class SaleOrderLine(models.Model):
@api.onchange('product_uom_qty')
def _onchange_product_uom_qty(self):
if self.state == 'sale' and self.product_id.type in ['product', 'consu'] and self.product_uom_qty < self._origin.product_uom_qty:
# When modifying a one2many, _origin doesn't guarantee that its values will be the ones
# in database. Hence, we need to explicitly read them from there.
if self._origin:
product_uom_qty_origin = self._origin.read(["product_uom_qty"])[0]["product_uom_qty"]
else:
product_uom_qty_origin = 0
if self.state == 'sale' and self.product_id.type in ['product', 'consu'] and self.product_uom_qty < product_uom_qty_origin:
# Do not display this warning if the new quantity is below the delivered
# one; the `write` will raise an `UserError` anyway.
if self.product_uom_qty < self.qty_delivered: