Skip to content

Commit

Permalink
[REF] ref unload_end for better inheritance
Browse files Browse the repository at this point in the history
  • Loading branch information
sbejaoui committed Dec 2, 2023
1 parent 0d339e8 commit f1a4615
Showing 1 changed file with 32 additions and 25 deletions.
57 changes: 32 additions & 25 deletions shopfloor/services/cluster_picking.py
Original file line number Diff line number Diff line change
Expand Up @@ -1122,17 +1122,19 @@ def set_destination_all(self, picking_batch_id, barcode, confirmation=False):
def _unload_write_destination_on_lines(self, lines, location):
lines.write({"shopfloor_unloaded": True, "location_dest_id": location.id})
lines.package_level_id.location_dest_id = location
for line in lines:
# We set the picking to done only when the last line is
# unloaded to avoid backorders.
picking = line.picking_id
if picking.state == "done":
continue
picking_lines = picking.mapped("move_line_ids")
if all(line.shopfloor_unloaded for line in picking_lines):
picking._action_done()
for picking in lines.picking_id:
picking_lines = lines.filtered(lambda l, p=picking: l.picking_id == p)
self._unload_set_picking_to_done(picking, picking_lines)

def _unload_set_picking_to_done(self, picking, picking_lines):
if picking.state == "done":
return
# We set the picking to done only when the last line is
# unloaded to avoid backorders.
if all(line.shopfloor_unloaded for line in picking.move_line_ids):
picking._action_done()
if self.work.menu.unload_package_at_destination:
lines.result_package_id = False
picking_lines.result_package_id = False

def _unload_end(self, batch, completion_info_popup=None):
"""Try to close the batch if all transfers are done.
Expand All @@ -1157,21 +1159,26 @@ def _unload_end(self, batch, completion_info_popup=None):
message=self.msg_store.batch_transfer_line_done(),
popup=completion_info_popup,
)
else:
# TODO add tests for this (for instance a picking is not 'done'
# because a move was unassigned, we want to validate the batch to
# produce backorders)
all_pickings.filtered(lambda x: x.state == "assigned")._action_done()
batch.state = "done"
# Unassign not validated pickings from the batch, they will be
# processed in another batch automatically later on
all_pickings.invalidate_recordset(["state"])
pickings_not_done = all_pickings.filtered(lambda p: p.state != "done")
pickings_not_done.batch_id = False
return self._response_for_start(
message=self.msg_store.batch_transfer_complete(),
popup=completion_info_popup,
)
return self._unload_end_set_batch_to_done(
batch, completion_info_popup=completion_info_popup
)

def _unload_end_set_batch_to_done(self, batch, completion_info_popup=None):
all_pickings = batch.picking_ids
# TODO add tests for this (for instance a picking is not 'done'
# because a move was unassigned, we want to validate the batch to
# produce backorders)
all_pickings.filtered(lambda x: x.state == "assigned")._action_done()
batch.state = "done"
# Unassign not validated pickings from the batch, they will be
# processed in another batch automatically later on
all_pickings.invalidate_recordset(["state"])
pickings_not_done = all_pickings.filtered(lambda p: p.state != "done")
pickings_not_done.batch_id = False
return self._response_for_start(
message=self.msg_store.batch_transfer_complete(),
popup=completion_info_popup,
)

def unload_split(self, picking_batch_id):
"""Indicates that now the batch must be treated line per line
Expand Down

0 comments on commit f1a4615

Please sign in to comment.