diff --git a/addons/stock/models/stock_move.py b/addons/stock/models/stock_move.py index 01923d1d824..05bc0a0a7c3 100644 --- a/addons/stock/models/stock_move.py +++ b/addons/stock/models/stock_move.py @@ -1641,7 +1641,7 @@ class StockMove(models.Model): precision_rounding=rounding, rounding_method='HALF-UP') extra_move_vals = self._prepare_extra_move_vals(extra_move_quantity) - extra_move = self.copy(default=extra_move_vals) + extra_move = self.copy(default=extra_move_vals).with_context(avoid_putaway_rules=True) merge_into_self = all(self[field] == extra_move[field] for field in self._prepare_merge_moves_distinct_fields()) diff --git a/addons/stock/models/stock_move_line.py b/addons/stock/models/stock_move_line.py index 632aa8f94b6..aa0c0ae107a 100644 --- a/addons/stock/models/stock_move_line.py +++ b/addons/stock/models/stock_move_line.py @@ -226,6 +226,8 @@ class StockMoveLine(models.Model): packaging=self.move_id.product_packaging_id) def _apply_putaway_strategy(self): + if self._context.get('avoid_putaway_rules'): + return self = self.with_context(do_not_unreserve=True) for package, smls in groupby(self, lambda sml: sml.result_package_id): smls = self.env['stock.move.line'].concat(*smls) diff --git a/addons/stock/tests/test_move.py b/addons/stock/tests/test_move.py index 36de38fa786..43c4e7e670b 100644 --- a/addons/stock/tests/test_move.py +++ b/addons/stock/tests/test_move.py @@ -5771,3 +5771,26 @@ class StockMove(TransactionCase): }) self.assertEqual(move.move_line_ids.location_id, self.stock_location) self.assertEqual(move.move_line_ids.location_dest_id, self.customer_location) + + def test_receive_more_and_in_child_location(self): + """ + Ensure that, when receiving more than expected, and when the destination + location of the SML is different from the SM one, the SM validation will + not change the destination location of the SML + """ + move = self.env['stock.move'].create({ + 'name': self.product.name, + 'location_id': self.supplier_location.id, + 'location_dest_id': self.stock_location.id, + 'product_id': self.product.id, + 'product_uom': self.uom_unit.id, + 'product_uom_qty': 1.0, + }) + move._action_confirm() + move.move_line_ids.write({ + 'location_dest_id': self.stock_location.child_ids[0].id, + 'qty_done': 3, + }) + move._action_done() + self.assertEqual(move.move_line_ids.qty_done, 3) + self.assertEqual(move.move_line_ids.location_dest_id, self.stock_location.child_ids[0])