From 455e3772d84bfd0635c5aeee889a74865439ec6e Mon Sep 17 00:00:00 2001 From: Thierry Ducrest Date: Mon, 17 Jul 2023 14:04:16 +0200 Subject: [PATCH] Fix stock_location_package_restriction for backorder Only check the restriction for moves actually being done. --- .../models/stock_move.py | 3 +- .../tests/test_stock_move.py | 43 +++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/stock_location_package_restriction/models/stock_move.py b/stock_location_package_restriction/models/stock_move.py index eea352f82289..a5e41c4fe54f 100644 --- a/stock_location_package_restriction/models/stock_move.py +++ b/stock_location_package_restriction/models/stock_move.py @@ -31,8 +31,9 @@ def _check_location_package_restriction(self): location_packages = { g["location_id"][0]: set(g["package_id"]) for g in quants_grouped } + lines_being_processed = self.move_line_ids.filtered(lambda line: line.qty_done) for location, move_lines in groupby( - self.move_line_ids, lambda m: m.location_dest_id + lines_being_processed, lambda m: m.location_dest_id ): if location.package_restriction == NORESTRICTION: continue diff --git a/stock_location_package_restriction/tests/test_stock_move.py b/stock_location_package_restriction/tests/test_stock_move.py index 7e73ec67e08f..f967a4b4f3cc 100644 --- a/stock_location_package_restriction/tests/test_stock_move.py +++ b/stock_location_package_restriction/tests/test_stock_move.py @@ -247,6 +247,49 @@ def test_03(self): with self.assertRaises(ValidationError): self._process_picking(picking) + def test_03_with_backorder(self): + """ + Data: + location_2 without package but with package restriction = 'single package' + a picking with two move with destination location_2 but only one move is + being processsed, backorder creation. + Test case: + Process the picking + Expected result: + One package in location no error + """ + self.location_2.package_restriction = SINGLEPACKAGE + picking = self._create_and_assign_picking( + [ + ShortMoveInfo( + product=self.product_1, + location_dest=self.location_2, + qty=2, + package_id=self.pack_1, + ), + ShortMoveInfo( + product=self.product_2, + location_dest=self.location_2, + qty=2, + package_id=self.pack_2, + ), + ], + location_dest=self.location_2, + ) + picking.action_assign() + # Processing only one move out of two + line_to_process = picking.move_line_ids[0] + line_to_process.qty_done = line_to_process.product_qty + wizard_action = picking.button_validate() + wizard_context = wizard_action.get("context", {}) + wizard = ( + self.env[wizard_action["res_model"]] + .with_context(**wizard_context) + .create({}) + ) + wizard.process() + self.assertEqual(self.pack_1, self._get_package_in_location(self.location_2)) + def test_04(self): """ Data: