diff --git a/shopfloor/actions/message.py b/shopfloor/actions/message.py index 117ae161a3b..8aaffb5f0fc 100644 --- a/shopfloor/actions/message.py +++ b/shopfloor/actions/message.py @@ -6,6 +6,7 @@ from odoo import _ from odoo.addons.component.core import Component +from odoo.addons.stock.models.stock_location import Location _logger = logging.getLogger(__name__) @@ -191,8 +192,22 @@ def no_location_found(self): def location_not_allowed(self): return {"message_type": "error", "body": _("Location not allowed here.")} - def dest_location_not_allowed(self): - return {"message_type": "error", "body": _("You cannot place it here")} + def dest_location_not_allowed( + self, location: (Location | None) = None, extra_message: str = "" + ) -> dict: + """ + This returns the message that destination location is incorrect + """ + if location: + body = _( + "You cannot place it here (%(location_name)s)", + location_name=location.name if location else "", + ) + else: + body = _("You cannot place it here") + if extra_message: + body += "\n" + extra_message + return {"message_type": "error", "body": body} def need_confirmation(self): return {"message_type": "warning", "body": _("Are you sure?")} diff --git a/shopfloor/services/checkout.py b/shopfloor/services/checkout.py index b7b81048533..b736b7ef417 100644 --- a/shopfloor/services/checkout.py +++ b/shopfloor/services/checkout.py @@ -1573,7 +1573,7 @@ def scan_dest_location(self, picking_id, barcode): if scanned_location not in allowed_locations: return self._response_for_select_child_location( picking, - message=self.msg_store.dest_location_not_allowed(), + message=self.msg_store.dest_location_not_allowed(scanned_location), ) lines_done = self._lines_checkout_done(picking) for line in lines_done: diff --git a/shopfloor/services/cluster_picking.py b/shopfloor/services/cluster_picking.py index 454ba27f3d4..dfdc1690933 100644 --- a/shopfloor/services/cluster_picking.py +++ b/shopfloor/services/cluster_picking.py @@ -1132,7 +1132,8 @@ def set_destination_all(self, picking_batch_id, barcode, confirmation=None): ) if not self.is_dest_location_valid(lines.move_id, scanned_location): return self._response_for_unload_all( - batch, message=self.msg_store.dest_location_not_allowed() + batch, + message=self.msg_store.dest_location_not_allowed(scanned_location), ) if confirmation != barcode and self.is_dest_location_to_confirm( @@ -1297,7 +1298,9 @@ def _unload_scan_destination_lines( ) if not self.is_dest_location_valid(lines.move_id, scanned_location): return self._response_for_unload_set_destination( - batch, package, message=self.msg_store.dest_location_not_allowed() + batch, + package, + message=self.msg_store.dest_location_not_allowed(scanned_location), ) if confirmation != barcode and self.is_dest_location_to_confirm( first_line.location_dest_id, scanned_location diff --git a/shopfloor/services/location_content_transfer.py b/shopfloor/services/location_content_transfer.py index b798208863b..cc5325fa303 100644 --- a/shopfloor/services/location_content_transfer.py +++ b/shopfloor/services/location_content_transfer.py @@ -388,9 +388,7 @@ def scan_location(self, barcode): # noqa: C901 if not self.is_dest_location_valid(line.move_id, line.location_dest_id): savepoint.rollback() return self._response_for_start( - message=self.msg_store.location_content_unable_to_transfer( - location - ) + message=self.msg_store.dest_location_not_allowed(location) ) stock = self._actions_for("stock") @@ -467,7 +465,8 @@ def set_destination_all(self, location_id, barcode, confirmation=None): if not self.is_dest_location_valid(move_lines.move_id, scanned_location): return self._response_for_scan_destination_all( - pickings, message=self.msg_store.dest_location_not_allowed() + pickings, + message=self.msg_store.dest_location_not_allowed(scanned_location), ) if confirmation != barcode and self.is_dest_location_to_confirm( move_lines.location_dest_id, scanned_location @@ -693,7 +692,7 @@ def set_destination_package( return self._response_for_scan_destination( location, package_level, - message=self.msg_store.dest_location_not_allowed(), + message=self.msg_store.dest_location_not_allowed(scanned_location), ) if confirmation != barcode and self.is_dest_location_to_confirm( package_level.location_dest_id, scanned_location @@ -750,7 +749,9 @@ def set_destination_line( ) if not self.is_dest_location_valid(move_line.move_id, scanned_location): return self._response_for_scan_destination( - location, move_line, message=self.msg_store.dest_location_not_allowed() + location, + move_line, + message=self.msg_store.dest_location_not_allowed(scanned_location), ) if confirmation != barcode and self.is_dest_location_to_confirm( move_line.location_dest_id, scanned_location diff --git a/shopfloor/services/single_pack_transfer.py b/shopfloor/services/single_pack_transfer.py index e3e98c72354..c0233f69a2a 100644 --- a/shopfloor/services/single_pack_transfer.py +++ b/shopfloor/services/single_pack_transfer.py @@ -234,7 +234,8 @@ def validate(self, package_level_id, location_barcode, confirmation=None): if not self.is_dest_location_valid(moves, scanned_location): return self._response_for_scan_location( - package_level, message=self.msg_store.dest_location_not_allowed() + package_level, + message=self.msg_store.dest_location_not_allowed(scanned_location), ) if confirmation != location_barcode and self.is_dest_location_to_confirm( diff --git a/shopfloor/services/zone_picking.py b/shopfloor/services/zone_picking.py index ff6512cfe2e..8bdf49bf309 100644 --- a/shopfloor/services/zone_picking.py +++ b/shopfloor/services/zone_picking.py @@ -909,7 +909,7 @@ def _check_set_destination_location( if not self.is_dest_location_valid(move_line.move_id, location): return self._response_for_set_line_destination( move_line, - message=self.msg_store.dest_location_not_allowed(), + message=self.msg_store.dest_location_not_allowed(location), qty_done=quantity, ) @@ -1704,7 +1704,7 @@ def unload_set_destination(self, package_id, barcode, confirmation=None): if not self.is_dest_location_valid(moves, location): return self._response_for_unload_set_destination( first(buffer_lines), - message=self.msg_store.dest_location_not_allowed(), + message=self.msg_store.dest_location_not_allowed(location), ) # check if the destination location is not the expected one # - OK if the scanned destination is a child of the current diff --git a/shopfloor/tests/test_checkout_scan_dest_location.py b/shopfloor/tests/test_checkout_scan_dest_location.py index e3aab4b4088..cb027cac730 100644 --- a/shopfloor/tests/test_checkout_scan_dest_location.py +++ b/shopfloor/tests/test_checkout_scan_dest_location.py @@ -95,5 +95,7 @@ def test_scan_dest_location_not_allowed(self): self.picking, done=True, with_lines=False, with_location=True ), }, - message=self.service.msg_store.dest_location_not_allowed(), + message=self.service.msg_store.dest_location_not_allowed( + self.child_location_view + ), ) diff --git a/shopfloor/tests/test_cluster_picking_unload.py b/shopfloor/tests/test_cluster_picking_unload.py index 496468e433e..1b004bc7912 100644 --- a/shopfloor/tests/test_cluster_picking_unload.py +++ b/shopfloor/tests/test_cluster_picking_unload.py @@ -347,7 +347,10 @@ def test_set_destination_all_error_location_invalid(self): response, next_state="unload_all", data=data, - message={"message_type": "error", "body": "You cannot place it here"}, + message={ + "message_type": "error", + "body": f"You cannot place it here ({self.dispatch_location.name})", + }, ) def test_set_destination_all_error_location_move_invalid(self): @@ -374,7 +377,9 @@ def test_set_destination_all_error_location_move_invalid(self): response, next_state="unload_all", data=data, - message=self.service.msg_store.dest_location_not_allowed(), + message=self.service.msg_store.dest_location_not_allowed( + self.packing_b_location + ), ) def test_set_destination_all_need_confirmation(self): @@ -822,7 +827,10 @@ def test_unload_scan_destination_error_location_invalid(self): response, next_state="unload_set_destination", data=data, - message={"message_type": "error", "body": "You cannot place it here"}, + message={ + "message_type": "error", + "body": f"You cannot place it here ({self.dispatch_location.name})", + }, ) def test_unload_scan_destination_error_location_move_invalid(self): @@ -846,7 +854,9 @@ def test_unload_scan_destination_error_location_move_invalid(self): response, next_state="unload_set_destination", data=data, - message=self.service.msg_store.dest_location_not_allowed(), + message=self.service.msg_store.dest_location_not_allowed( + self.packing_b_location + ), ) def test_unload_scan_destination_need_confirmation(self): diff --git a/shopfloor/tests/test_location_content_transfer_putaway.py b/shopfloor/tests/test_location_content_transfer_putaway.py index fb073f8bbc8..0b99a1a1eef 100644 --- a/shopfloor/tests/test_location_content_transfer_putaway.py +++ b/shopfloor/tests/test_location_content_transfer_putaway.py @@ -133,9 +133,7 @@ def test_putaway_move_dest_not_child_of_picking_type_dest(self): response, next_state="scan_location", data=self.ANY, - message=self.service.msg_store.location_content_unable_to_transfer( - self.test_loc - ), + message=self.service.msg_store.dest_location_not_allowed(self.test_loc), ) current_moves = self.env["stock.move"].search( [("location_id", "=", self.test_loc.id), ("state", "=", "assigned")] diff --git a/shopfloor/tests/test_location_content_transfer_set_destination_all.py b/shopfloor/tests/test_location_content_transfer_set_destination_all.py index 2282bcccc2f..45c5e740d97 100644 --- a/shopfloor/tests/test_location_content_transfer_set_destination_all.py +++ b/shopfloor/tests/test_location_content_transfer_set_destination_all.py @@ -310,7 +310,9 @@ def test_set_destination_all_dest_location_invalid(self): self.assert_response_scan_destination_all( response, self.pickings, - message=self.service.msg_store.dest_location_not_allowed(), + message=self.service.msg_store.dest_location_not_allowed( + self.dispatch_location + ), ) def test_set_destination_all_dest_location_move_invalid(self): @@ -332,7 +334,7 @@ def test_set_destination_all_dest_location_move_invalid(self): self.assert_response_scan_destination_all( response, self.pickings, - message=self.service.msg_store.dest_location_not_allowed(), + message=self.service.msg_store.dest_location_not_allowed(self.shelf2), ) def test_go_to_single(self): diff --git a/shopfloor/tests/test_location_content_transfer_set_destination_package_or_line.py b/shopfloor/tests/test_location_content_transfer_set_destination_package_or_line.py index 1fd599b260c..5fda9f8fe5e 100644 --- a/shopfloor/tests/test_location_content_transfer_set_destination_package_or_line.py +++ b/shopfloor/tests/test_location_content_transfer_set_destination_package_or_line.py @@ -117,7 +117,7 @@ def test_set_destination_package_dest_location_nok(self): self.assert_response_scan_destination( response, package_level, - message=self.service.msg_store.dest_location_not_allowed(), + message=self.service.msg_store.dest_location_not_allowed(customer_location), ) def test_set_destination_package_dest_location_move_nok(self): @@ -141,7 +141,7 @@ def test_set_destination_package_dest_location_move_nok(self): self.assert_response_scan_destination( response, package_level, - message=self.service.msg_store.dest_location_not_allowed(), + message=self.service.msg_store.dest_location_not_allowed(self.shelf2), ) def test_set_destination_package_dest_location_to_confirm(self): @@ -309,7 +309,7 @@ def test_set_destination_line_dest_location_nok(self): self.assert_response_scan_destination( response, move_line, - message=self.service.msg_store.dest_location_not_allowed(), + message=self.service.msg_store.dest_location_not_allowed(customer_location), ) def test_set_destination_line_dest_location_move_nok(self): @@ -333,7 +333,7 @@ def test_set_destination_line_dest_location_move_nok(self): self.assert_response_scan_destination( response, move_line, - message=self.service.msg_store.dest_location_not_allowed(), + message=self.service.msg_store.dest_location_not_allowed(self.shelf2), ) def test_set_destination_line_dest_location_to_confirm(self): diff --git a/shopfloor/tests/test_single_pack_transfer.py b/shopfloor/tests/test_single_pack_transfer.py index 3146c08afd5..8a2a33d4151 100644 --- a/shopfloor/tests/test_single_pack_transfer.py +++ b/shopfloor/tests/test_single_pack_transfer.py @@ -696,7 +696,10 @@ def test_validate_location_forbidden(self): response, next_state="scan_location", data=self.ANY, - message={"message_type": "error", "body": "You cannot place it here"}, + message={ + "message_type": "error", + "body": f"You cannot place it here ({self.dispatch_location.name})", + }, ) def test_validate_location_move_not_child_of_picking_allowed(self): diff --git a/shopfloor/tests/test_zone_picking_set_line_destination.py b/shopfloor/tests/test_zone_picking_set_line_destination.py index f3094d258e7..1fb2a394bf2 100644 --- a/shopfloor/tests/test_zone_picking_set_line_destination.py +++ b/shopfloor/tests/test_zone_picking_set_line_destination.py @@ -79,7 +79,9 @@ def test_set_destination_location_confirm(self): zone_location, picking_type, move_line, - message=self.service.msg_store.dest_location_not_allowed(), + message=self.service.msg_store.dest_location_not_allowed( + self.customer_location + ), qty_done=quantity_done, ) # Confirm the destination with the right destination this time @@ -127,7 +129,9 @@ def test_set_destination_location_move_invalid_location(self): zone_location, picking_type, move_line, - message=self.service.msg_store.dest_location_not_allowed(), + message=self.service.msg_store.dest_location_not_allowed( + self.packing_sublocation_b + ), qty_done=quantity_done, ) diff --git a/shopfloor/tests/test_zone_picking_unload_set_destination.py b/shopfloor/tests/test_zone_picking_unload_set_destination.py index daed7ccae89..5ab889da7e9 100644 --- a/shopfloor/tests/test_zone_picking_unload_set_destination.py +++ b/shopfloor/tests/test_zone_picking_unload_set_destination.py @@ -95,7 +95,9 @@ def test_unload_set_destination_location_not_allowed(self): zone_location, picking_type, move_line, - message=self.service.msg_store.dest_location_not_allowed(), + message=self.service.msg_store.dest_location_not_allowed( + self.customer_location + ), ) def test_unload_set_destination_location_move_not_allowed(self): @@ -122,7 +124,9 @@ def test_unload_set_destination_location_move_not_allowed(self): zone_location, picking_type, move_line, - message=self.service.msg_store.dest_location_not_allowed(), + message=self.service.msg_store.dest_location_not_allowed( + self.packing_sublocation_b + ), ) # Ensure that when unload_package_at_destination is False, # the result_package_id remains.