Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make partially shipped shipment able to be ready #2634

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
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