diff --git a/shopfloor/services/location_content_transfer.py b/shopfloor/services/location_content_transfer.py index 9601395410..c2869d7692 100644 --- a/shopfloor/services/location_content_transfer.py +++ b/shopfloor/services/location_content_transfer.py @@ -51,29 +51,23 @@ def _response_for_start(self, message=None): """Transition to the 'start' state""" return self._response(next_state="start", message=message) - def _response_for_scan_destination_all(self, pickings, message=None): + def _response_for_scan_destination_all( + self, pickings, message=None, confirmation_required=False + ): """Transition to the 'scan_destination_all' state The client screen shows a summary of all the lines and packages to move to a single destination. - """ - return self._response( - next_state="scan_destination_all", - data=self._data_content_all_for_location(pickings=pickings), - message=message, - ) - - def _response_for_confirm_scan_destination_all(self, pickings, message=None): - """Transition to the 'confirm_scan_destination_all' state - The client screen shows a summary of all the lines and packages - to move to a single destination. The user has to scan the destination - location a second time to validate the destination. + If `confirmation_required` is set, + the client will ask to scan again the destination """ + data = self._data_content_all_for_location(pickings=pickings) + data["confirmation_required"] = confirmation_required + if confirmation_required and not message: + message = self.msg_store.need_confirmation() return self._response( - next_state="confirm_scan_destination_all", - data=self._data_content_all_for_location(pickings=pickings), - message=message, + next_state="scan_destination_all", data=data, message=message, ) def _response_for_start_single(self, pickings, message=None): @@ -94,30 +88,19 @@ def _response_for_start_single(self, pickings, message=None): message=message, ) - def _response_for_scan_destination(self, location, next_content, message=None): + def _response_for_scan_destination( + self, location, next_content, message=None, confirmation_required=False + ): """Transition to the 'scan_destination' state The client screen shows details of the package level or move line to move. """ + data = self._data_content_line_for_location(location, next_content) + data["confirmation_required"] = confirmation_required + if confirmation_required and not message: + message = self.msg_store.need_confirmation() return self._response( - next_state="scan_destination", - data=self._data_content_line_for_location(location, next_content), - message=message, - ) - - def _response_for_confirm_scan_destination( - self, location, next_content, message=None - ): - """Transition to the 'confirm_scan_destination' state - - The client screen shows details of the package level or move line to - move. The user has to scan the destination location a second time to - validate the destination. - """ - return self._response( - next_state="confirm_scan_destination", - data=self._data_content_line_for_location(location, next_content), - message=message, + next_state="scan_destination", data=data, message=message, ) def _data_content_all_for_location(self, pickings): @@ -381,7 +364,9 @@ def set_destination_all(self, location_id, barcode, confirmation=False): ): # the scanned location is valid (child of picking type's destination) # but not the expected one: ask for confirmation - return self._response_for_confirm_scan_destination_all(pickings) + return self._response_for_scan_destination_all( + pickings, confirmation_required=True + ) self._set_destination_lines(pickings, move_lines, scanned_location) @@ -562,8 +547,8 @@ def set_destination_package( ) if not scanned_location.is_sublocation_of(package_level.location_dest_id): if not confirmation: - return self._response_for_confirm_scan_destination( - location, package_level + return self._response_for_scan_destination( + location, package_level, confirmation_required=True ) package_move_lines = package_level.move_line_ids package_moves = package_move_lines.mapped("move_id") @@ -626,7 +611,9 @@ def set_destination_line( ) if not scanned_location.is_sublocation_of(move_line.location_dest_id): if not confirmation: - return self._response_for_confirm_scan_destination(location, move_line) + return self._response_for_scan_destination( + location, move_line, confirmation_required=True + ) if quantity < move_line.product_uom_qty: # Update the current move line quantity and # put the scanned qty (the move line) in its own move @@ -876,10 +863,8 @@ def _states(self): return { "start": {}, "scan_destination_all": self._schema_all, - "confirm_scan_destination_all": self._schema_all, "start_single": self._schema_single, "scan_destination": self._schema_single, - "confirm_scan_destination": self._schema_single, } @property @@ -892,6 +877,11 @@ def _schema_all(self): # levels* "package_levels": self.schemas._schema_list_of(package_level_schema), "move_lines": self.schemas._schema_list_of(move_line_schema), + "confirmation_required": { + "type": "boolean", + "nullable": True, + "required": False, + }, } @property @@ -902,6 +892,11 @@ def _schema_single(self): # we'll have one or the other... "package_level": self.schemas._schema_dict_of(schema_package_level), "move_line": self.schemas._schema_dict_of(schema_move_line), + "confirmation_required": { + "type": "boolean", + "nullable": True, + "required": False, + }, } def start_or_recover(self): @@ -915,13 +910,7 @@ def scan_location(self): ) def set_destination_all(self): - return self._response_schema( - next_states={ - "start", - "scan_destination_all", - "confirm_scan_destination_all", - } - ) + return self._response_schema(next_states={"start", "scan_destination_all"}) def go_to_single(self): return self._response_schema(next_states={"start", "start_single"}) @@ -937,14 +926,10 @@ def scan_line(self): ) def set_destination_package(self): - return self._response_schema( - next_states={"start_single", "scan_destination", "confirm_scan_destination"} - ) + return self._response_schema(next_states={"start_single", "scan_destination"}) def set_destination_line(self): - return self._response_schema( - next_states={"start_single", "scan_destination", "confirm_scan_destination"} - ) + return self._response_schema(next_states={"start_single", "scan_destination"}) def postpone_package(self): return self._response_schema(next_states={"start_single"}) diff --git a/shopfloor/tests/test_location_content_transfer_base.py b/shopfloor/tests/test_location_content_transfer_base.py index 989f867b17..0bf62b4ef7 100644 --- a/shopfloor/tests/test_location_content_transfer_base.py +++ b/shopfloor/tests/test_location_content_transfer_base.py @@ -50,7 +50,7 @@ def assert_response_start(self, response, message=None): self.assert_response(response, next_state="start", message=message) def _assert_response_scan_destination_all( - self, state, response, pickings, message=None + self, state, response, pickings, message=None, confirmation_required=False ): # this code is repeated from the implementation, not great, but we # mostly want to ensure the selection of pickings is right, and the @@ -65,20 +65,20 @@ def _assert_response_scan_destination_all( "move_lines": self.data.move_lines(lines), "package_levels": self.data.package_levels(package_levels), "location": self.data.location(location), + "confirmation_required": confirmation_required, }, message=message, ) - def assert_response_scan_destination_all(self, response, pickings, message=None): - self._assert_response_scan_destination_all( - "scan_destination_all", response, pickings, message=message - ) - - def assert_response_confirm_scan_destination_all( - self, response, pickings, message=None + def assert_response_scan_destination_all( + self, response, pickings, message=None, confirmation_required=False ): self._assert_response_scan_destination_all( - "confirm_scan_destination_all", response, pickings, message=message + "scan_destination_all", + response, + pickings, + message=message, + confirmation_required=confirmation_required, ) def assert_response_start_single(self, response, pickings, message=None): @@ -93,24 +93,22 @@ def assert_response_start_single(self, response, pickings, message=None): ) def _assert_response_scan_destination( - self, state, response, next_content, message=None + self, state, response, next_content, message=None, confirmation_required=False ): location = next_content.location_id + data = self.service._data_content_line_for_location(location, next_content) + data["confirmation_required"] = confirmation_required self.assert_response( - response, - next_state=state, - data=self.service._data_content_line_for_location(location, next_content), - message=message, - ) - - def assert_response_scan_destination(self, response, next_content, message=None): - self._assert_response_scan_destination( - "scan_destination", response, next_content, message=message + response, next_state=state, data=data, message=message, ) - def assert_response_confirm_scan_destination( - self, response, next_content, message=None + def assert_response_scan_destination( + self, response, next_content, message=None, confirmation_required=False ): self._assert_response_scan_destination( - "confirm_scan_destination", response, next_content, message=message + "scan_destination", + response, + next_content, + message=message, + confirmation_required=confirmation_required, ) 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 c40f566250..35903b2dbf 100644 --- a/shopfloor/tests/test_location_content_transfer_set_destination_all.py +++ b/shopfloor/tests/test_location_content_transfer_set_destination_all.py @@ -104,7 +104,12 @@ def test_set_destination_all_dest_location_need_confirm(self): "barcode": self.shelf2.barcode, }, ) - self.assert_response_confirm_scan_destination_all(response, self.pickings) + self.assert_response_scan_destination_all( + response, + self.pickings, + message=self.service.msg_store.need_confirmation(), + confirmation_required=True, + ) def test_set_destination_all_dest_location_confirmation(self): """Scanned dest. location != child but in picking type location: confirm 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 362fdf1973..b46855f270 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 @@ -120,8 +120,11 @@ def test_set_destination_package_dest_location_to_confirm(self): "barcode": self.env.ref("stock.stock_location_14").barcode, }, ) - self.assert_response_confirm_scan_destination( - response, package_level, + self.assert_response_scan_destination( + response, + package_level, + message=self.service.msg_store.need_confirmation(), + confirmation_required=True, ) def test_set_destination_package_dest_location_ok(self): @@ -223,7 +226,12 @@ def test_set_destination_line_dest_location_to_confirm(self): "barcode": self.env.ref("stock.stock_location_14").barcode, }, ) - self.assert_response_confirm_scan_destination(response, move_line) + self.assert_response_scan_destination( + response, + move_line, + message=self.service.msg_store.need_confirmation(), + confirmation_required=True, + ) def test_set_destination_line_dest_location_ok(self): """Scanned destination location valid, moves set to done."""