From 9acedea3d5d40cc32a99cca8dcb459893b1f4f33 Mon Sep 17 00:00:00 2001 From: Michael Tietz Date: Fri, 17 Jan 2025 15:36:13 +0100 Subject: [PATCH] [IMP] shopfloor: Ensure destination location is also set on move --- shopfloor/actions/stock.py | 1 + shopfloor/tests/test_single_pack_transfer.py | 74 ++++++++++++++++++- .../tests/test_set_quantity.py | 24 +++++- 3 files changed, 95 insertions(+), 4 deletions(-) diff --git a/shopfloor/actions/stock.py b/shopfloor/actions/stock.py index 77ed932ee9..69a4f32592 100644 --- a/shopfloor/actions/stock.py +++ b/shopfloor/actions/stock.py @@ -242,6 +242,7 @@ def _set_destination_on_lines(self, lines, location_dest): lines_with_package_level.package_level_id.location_dest_id = location_dest if lines_without_package_level: lines_without_package_level.location_dest_id = location_dest + lines_without_package_level.move_id.location_dest_id = location_dest def _unload_package(self, lines): lines.result_package_id = False diff --git a/shopfloor/tests/test_single_pack_transfer.py b/shopfloor/tests/test_single_pack_transfer.py index 180cb32375..0fa23736a2 100644 --- a/shopfloor/tests/test_single_pack_transfer.py +++ b/shopfloor/tests/test_single_pack_transfer.py @@ -186,7 +186,8 @@ def test_start_no_operation_create(self): package_level = move_line.package_level_id self.assertTrue(package_level.is_done) - + self.assertEqual(move_line.location_id, self.pack_a.location_id) + self.assertEqual(move_line.move_id.location_id, self.pack_a.location_id) expected_data = { "id": package_level.id, "name": package_level.package_id.name, @@ -204,6 +205,60 @@ def test_start_no_operation_create(self): self.assert_response(response, next_state="scan_location", data=expected_data) + def test_start_validate_no_operation_create(self): + self.menu.sudo().allow_move_create = True + self.picking.do_unreserve() + barcode = self.pack_a.name + params = {"barcode": barcode} + + # Simulate the client scanning a package's barcode, which + # in turns should start the operation in odoo + response = self.service.dispatch("start", params=params) + + move_line = self.env["stock.move.line"].search( + [("package_id", "=", self.pack_a.id)] + ) + package_level = move_line.package_level_id + + response = self.service.dispatch( + "validate", + params={ + "package_level_id": package_level.id, + "location_barcode": self.shelf2.barcode, + }, + ) + + self.assert_response( + response, + next_state="start", + message={ + "message_type": "success", + "body": "The pack has been moved, you can scan a new pack.", + }, + ) + + self.assertRecordValues( + package_level.move_line_ids, + [ + { + "qty_done": 1.0, + "location_dest_id": self.shelf2.id, + "location_id": self.shelf1.id, + "state": "done", + } + ], + ) + self.assertRecordValues( + package_level.move_line_ids.move_id, + [ + { + "location_dest_id": self.shelf2.id, + "location_id": self.shelf1.id, + "state": "done", + } + ], + ) + def test_start_barcode_not_known(self): """Test /start when the barcode is unknown @@ -449,11 +504,24 @@ def test_validate(self): self.assertRecordValues( package_level.move_line_ids, - [{"qty_done": 1.0, "location_dest_id": self.shelf2.id, "state": "done"}], + [ + { + "qty_done": 1.0, + "location_dest_id": self.shelf2.id, + "location_id": self.shelf1.id, + "state": "done", + } + ], ) self.assertRecordValues( package_level.move_line_ids.move_id, - [{"location_dest_id": self.shelf2.id, "state": "done"}], + [ + { + "location_dest_id": self.shelf2.id, + "location_id": self.shelf1.location_id.id, + "state": "done", + } + ], ) def test_validate_completion_info(self): diff --git a/shopfloor_single_product_transfer/tests/test_set_quantity.py b/shopfloor_single_product_transfer/tests/test_set_quantity.py index 23e21cdff2..1353e22413 100644 --- a/shopfloor_single_product_transfer/tests/test_set_quantity.py +++ b/shopfloor_single_product_transfer/tests/test_set_quantity.py @@ -8,7 +8,7 @@ class TestSetQuantity(CommonCase): @classmethod def setUpClass(cls): super().setUpClass() - cls.location = cls.location_src + cls.location = cls.env.ref("stock.stock_location_components") cls.product = cls.product_a cls.packaging = cls.product_a_packaging cls.packaging.qty = 5 @@ -429,6 +429,10 @@ def test_set_quantity_scan_packaging_with_allow_move_create(self): self.assert_response( response, next_state="select_product", message=expected_message, data=data ) + self.assertEqual(move_line.location_dest_id, self.dispatch_location) + self.assertEqual(move_line.location_id, location) + self.assertEqual(move_line.move_id.location_dest_id, self.dispatch_location) + self.assertEqual(move_line.move_id.location_id, location) def test_set_quantity_scan_packaging_with_allow_move_create_and_no_prefill_qty( self, @@ -725,6 +729,15 @@ def test_set_quantity_scan_location(self): self.assertFalse(picking.move_line_ids.result_package_id) self.assertEqual(picking.user_id.id, False) self.assertEqual(picking.move_line_ids.shopfloor_user_id.id, False) + self.assertEqual(picking.move_line_ids.location_dest_id, self.dispatch_location) + self.assertEqual(picking.move_line_ids.location_id, self.location) + self.assertEqual( + picking.move_line_ids.move_id.location_dest_id, self.dispatch_location + ) + self.assertEqual( + picking.move_line_ids.move_id.location_id, + self.picking_type.default_location_src_id, + ) def test_set_quantity_scan_location_allow_move_create(self): self.menu.sudo().allow_move_create = True @@ -754,6 +767,15 @@ def test_set_quantity_scan_location_allow_move_create(self): self.assertFalse(backorder) self.assertEqual(picking.move_line_ids.qty_done, 6.0) self.assertEqual(picking.move_line_ids.state, "done") + self.assertEqual(picking.move_line_ids.location_dest_id, self.dispatch_location) + self.assertEqual(picking.move_line_ids.location_id, self.location) + self.assertEqual( + picking.move_line_ids.move_id.location_dest_id, self.dispatch_location + ) + self.assertEqual( + picking.move_line_ids.move_id.location_id, + self.picking_type.default_location_src_id, + ) def test_set_quantity_scan_package_not_empty(self): # We scan a package that's not empty