From c0d5908c6ad5156b767d85bb5cabeab2f3bd0a10 Mon Sep 17 00:00:00 2001 From: "Walid HANNICHE (waha)" Date: Thu, 16 Mar 2023 10:54:31 +0000 Subject: [PATCH] [FIX] stock: set correct return quantity Steps to reproduce: -Enable multistep routes for manufacturing -create a MO for 50 products -In internal transfers from Stock to Pre-production validate part of the tansfer (20 units) and create a back order for the remaining qty (30 units) -create and validate another pertail transfer (3 units)with a back order for the remaining quantity (27 units) -create a return for the last validated transfers Bug: the default qty for the return is set to -20 where it should be 3 this commit[1] deducts the previous transfers from the returned amount Fix: only deduct returns from current transfer opw-3104699 [1]:https://github.com/odoo/odoo/commit/7b08f0ae0a39e8f575b21e744de16264b6365704 closes odoo/odoo#115929 X-original-commit: 0278a4a7ba5cdd7a722e5d576d22820a3ee64308 Signed-off-by: William Henrotin (whe) Signed-off-by: Walid Hanniche (waha) --- addons/sale_stock/tests/test_sale_stock.py | 31 +++++++++++++++++++++ addons/stock/wizard/stock_picking_return.py | 2 +- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/addons/sale_stock/tests/test_sale_stock.py b/addons/sale_stock/tests/test_sale_stock.py index e6bd2700823..2857f3caf6f 100644 --- a/addons/sale_stock/tests/test_sale_stock.py +++ b/addons/sale_stock/tests/test_sale_stock.py @@ -1232,6 +1232,37 @@ class TestSaleStock(TestSaleCommon, ValuationReconciliationTestCommon): self.assertEqual(so.order_line[1].qty_delivered, 1) self.assertEqual(so.order_line[1].product_uom.id, uom_km_id) + def test_multiple_returns(self): + # Creates a sale order for 10 products. + sale_order = self._get_new_sale_order() + # Valids the sale order, then valids the delivery. + sale_order.action_confirm() + picking = sale_order.picking_ids + picking.move_ids.write({'quantity_done': 10}) + picking.button_validate() + + # Creates a return from the delivery picking. + return_picking_form = Form(self.env['stock.return.picking'] + .with_context(active_ids=picking.ids, active_id=picking.id, + active_model='stock.picking')) + return_wizard = return_picking_form.save() + # Check that the correct quantity is set on the retrun + self.assertEqual(return_wizard.product_return_moves.quantity, 10) + return_wizard.product_return_moves.quantity = 2 + # Valids the return picking. + res = return_wizard.create_returns() + return_picking = self.env['stock.picking'].browse(res['res_id']) + return_picking.move_ids.write({'quantity_done': 2}) + return_picking.button_validate() + + # Creates a second return from the delivery picking. + return_picking_form = Form(self.env['stock.return.picking'] + .with_context(active_ids=picking.ids, active_id=picking.id, + active_model='stock.picking')) + return_wizard = return_picking_form.save() + # Check that the remaining quantity is set on the retrun + self.assertEqual(return_wizard.product_return_moves.quantity, 8) + def test_return_with_mto_and_multisteps(self): """ Suppose a product P and a 3-steps delivery. diff --git a/addons/stock/wizard/stock_picking_return.py b/addons/stock/wizard/stock_picking_return.py index 80db63fcc54..08e993b296b 100644 --- a/addons/stock/wizard/stock_picking_return.py +++ b/addons/stock/wizard/stock_picking_return.py @@ -79,7 +79,7 @@ class ReturnPicking(models.TransientModel): def _prepare_stock_return_picking_line_vals_from_move(self, stock_move): quantity = stock_move.product_qty for move in stock_move.move_dest_ids: - if move.origin_returned_move_id and move.origin_returned_move_id != stock_move: + if not move.origin_returned_move_id or move.origin_returned_move_id != stock_move: continue if move.state in ('partially_available', 'assigned'): quantity -= sum(move.move_line_ids.mapped('reserved_qty'))