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
16 changes: 0 additions & 16 deletions core/app/models/spree/order_cancellations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ def short_ship(inventory_units, created_by: nil)
inventory_units.each do |iu|
unit_cancels << short_ship_unit(iu, created_by:)
end

update_shipped_shipments(inventory_units)
end

@order.recalculate
Expand Down Expand Up @@ -122,18 +120,4 @@ def short_ship_unit(inventory_unit, created_by: nil)

unit_cancel
end

# if any shipments are now fully shipped then mark them as such
def update_shipped_shipments(inventory_units)
shipments = Spree::Shipment.
includes(:inventory_units).
where(id: inventory_units.map(&:shipment_id)).
to_a

shipments.each do |shipment|
if shipment.inventory_units.all? { |iu| iu.shipped? || iu.canceled? }
shipment.update!(state: 'shipped', shipped_at: Time.current)
end
end
end
end
2 changes: 1 addition & 1 deletion core/app/models/spree/shipment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,8 @@ def selected_shipping_rate_id=(id)
# shipped if already shipped (ie. does not change the state)
# ready all other cases
def determine_state(order)
return 'canceled' if order.canceled?
return 'shipped' if shipped?
return 'canceled' if order.canceled? || inventory_units.all?(&:canceled?)
return 'pending' unless order.can_ship?
if can_transition_from_pending_to_ready?
'ready'
Expand Down
8 changes: 0 additions & 8 deletions core/spec/models/spree/order_cancellations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,6 @@
expect { subject }.to change { inventory_unit.state }.to "canceled"
end

it "updates the shipment.state" do
expect { subject }.to change { shipment.reload.state }.from('ready').to('shipped')
end

it "updates the order.shipment_state" do
expect { subject }.to change { order.shipment_state }.from('ready').to('shipped')
end

it "publishes an 'order_short_shipped' event" do
stub_spree_bus

Expand Down
5 changes: 5 additions & 0 deletions core/spec/models/spree/shipment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@
expect(shipment.determine_state(order)).to eq 'canceled'
end

it 'returns canceled if all of the inventory units are canceled' do
shipment.inventory_units.each(&:cancel!)
expect(shipment.determine_state(order)).to eql 'canceled'
end

it 'returns pending unless order.can_ship?' do
allow(order).to receive_messages can_ship?: false
expect(shipment.determine_state(order)).to eq 'pending'
Expand Down
Loading