From 45c1fd968dd0283046079be05df729958d1de09b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20G=C3=B6ttsch?= Date: Fri, 12 Jun 2026 21:55:28 +0200 Subject: [PATCH] [FIX] nfu_sale_order_batch_packaging: add float_is_zero import and use uom precision instead of hardcoded 0.01 --- nfu_sale_order_batch_packaging/models/sale_order_batch.py | 6 +++--- .../models/sale_order_batch_product.py | 5 ++--- nfu_sale_order_batch_packaging/readme/HISTORY.rst | 2 +- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/nfu_sale_order_batch_packaging/models/sale_order_batch.py b/nfu_sale_order_batch_packaging/models/sale_order_batch.py index 45c14c5..cd2eac0 100644 --- a/nfu_sale_order_batch_packaging/models/sale_order_batch.py +++ b/nfu_sale_order_batch_packaging/models/sale_order_batch.py @@ -1,6 +1,6 @@ from odoo import api, fields, models - from odoo.addons.sale_order_batch.models.sale_order_batch import READONLY_FIELD_STATES +from odoo.tools import float_is_zero class SaleOrderBatch(models.Model): @@ -58,10 +58,10 @@ class SaleOrderBatch(models.Model): def action_fill_packages(self): self.ensure_one() eligible = self.product_ids.filtered( - lambda p: p.open_packaging_qty > 0 and p.open_packaging_max_qty == 0.0 + lambda p: p.open_packaging_qty > 0 and float_is_zero(p.open_packaging_max_qty, precision_rounding=p.product_id.uom_id.batch_fill_precision) ) ineligible = self.product_ids.filtered( - lambda p: p.open_packaging_qty > 0 and p.open_packaging_max_qty != 0.0 + lambda p: p.open_packaging_qty > 0 and not float_is_zero(p.open_packaging_max_qty, precision_rounding=p.product_id.uom_id.batch_fill_precision) ) wizard = self.env["sale.order.batch.packaging.fill"].create( { diff --git a/nfu_sale_order_batch_packaging/models/sale_order_batch_product.py b/nfu_sale_order_batch_packaging/models/sale_order_batch_product.py index a69ad9e..8758085 100644 --- a/nfu_sale_order_batch_packaging/models/sale_order_batch_product.py +++ b/nfu_sale_order_batch_packaging/models/sale_order_batch_product.py @@ -167,10 +167,9 @@ class SaleOrderBatchProduct(models.Model): # Attach any sub-rounding remainder directly to the last eligible line remainder = target - distributed if remainder > 1e-9 and last_line: - new_qty = float_round( - last_line.product_uom_qty + remainder, precision_rounding=rounding + new_qty = min( + last_line.product_uom_qty + remainder, last_line.product_uom_max_qty ) - new_qty = min(new_qty, last_line.product_uom_max_qty) last_line.write({"product_uom_qty": new_qty}) def _zero_packaging(self): diff --git a/nfu_sale_order_batch_packaging/readme/HISTORY.rst b/nfu_sale_order_batch_packaging/readme/HISTORY.rst index 6350d08..16306cc 100644 --- a/nfu_sale_order_batch_packaging/readme/HISTORY.rst +++ b/nfu_sale_order_batch_packaging/readme/HISTORY.rst @@ -1,6 +1,6 @@ - 16.0.0.0.1: Initial module. - 16.0.1.0.0: rename to nfu_sale_order_batch_packaging -- 16.0.1.16.0.1.0: Live +- 16.0.1.1.0: Live - 16.0.1.2.0: Add regeneration action for batch products - 16.0.1.2.1: refactoring - 16.0.1.3.0: add packaging states