From 4b60ed0c5f60c5fb7298a7e43b8909656959ea37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Tue, 31 May 2022 23:57:32 +0200 Subject: [PATCH] Round actual quantity after the sum The sum of rounded quantity is not always a rounded value. issue11503 review431141003 (grafted from 4d7d93d2d54634a7419bc12719115e7573ff152e) --HG-- branch : 6.0 --- sale.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/sale.py b/sale.py index 84320df7ff..353fab3e41 100644 --- a/sale.py +++ b/sale.py @@ -1672,18 +1672,23 @@ class SaleLine(TaxableMixin, 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