From 9dc0af07d7aaf74a562b6c5f6210136fd27afdf9 Mon Sep 17 00:00:00 2001 From: Michael Tietz Date: Wed, 15 Jan 2025 15:56:48 +0100 Subject: [PATCH] [IMP] shopfloor: Sync src location on single_pack_transer and single_product_transfer --- shopfloor/actions/stock.py | 9 ++++++++- shopfloor/services/single_pack_transfer.py | 2 +- shopfloor/tests/test_single_pack_transfer.py | 18 ++++++++++++++++-- shopfloor_checkout_sync/actions/stock.py | 8 ++++++-- .../services/single_product_transfer.py | 4 +++- .../tests/test_set_quantity.py | 15 ++++++++++++++- 6 files changed, 48 insertions(+), 8 deletions(-) diff --git a/shopfloor/actions/stock.py b/shopfloor/actions/stock.py index 8d16f7cec1..265a429f64 100644 --- a/shopfloor/actions/stock.py +++ b/shopfloor/actions/stock.py @@ -242,8 +242,15 @@ def _set_destination_on_lines( def _unload_package(self, lines): lines.result_package_id = False - def set_locations_and_unload_lines(self, lines, location_dest, unload=False): + def _sync_src_location(self, lines): + lines.move_id.location_id = lines.location_id + + def set_locations_and_unload_lines( + self, lines, location_dest, unload=False, sync_src_location=False + ): self._lock_lines(lines) self._set_destination_on_lines(lines, location_dest) if unload: self._unload_package(lines) + if sync_src_location: + self._sync_src_location(lines) diff --git a/shopfloor/services/single_pack_transfer.py b/shopfloor/services/single_pack_transfer.py index 5c0b0fb619..0f359af2f0 100644 --- a/shopfloor/services/single_pack_transfer.py +++ b/shopfloor/services/single_pack_transfer.py @@ -271,7 +271,7 @@ def _set_destination_and_done(self, package_level, scanned_location): # on the move lines stock = self._actions_for("stock") stock.set_locations_and_unload_lines( - package_level.move_line_ids, scanned_location + package_level.move_line_ids, scanned_location, sync_src_location=True ) stock.put_package_level_in_move(package_level) stock.validate_moves(package_level.move_line_ids.move_id) diff --git a/shopfloor/tests/test_single_pack_transfer.py b/shopfloor/tests/test_single_pack_transfer.py index 180cb32375..ef1fc40e18 100644 --- a/shopfloor/tests/test_single_pack_transfer.py +++ b/shopfloor/tests/test_single_pack_transfer.py @@ -1,5 +1,6 @@ # Copyright 2020 Camptocamp SA (http://www.camptocamp.com) # Copyright 2020 Akretion (http://www.akretion.com) +# Copyright 2025 Michael Tietz (MT Software) # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from odoo.tests.common import Form @@ -449,11 +450,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.id, + "state": "done", + } + ], ) def test_validate_completion_info(self): diff --git a/shopfloor_checkout_sync/actions/stock.py b/shopfloor_checkout_sync/actions/stock.py index 1b08596791..77a3be62e5 100644 --- a/shopfloor_checkout_sync/actions/stock.py +++ b/shopfloor_checkout_sync/actions/stock.py @@ -12,7 +12,11 @@ def _set_destination_on_lines(self, lines, location_dest): checkout_sync._sync_checkout(lines, location_dest) super()._set_destination_on_lines(lines, location_dest) - def set_locations_and_unload_lines(self, lines, location_dest, unload=False): + def set_locations_and_unload_lines( + self, lines, location_dest, unload=False, sync_src_location=False + ): checkout_sync = self._actions_for("checkout.sync") checkout_sync._all_lines_to_lock(lines) - super().set_locations_and_unload_lines(lines, location_dest, unload) + super().set_locations_and_unload_lines( + lines, location_dest, unload, sync_src_location + ) diff --git a/shopfloor_single_product_transfer/services/single_product_transfer.py b/shopfloor_single_product_transfer/services/single_product_transfer.py index 98bda9be58..34f141b920 100644 --- a/shopfloor_single_product_transfer/services/single_product_transfer.py +++ b/shopfloor_single_product_transfer/services/single_product_transfer.py @@ -613,7 +613,9 @@ def _set_quantity__check_location( def _write_destination_on_lines(self, lines, location): stock = self._actions_for("stock") - stock.set_locations_and_unload_lines(lines, location) + stock.set_locations_and_unload_lines(lines, location, sync_src_location=True) + # lines.move_id.location_dest_id = location + # lines.move_id.location_id = lines.location_id def _set_quantity__post_move(self, move_line, location, confirmation=None): # TODO qty_done = 0: transfer_no_qty_done diff --git a/shopfloor_single_product_transfer/tests/test_set_quantity.py b/shopfloor_single_product_transfer/tests/test_set_quantity.py index 23e21cdff2..3810cf169e 100644 --- a/shopfloor_single_product_transfer/tests/test_set_quantity.py +++ b/shopfloor_single_product_transfer/tests/test_set_quantity.py @@ -1,4 +1,5 @@ # Copyright 2022 Camptocamp SA +# Copyright 2025 Michael Tietz (MT Software) # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) from .common import CommonCase @@ -8,7 +9,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 @@ -725,6 +726,12 @@ 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.location) def test_set_quantity_scan_location_allow_move_create(self): self.menu.sudo().allow_move_create = True @@ -754,6 +761,12 @@ 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.location) def test_set_quantity_scan_package_not_empty(self): # We scan a package that's not empty