From 4128871c6342aaf6463b60f3db090ed1f1867917 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20G=C3=B6ttsch?= Date: Mon, 7 Oct 2024 22:18:01 +0200 Subject: [PATCH] [IMP] nfu_ecommerce,nfu_sale_order_batch_packaging: use python rounding to get rid of buggy float_round --- nfu_ecommerce/models/sale_order_line.py | 9 ++------- nfu_sale_order_batch_packaging/models/sale_order_line.py | 4 +++- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/nfu_ecommerce/models/sale_order_line.py b/nfu_ecommerce/models/sale_order_line.py index a3225fa..31b6b3f 100644 --- a/nfu_ecommerce/models/sale_order_line.py +++ b/nfu_ecommerce/models/sale_order_line.py @@ -1,5 +1,5 @@ from odoo import fields, models -from odoo.tools import float_is_zero, float_repr, float_round +from odoo.tools import float_is_zero, float_round class SaleOrderLine(models.Model): @@ -16,12 +16,7 @@ class SaleOrderLine(models.Model): line.batch_uom_qty % line.product_packaging_id.qty, precision_rounding=precision_rounding ) if not float_is_zero(qty_of_last_pack, precision_rounding=precision_rounding): - open_qty = float_round( - line.product_packaging_id.qty - qty_of_last_pack, precision_rounding=precision_rounding - ) - # somehow float_rounding() does not capture all cases ex. float_rounding(2-1.1) - # this is a samll workaround - line.open_qty = float(float_repr(open_qty, precision_digits)) + line.open_qty = round(line.product_packaging_id.qty - qty_of_last_pack, precision_digits) else: line.open_qty = 0.0 else: diff --git a/nfu_sale_order_batch_packaging/models/sale_order_line.py b/nfu_sale_order_batch_packaging/models/sale_order_line.py index e01a175..d6ff040 100644 --- a/nfu_sale_order_batch_packaging/models/sale_order_line.py +++ b/nfu_sale_order_batch_packaging/models/sale_order_line.py @@ -28,13 +28,15 @@ class SaleOrderLine(models.Model): if line.order_id.batch_id: batch_id = line.batch_id product_id = line.product_id + precision_rounding = line.product_id.uom_id.rounding + precision_digits = len(str(precision_rounding).split(".")[1]) batch_lines = ( self.env["sale.order.line"] .sudo() .search([("batch_id", "=", batch_id.id), ("product_id", "=", product_id.id)]) ) line.batch_uom_qty = sum(batch_lines.mapped("product_uom_qty")) - line.batch_uom_max_qty = sum(batch_lines.mapped("product_uom_max_qty")) + line.batch_uom_max_qty = round(sum(batch_lines.mapped("product_uom_max_qty")), precision_digits) else: line.batch_uom_max_qty = line.batch_uom_qty = 0