From 536759644e13448f1c2b14d95cc8ecb44e5f0b24 Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Fri, 19 Jun 2020 10:17:57 +0000 Subject: [PATCH] [FIX] stock: reserved quantity on return of return 1. Activate receipt in 2 steps 2. Make a PO of 10 3. Receive 8 (pick 1), backorder 4. Receive 2 (pick 2) 5. Unreserve the internal transfer (pick 3) 6. Go to pick 2, return 2 (pick 4) => product is sent back to the supplier 7. Go to pick 4, return 2 (pick 5) => product is received from the supplier 8. Go to pick 3, check availability Only 8 units are reserved instead of 10. It happens because pick 5 (return of the return) is not linked to the pick 3 (internal transfer). We use a similar approach for `move_dest_to_link` than the one used for `move_orig_to_link`. Closes #52459 opw-2271838 closes odoo/odoo#53506 X-original-commit: c96339dd94ffe1e9c5103814062455c79d93a273 Signed-off-by: Nicolas Martinelli (nim) --- addons/stock/wizard/stock_picking_return.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/addons/stock/wizard/stock_picking_return.py b/addons/stock/wizard/stock_picking_return.py index 1ae97095df8..f553cbe1489 100644 --- a/addons/stock/wizard/stock_picking_return.py +++ b/addons/stock/wizard/stock_picking_return.py @@ -149,6 +149,14 @@ class ReturnPicking(models.TransientModel): .mapped('move_dest_ids').filtered(lambda m: m.state not in ('cancel'))\ .mapped('move_orig_ids').filtered(lambda m: m.state not in ('cancel')) move_dest_to_link = return_line.move_id.move_orig_ids.mapped('returned_move_ids') + # link to children of originally returned moves, if any. Note that the use of + # 'return_line.move_id.move_orig_ids.returned_move_ids.move_orig_ids.move_dest_ids' + # instead of 'return_line.move_id.move_orig_ids.move_dest_ids' prevents linking a + # return directly to the destination moves of its parents. However, the return of + # the return will be linked to the destination moves. + move_dest_to_link |= return_line.move_id.move_orig_ids.mapped('returned_move_ids')\ + .mapped('move_orig_ids').filtered(lambda m: m.state not in ('cancel'))\ + .mapped('move_dest_ids').filtered(lambda m: m.state not in ('cancel')) vals['move_orig_ids'] = [(4, m.id) for m in move_orig_to_link] vals['move_dest_ids'] = [(4, m.id) for m in move_dest_to_link] r.write(vals)