From 18f62fd5cef3b6ec0f73f58dd411f2d6fef607aa Mon Sep 17 00:00:00 2001 From: Thierry Ducrest Date: Fri, 13 Oct 2023 11:41:17 +0200 Subject: [PATCH] fixup! Add shopfloor_location_package_restriction --- .../services/__init__.py | 3 +-- .../services/{zone_picking.py => service.py} | 16 +++++------- .../services/single_pack_transfer.py | 26 ------------------- ...test_single_pack_transfer_force_package.py | 20 ++++++++++---- 4 files changed, 23 insertions(+), 42 deletions(-) rename shopfloor_location_package_restriction/services/{zone_picking.py => service.py} (51%) delete mode 100644 shopfloor_location_package_restriction/services/single_pack_transfer.py diff --git a/shopfloor_location_package_restriction/services/__init__.py b/shopfloor_location_package_restriction/services/__init__.py index 60365b3d07a..72d6086eee6 100644 --- a/shopfloor_location_package_restriction/services/__init__.py +++ b/shopfloor_location_package_restriction/services/__init__.py @@ -1,2 +1 @@ -from . import single_pack_transfer -from . import zone_picking +from . import service diff --git a/shopfloor_location_package_restriction/services/zone_picking.py b/shopfloor_location_package_restriction/services/service.py similarity index 51% rename from shopfloor_location_package_restriction/services/zone_picking.py rename to shopfloor_location_package_restriction/services/service.py index f482df90ae1..a46349f343b 100644 --- a/shopfloor_location_package_restriction/services/zone_picking.py +++ b/shopfloor_location_package_restriction/services/service.py @@ -1,26 +1,24 @@ # Copyright 2023 Camptocamp SA # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) - from odoo.exceptions import ValidationError -from odoo.addons.component.core import Component +from odoo.addons.component.core import AbstractComponent + +class BaseShopfloorProcess(AbstractComponent): -class ShopfloorZonePicking(Component): - _inherit = "shopfloor.zone.picking" + _inherit = "base.shopfloor.process" - def _validate_destination(self, location, moves): - message = super()._validate_destination(location, moves) + def validate_dest_location(self, moves, location): + message = super().validate_dest_location(moves, location) if message: return message - if location.package_restriction != "norestriction": + if location.package_restriction: try: moves._check_location_package_restriction(only_qty_done=False) except ValidationError as ex: - # __import__("pdb").set_trace() return { "message_type": "error", "body": ex.name, } - # return self.msg_store.location_has_restrictions() diff --git a/shopfloor_location_package_restriction/services/single_pack_transfer.py b/shopfloor_location_package_restriction/services/single_pack_transfer.py deleted file mode 100644 index 5aba89ea91d..00000000000 --- a/shopfloor_location_package_restriction/services/single_pack_transfer.py +++ /dev/null @@ -1,26 +0,0 @@ -# Copyright 2023 Camptocamp SA -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) - - -from odoo.exceptions import ValidationError - -from odoo.addons.component.core import Component - - -class ShopfloorSinglePackTransfer(Component): - _inherit = "shopfloor.single.pack.transfer" - - def _validate_destination_location(self, package_level, location): - response = super()._validate_destination_location(package_level, location) - if response: - return response - if location.package_restriction != "norestriction": - # Not sure about this - # Could there be more move lines being checked than intended ? - moves = package_level.move_line_ids.move_id - try: - moves._check_location_package_restriction(location) - except ValidationError: - return self._response_for_scan_location( - package_level, message=self.msg_store.location_has_restrictions() - ) diff --git a/shopfloor_location_package_restriction/tests/test_single_pack_transfer_force_package.py b/shopfloor_location_package_restriction/tests/test_single_pack_transfer_force_package.py index 5413552af0c..dcc64eede54 100644 --- a/shopfloor_location_package_restriction/tests/test_single_pack_transfer_force_package.py +++ b/shopfloor_location_package_restriction/tests/test_single_pack_transfer_force_package.py @@ -27,19 +27,21 @@ def setUpClass(cls): ) ) cls.picking = cls._create_initial_move(lines=[(cls.product_a, 1)]) - cls.package_level = cls.picking.move_line_ids.package_level_id + cls.move_line = cls.picking.move_line_ids + cls.package_level = cls.move_line.package_level_id cls.package_level.is_done = True cls.picking.move_line_ids.qty_done = 1 # Add restriction on destination location cls.shelf2.sudo().package_restriction = "singlepackage" # Add a package on the destination location + cls.pack_1 = cls.env["stock.quant.package"].create( + {"location_id": cls.shelf2.id} + ) cls._update_qty_in_location( cls.shelf2, cls.product_a, 1, - package=cls.env["stock.quant.package"].create( - {"location_id": cls.shelf2.id} - ), + package=cls.pack_1, ) def test_scan_location_has_restrictions(self): @@ -51,9 +53,17 @@ def test_scan_location_has_restrictions(self): "location_barcode": self.shelf2.barcode, }, ) + message = { + "message_type": "error", + "body": ( + f"Only one package is allowed on the location " + f"{self.shelf2.display_name}.You cannot add " + f"the {self.move_line.package_id.name}, there is already {self.pack_1.name}." + ), + } self.assert_response( response, next_state="scan_location", data=self.ANY, - message=self.service.msg_store.location_has_restrictions(), + message=message, )