@@ -316,7 +316,8 @@ def _remove_boxes_from_shipment(
316
316
"""With `box_state=InStock`, return boxes to stock; with `box_state=NotDelivered`,
317
317
mark boxes as lost during shipment. Soft-delete corresponding shipment details.
318
318
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.
320
321
"""
321
322
box_label_identifiers = box_label_identifiers or []
322
323
if not box_label_identifiers :
@@ -326,13 +327,16 @@ def _remove_boxes_from_shipment(
326
327
327
328
if box_state == BoxState .InStock :
328
329
fields = [ShipmentDetail .removed_on , ShipmentDetail .removed_by ]
330
+ old_box_states = [BoxState .MarkedForShipment ]
329
331
else :
330
332
fields = [ShipmentDetail .lost_on , ShipmentDetail .lost_by ]
333
+ old_box_states = [BoxState .InTransit , BoxState .Receiving ]
331
334
332
335
details = []
333
336
for detail in _retrieve_shipment_details (
334
337
shipment_id ,
335
338
(Box .label_identifier << box_label_identifiers ),
339
+ Box .state << old_box_states ,
336
340
):
337
341
setattr (detail , fields [0 ].name , now )
338
342
setattr (detail , fields [1 ].name , user_id )
0 commit comments