Skip to content

Commit

Permalink
location transfer bknd: get rid of 'confirm_*' states
Browse files Browse the repository at this point in the history
  • Loading branch information
simahawk authored and sebalix committed Jul 16, 2020
1 parent f0b066c commit 4956baf
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 80 deletions.
93 changes: 39 additions & 54 deletions shopfloor/services/location_content_transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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):
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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):
Expand All @@ -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"})
Expand All @@ -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"})
Expand Down
42 changes: 20 additions & 22 deletions shopfloor/tests/test_location_content_transfer_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand All @@ -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,
)
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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."""
Expand Down

0 comments on commit 4956baf

Please sign in to comment.