From daaa255f04bf3d21f647cd87a870c875d5172334 Mon Sep 17 00:00:00 2001 From: Djamel Touati Date: Thu, 18 Apr 2024 11:59:12 +0200 Subject: [PATCH] [FIX] stock: use precision_rounding instead of digits with float_is_zero MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Steps to reproduce the bug: - Create a storable product “P1” - UoM: gram - Create an internal picking with 0.01g of P1 - Validate the picking - Create a return and try to validate it Problem: A UserError is triggered: “Please specify at least one non-zero quantity.” When creating a return, we check if the quantity is not zero using the “float_is_zero” function, but we mistakenly use rounding as precision_digits. opw-3862142" closes odoo/odoo#162389 Signed-off-by: Quentin Wolfs (quwo) --- addons/stock/tests/test_stock_return_picking.py | 11 ++++++----- addons/stock/wizard/stock_picking_return.py | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/addons/stock/tests/test_stock_return_picking.py b/addons/stock/tests/test_stock_return_picking.py index 0947c1047c1..4213bb37fa9 100644 --- a/addons/stock/tests/test_stock_return_picking.py +++ b/addons/stock/tests/test_stock_return_picking.py @@ -178,8 +178,9 @@ class TestReturnPicking(TestStockCommon): def test_return_wizard_with_partial_delivery(self): """ - Create a picking for 10 units, deliver 6, and do not backorder the remaining 4. - Then, attempt to return the quantity that was delivered. The return should be created with the correct quantity. + Create a picking for 10 grams, deliver 0.01, and do not backorder the remaining quantity. + Then, attempt to return the quantity that was delivered. The quantity should be properly verified + to not be equal to 0 and the return should be created. """ delivery_picking = self.PickingObj.create({ 'picking_type_id': self.picking_type_out, @@ -188,14 +189,14 @@ class TestReturnPicking(TestStockCommon): }) out_move = self.MoveObj.create({ 'name': "OUT move", - 'product_id':self.productA.id, + 'product_id': self.gB.id, 'product_uom_qty': 10, 'picking_id': delivery_picking.id, 'location_id': self.stock_location, 'location_dest_id': self.customer_location, }) delivery_picking.action_confirm() - out_move.quantity = 6 + out_move.quantity = 0.01 # No backorder res_dict = delivery_picking.with_context(picking_ids_not_to_backorder=delivery_picking.id).button_validate() @@ -206,4 +207,4 @@ class TestReturnPicking(TestStockCommon): .with_context(active_ids=delivery_picking.ids, active_id=delivery_picking.ids[0], active_model='stock.picking')) stock_return_picking = stock_return_picking_form.save() - self.assertEqual(stock_return_picking.product_return_moves.quantity, 6) + self.assertEqual(stock_return_picking.product_return_moves.quantity, 0.01) diff --git a/addons/stock/wizard/stock_picking_return.py b/addons/stock/wizard/stock_picking_return.py index 2309c28c761..0fe0067b497 100644 --- a/addons/stock/wizard/stock_picking_return.py +++ b/addons/stock/wizard/stock_picking_return.py @@ -142,7 +142,7 @@ class ReturnPicking(models.TransientModel): for return_line in self.product_return_moves: if not return_line.move_id: raise UserError(_("You have manually created product lines, please delete them to proceed.")) - if not float_is_zero(return_line.quantity, return_line.uom_id.rounding): + if not float_is_zero(return_line.quantity, precision_rounding=return_line.uom_id.rounding): returned_lines += 1 vals = self._prepare_move_default_values(return_line, new_picking) r = return_line.move_id.copy(vals)