From d80f4e04c0a8ac2c7553064126de89d6f2366bc2 Mon Sep 17 00:00:00 2001 From: Arnold Moyaux Date: Fri, 27 Oct 2023 13:20:13 +0200 Subject: [PATCH] [FIX] stock: redirect move lines location dest Changing the destination location on a picking will: - Change the dest location of its stock.move - Not change the dest location of stock.move.line So it the picking has been reserved, everything will be send to an incorrect location. On top of it, the system prevent to select a destination location that is not a child of the move dest location. This commit, redirect the location dest on stock.move.line when the dest location on stock.move change. closes odoo/odoo#140101 Signed-off-by: William Henrotin (whe) --- addons/stock/models/stock_move.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/addons/stock/models/stock_move.py b/addons/stock/models/stock_move.py index d6654399b5c..ba3d9ce1bc5 100644 --- a/addons/stock/models/stock_move.py +++ b/addons/stock/models/stock_move.py @@ -612,6 +612,7 @@ Please change the quantity done or the rounding precision of your unit of measur receipt_moves_to_reassign = self.env['stock.move'] move_to_recompute_state = self.env['stock.move'] move_to_confirm = self.env['stock.move'] + move_to_check_dest_location = self.env['stock.move'] if 'quantity' in vals: if any(move.state == 'cancel' for move in self): raise UserError(_('You cannot change a cancelled stock move, create a new line instead.')) @@ -643,10 +644,18 @@ Please change the quantity done or the rounding precision of your unit of measur self._set_date_deadline(vals.get('date_deadline')) if 'move_orig_ids' in vals: move_to_recompute_state |= self.filtered(lambda m: m.state not in ['draft', 'cance', 'done']) - + if 'location_dest_id' in vals: + move_to_check_dest_location = self.filtered(lambda m: m.location_dest_id.id != vals.get('location_dest_id')) res = super(StockMove, self).write(vals) if move_to_recompute_state: move_to_recompute_state._recompute_state() + if move_to_check_dest_location: + for ml in move_to_check_dest_location.move_line_ids: + parent_path = [int(id) for id in ml.location_dest_id.parent_path.split('/')[:-1]] + if ml.move_id.location_dest_id.id in parent_path: + continue + loc_dest = ml.move_id.location_dest_id._get_putaway_strategy(ml.product_id, ml.quantity_product_uom) + ml.location_dest_id = loc_dest if move_to_confirm: move_to_confirm._action_assign() if receipt_moves_to_reassign: