Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions core/app/models/spree/shipment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,10 @@ def determine_state(order)
# ready all other cases
def recalculate_state
self.state =
if order.canceled? || inventory_units.all?(&:canceled?)
"canceled"
elsif shipped?
if shipped?
"shipped"
elsif order.canceled? || inventory_units.all?(&:canceled?)
"canceled"
elsif !order.can_ship?
"pending"
elsif can_transition_from_pending_to_ready?
Expand Down
26 changes: 26 additions & 0 deletions core/spec/models/spree/order_cancellations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,32 @@
it "adjusts the order" do
expect { subject }.to change { order.reload.total }.by(-40.0)
end

context "when cancelling all items in a completed order" do
let!(:order) { create(:completed_order_with_totals, line_items_attributes: [{ quantity: }]) }

subject { described_class.new(order).short_ship(order.inventory_units) }

it "updates all of the inventory units" do
expect { subject }.to change { order.inventory_units.canceled.count }.to(quantity)
end

it "updates the shipment state" do
expect { subject }.to change { order.shipments.first.reload.state }.to("canceled")
end

context "when the shipment is already shipped" do
let!(:order) { create(:shipped_order, line_items_attributes: [{ quantity: }]) }

it "updates all of the inventory units" do
expect { subject }.to change { order.inventory_units.canceled.count }.to(quantity)
end

it "does not update the shipment state" do
expect { subject }.not_to change { order.shipments.first.reload.state }.from("shipped")
end
end
end
end

it "sends a cancellation email" do
Expand Down
Loading