Skip to content

Commit 6035494

Browse files
authored
Merge pull request #6321 from solidusio/bugfix/shipment-state-calculation
Fix shipment state calculation
2 parents 72f1b5c + 593d11a commit 6035494

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

core/app/models/spree/shipment.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,10 +221,10 @@ def determine_state(order)
221221
# ready all other cases
222222
def recalculate_state
223223
self.state =
224-
if order.canceled? || inventory_units.all?(&:canceled?)
225-
"canceled"
226-
elsif shipped?
224+
if shipped?
227225
"shipped"
226+
elsif order.canceled? || inventory_units.all?(&:canceled?)
227+
"canceled"
228228
elsif !order.can_ship?
229229
"pending"
230230
elsif can_transition_from_pending_to_ready?

core/spec/models/spree/order_cancellations_spec.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,32 @@
109109
it "adjusts the order" do
110110
expect { subject }.to change { order.reload.total }.by(-40.0)
111111
end
112+
113+
context "when cancelling all items in a completed order" do
114+
let!(:order) { create(:completed_order_with_totals, line_items_attributes: [{ quantity: }]) }
115+
116+
subject { described_class.new(order).short_ship(order.inventory_units) }
117+
118+
it "updates all of the inventory units" do
119+
expect { subject }.to change { order.inventory_units.canceled.count }.to(quantity)
120+
end
121+
122+
it "updates the shipment state" do
123+
expect { subject }.to change { order.shipments.first.reload.state }.to("canceled")
124+
end
125+
126+
context "when the shipment is already shipped" do
127+
let!(:order) { create(:shipped_order, line_items_attributes: [{ quantity: }]) }
128+
129+
it "updates all of the inventory units" do
130+
expect { subject }.to change { order.inventory_units.canceled.count }.to(quantity)
131+
end
132+
133+
it "does not update the shipment state" do
134+
expect { subject }.not_to change { order.shipments.first.reload.state }.from("shipped")
135+
end
136+
end
137+
end
112138
end
113139

114140
it "sends a cancellation email" do

0 commit comments

Comments
 (0)