Skip to content

Commit a176b61

Browse files
authored
Merge pull request #6314 from solidusio/fix-shipment-cancellation
Fix shipment state when all units cancelled
2 parents 12f00d6 + b1471da commit a176b61

File tree

4 files changed

+6
-25
lines changed

4 files changed

+6
-25
lines changed

core/app/models/spree/order_cancellations.rb

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ def short_ship(inventory_units, created_by: nil)
5151
inventory_units.each do |iu|
5252
unit_cancels << short_ship_unit(iu, created_by:)
5353
end
54-
55-
update_shipped_shipments(inventory_units)
5654
end
5755

5856
@order.recalculate
@@ -122,18 +120,4 @@ def short_ship_unit(inventory_unit, created_by: nil)
122120

123121
unit_cancel
124122
end
125-
126-
# if any shipments are now fully shipped then mark them as such
127-
def update_shipped_shipments(inventory_units)
128-
shipments = Spree::Shipment.
129-
includes(:inventory_units).
130-
where(id: inventory_units.map(&:shipment_id)).
131-
to_a
132-
133-
shipments.each do |shipment|
134-
if shipment.inventory_units.all? { |iu| iu.shipped? || iu.canceled? }
135-
shipment.update!(state: 'shipped', shipped_at: Time.current)
136-
end
137-
end
138-
end
139123
end

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/order_cancellations_spec.rb

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,6 @@
8686
expect { subject }.to change { inventory_unit.state }.to "canceled"
8787
end
8888

89-
it "updates the shipment.state" do
90-
expect { subject }.to change { shipment.reload.state }.from('ready').to('shipped')
91-
end
92-
93-
it "updates the order.shipment_state" do
94-
expect { subject }.to change { order.shipment_state }.from('ready').to('shipped')
95-
end
96-
9789
it "publishes an 'order_short_shipped' event" do
9890
stub_spree_bus
9991

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)