From ab940a921edcf68a7e049231dc971a28085ef2fa Mon Sep 17 00:00:00 2001 From: Florian Damhaut Date: Thu, 30 Dec 2021 12:09:17 +0000 Subject: [PATCH] [FIX] product: packaging correctly chosen Step to reproduce: - create a unit of measurement (UoM) and set it's rounding to 1.000 - create a product that uses this UoM - create two packaging for this product - create a sales order and in the sales order line set the created product - you can already see the packaging is set, but anyways set a quantity to near the defined in the package - the quantity will be updated Current behaviour: - Packaging always update to bigger package even if it doesn't fit Behaviour after PR: - Packaging update to the biggest package which is a full divider of the qty - If no package fit, then no package are applied opw-2718146 closes odoo/odoo#85351 X-original-commit: ad047434a802abfc9f4203897aec9cda149dd43b Signed-off-by: Tiffany Chang Signed-off-by: Damhaut Florian (flda) --- addons/product/models/product_packaging.py | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/addons/product/models/product_packaging.py b/addons/product/models/product_packaging.py index 6b409558e7f..9e622054c19 100644 --- a/addons/product/models/product_packaging.py +++ b/addons/product/models/product_packaging.py @@ -48,19 +48,10 @@ class ProductPackaging(models.Model): # per package might be a float, leading to incorrect results. For example: # 8 % 1.6 = 1.5999999999999996 # 5.4 % 1.8 = 2.220446049250313e-16 - if ( - product_qty - and packaging_qty - and float_compare( - product_qty / packaging_qty, - float_round(product_qty / packaging_qty, precision_rounding=1.0), - precision_rounding=default_uom.rounding - ) - != 0 - ): - return float_round( - product_qty / packaging_qty, precision_rounding=1.0, rounding_method=rounding_method - ) * packaging_qty + if product_qty and packaging_qty: + rounded_qty = float_round(product_qty / packaging_qty, precision_rounding=1.0, + rounding_method=rounding_method) * packaging_qty + return rounded_qty if float_compare(rounded_qty, product_qty, precision_rounding=default_uom.rounding) else product_qty return product_qty def _find_suitable_product_packaging(self, product_qty, uom_id):