Skip to content

Commit 6c33461

Browse files
committed
Ignore removing boxes with invalid state from shipment
1 parent 76f95b3 commit 6c33461

File tree

1 file changed

+5
-1
lines changed
  • back/boxtribute_server/business_logic/box_transfer/shipment

1 file changed

+5
-1
lines changed

back/boxtribute_server/business_logic/box_transfer/shipment/crud.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,8 @@ def _remove_boxes_from_shipment(
316316
"""With `box_state=InStock`, return boxes to stock; with `box_state=NotDelivered`,
317317
mark boxes as lost during shipment. Soft-delete corresponding shipment details.
318318
If boxes are requested to be removed that are not contained in the given shipment,
319-
they are silently discarded.
319+
or in an invalid state for the operation (e.g. only MarkedForShipment boxes can be
320+
moved back to InStock during shipment preparation), they are silently discarded.
320321
"""
321322
box_label_identifiers = box_label_identifiers or []
322323
if not box_label_identifiers:
@@ -326,13 +327,16 @@ def _remove_boxes_from_shipment(
326327

327328
if box_state == BoxState.InStock:
328329
fields = [ShipmentDetail.removed_on, ShipmentDetail.removed_by]
330+
old_box_states = [BoxState.MarkedForShipment]
329331
else:
330332
fields = [ShipmentDetail.lost_on, ShipmentDetail.lost_by]
333+
old_box_states = [BoxState.InTransit, BoxState.Receiving]
331334

332335
details = []
333336
for detail in _retrieve_shipment_details(
334337
shipment_id,
335338
(Box.label_identifier << box_label_identifiers),
339+
Box.state << old_box_states,
336340
):
337341
setattr(detail, fields[0].name, now)
338342
setattr(detail, fields[1].name, user_id)

0 commit comments

Comments
 (0)