Skip to content

Commit

Permalink
Make partially shipped shipment able to be ready
Browse files Browse the repository at this point in the history
Previously, all inventory units in a shipment needed to be on_hand or
cancelled in order for the shipment to be considered shippable.

This worked fine for most users, but it caused issues for users who were
partially shipping shipments manually using cartons.

This commit allows shipments with some shipped inventory units to still
be considered "ready".
  • Loading branch information
John Hawthorn authored and jhawthorn committed Mar 16, 2018
1 parent 64bb34a commit 56997d3
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
2 changes: 1 addition & 1 deletion core/app/models/spree/shipment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def can_transition_from_pending_to_shipped?

def can_transition_from_pending_to_ready?
order.can_ship? &&
inventory_units.all? { |iu| iu.allow_ship? || iu.canceled? } &&
inventory_units.all? { |iu| iu.shipped? || iu.allow_ship? || iu.canceled? } &&
(order.paid? || !Spree::Config[:require_payment_to_ship])
end

Expand Down
34 changes: 32 additions & 2 deletions core/spec/models/spree/shipment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
end

it 'returns pending if backordered' do
allow(shipment).to receive_messages inventory_units: [mock_model(Spree::InventoryUnit, allow_ship?: false, canceled?: false)]
allow(shipment).to receive_messages inventory_units: [mock_model(Spree::InventoryUnit, allow_ship?: false, canceled?: false, shipped?: false)]
expect(shipment.determine_state(order)).to eq 'pending'
end

Expand Down Expand Up @@ -300,7 +300,7 @@
# Set as ready so we can test for change
shipment.update_attributes!(state: 'ready')

allow(shipment).to receive_messages(inventory_units: [mock_model(Spree::InventoryUnit, allow_ship?: false, canceled?: false)])
allow(shipment).to receive_messages(inventory_units: [mock_model(Spree::InventoryUnit, allow_ship?: false, canceled?: false, shipped?: false)])
expect(shipment).to receive(:update_columns).with(state: 'pending', updated_at: kind_of(Time))
shipment.update_state
end
Expand Down Expand Up @@ -865,4 +865,34 @@
end
end
end

describe '#can_transition_from_pending_to_ready?' do
let(:shipment) { create(:shipment, order: order) }

subject { shipment.can_transition_from_pending_to_ready? }

context "with backordered inventory" do
before { shipment.inventory_units.update_all(state: "backordered") }

it "returns false" do
expect(subject).to be false
end
end

context "with on_hand inventory" do
before { shipment.inventory_units.update_all(state: "on_hand") }

it "returns true" do
expect(subject).to be true
end
end

context "with shipped inventory" do
before { shipment.inventory_units.update_all(state: "shipped") }

it "returns true" do
expect(subject).to be true
end
end
end
end

0 comments on commit 56997d3

Please sign in to comment.