From ba5824c1388fc649ec67153b68198472aa70bf2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Tue, 30 Sep 2014 09:44:28 +0200 Subject: [PATCH] Round quantity before using it on invoice line or stock move Precision can be lost also with only addition and substraction because of float, so quantity must be rounded before used on invoice line or stock move. issue4191 review13551002 --- purchase.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/purchase.py b/purchase.py index ac2477aa7c..de74312319 100644 --- a/purchase.py +++ b/purchase.py @@ -1291,11 +1291,12 @@ class PurchaseLine(ModelSQL, ModelView): if old_invoice_line.id not in skip_ids: quantity -= Uom.compute_qty(old_invoice_line.unit, old_invoice_line.quantity, self.unit) - invoice_line.quantity = quantity rounding = self.unit.rounding if self.unit else 0 - if invoice_line.quantity < rounding: + invoice_line.quantity = Uom.round(quantity, rounding) + if invoice_line.quantity <= 0: return [] + invoice_line.unit = self.unit invoice_line.product = self.product invoice_line.unit_price = self.unit_price @@ -1349,8 +1350,11 @@ class PurchaseLine(ModelSQL, ModelView): if move not in skip: quantity -= Uom.compute_qty(move.uom, move.quantity, self.unit) - if quantity < self.unit.rounding: + + quantity = Uom.round(quantity, self.unit.rounding) + if quantity <= 0: return + if not self.purchase.party.supplier_location: self.raise_user_error('supplier_location_required', { 'purchase': self.purchase.rec_name,