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)