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: