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
This commit is contained in:
Cédric Krier committed 2014-09-30 09:44:28 +02:00
1 parent 80ab8af123
commit ba5824c138
1 file changed
+7 -3
+7 -3
View File
@@ -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,