Skip to content

Commit b1471da

Browse files
adammathysAlistairNormanNoah-Silvera
committed
Mark shipment as cancelled if all units cancelled
If we cancel all inventory units in a shipment, we should mark it as cancelled itself because there's nothing to ship. Co-authored-by: Alistair Norman <alistair@super.gd> Co-authored-by: Noah Silvera <noah@super.gd>
1 parent 6c76fc5 commit b1471da

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

core/app/models/spree/shipment.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,8 @@ def selected_shipping_rate_id=(id)
207207
# shipped if already shipped (ie. does not change the state)
208208
# ready all other cases
209209
def determine_state(order)
210-
return 'canceled' if order.canceled?
211210
return 'shipped' if shipped?
211+
return 'canceled' if order.canceled? || inventory_units.all?(&:canceled?)
212212
return 'pending' unless order.can_ship?
213213
if can_transition_from_pending_to_ready?
214214
'ready'

core/spec/models/spree/shipment_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@
5050
expect(shipment.determine_state(order)).to eq 'canceled'
5151
end
5252

53+
it 'returns canceled if all of the inventory units are canceled' do
54+
shipment.inventory_units.each(&:cancel!)
55+
expect(shipment.determine_state(order)).to eql 'canceled'
56+
end
57+
5358
it 'returns pending unless order.can_ship?' do
5459
allow(order).to receive_messages can_ship?: false
5560
expect(shipment.determine_state(order)).to eq 'pending'

0 commit comments

Comments
 (0)