Round actual quantity after the sum

The sum of rounded quantity is not always a rounded value.

issue11503
review431141003
This commit is contained in:
Cédric Krier committed 2022-05-31 23:57:32 +02:00
1 parent 2dbbeb2775
commit 276eed83dc
1 file changed
+10 -5
+10 -5
View File
@@ -1718,18 +1718,23 @@ class Line(sequence_ordered(), ModelSQL, ModelView):
return
moved_quantity = 0
for move in self.moves:
if move.state != 'cancelled':
if move.state != 'cancelled' and self.unit:
moved_quantity += Uom.compute_qty(
move.uom, move.quantity, self.unit)
move.uom, move.quantity, self.unit, round=False)
if self.quantity < 0:
moved_quantity *= -1
invoiced_quantity = 0
for invoice_line in self.invoice_lines:
if (not invoice_line.invoice
or invoice_line.invoice.state != 'cancelled'):
if (
(not invoice_line.invoice
or invoice_line.invoice.state != 'cancelled')
and self.unit and invoice_line.unit):
invoiced_quantity += Uom.compute_qty(
invoice_line.unit, invoice_line.quantity, self.unit)
invoice_line.unit, invoice_line.quantity, self.unit,
round=False)
actual_quantity = max(moved_quantity, invoiced_quantity, key=abs)
if self.unit:
actual_quantity = self.unit.round(actual_quantity)
if self.actual_quantity != actual_quantity:
self.actual_quantity = actual_quantity