From 8482fb8a929df1c09beed2bbaeebd6bebaf6d903 Mon Sep 17 00:00:00 2001 From: Adrien Widart Date: Thu, 14 Jul 2022 08:47:35 +0000 Subject: [PATCH] [FIX] stock: avoid putaway rules application with extra-SM When receiving more than expected, we try to redirect the SM thanks to the putaway rules. This can lead to undesirable behaviors. To reproduce the issue: 1. In Settings, enable 'Storage Locations' 2. Create a storable product P 3. Edit the operation type "Receipt": - Show Detailed Operations: True 4. Create and confirm a planned receipt for 1 x P 5. In the Detailed Operations: - Set the done quantity to 3 - Set the destination location to Shelf 1 6. Validate the receipt Error: The destination location of the SML has changed: Stock. It should still be Shelf 1 When validating the SM, because the done quantity is more than the demand, an exra-move is created. During such a process, the extra move is confirmed and assigned, so it leads to the destination redirection thanks to the putaway rules (that's the reason why the destination Stock will be selected and defined on the SML). In such situation, we should not try to apply the putaway rules. OPW-2900283 closes odoo/odoo#96124 X-original-commit: 0183298293192538a801f52262c047ea34a1b76a Signed-off-by: Arnold Moyaux (arm) Signed-off-by: Adrien Widart --- addons/stock/models/stock_move.py | 2 +- addons/stock/models/stock_move_line.py | 2 ++ addons/stock/tests/test_move.py | 23 +++++++++++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) 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])