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

Allow fulfilling all items of a ready shipment from another location #1784

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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
* Fix an issue where updating a user in the admin without specifying roles in
the params would clear the user's roles.

* Allow destruction of shipments in the "ready" state.

[#1784](https://github.com/solidusio/solidus/pull/1784)

* Deprecations

* `cache_key_for_taxons` helper has been deprecated in favour of `cache [I18n.locale, @taxons]`
Expand Down
21 changes: 21 additions & 0 deletions backend/spec/features/admin/orders/shipments_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,26 @@ def ship_shipment
expect(page).to have_css("#shipment_#{shipment2.id} tr.stock-item", count: 2)
expect(page).to have_css("#shipment_#{shipment1.id} tr.stock-item", count: 3)
end

context "with a ready-to-ship order" do
let(:variant) { create(:variant) }
let!(:order) do
create(
:order_ready_to_ship,
number: "R100",
line_items_attributes: [{ variant: variant, quantity: 5 }]
)
end

it "can transfer all items to a new location" do
expect(order.shipments.count).to eq(1)

within_row(1) { click_icon 'arrows-h' }
complete_split_to('LA', quantity: 5)

expect(page).to_not have_content("package from 'NY Warehouse'")
expect(page).to have_content("package from 'LA'")
end
end
end
end
2 changes: 1 addition & 1 deletion core/app/models/spree/inventory_unit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def ensure_can_destroy
throw :abort
end

unless shipment.pending?
if shipment.shipped? || shipment.canceled?
errors.add(:base, :cannot_destroy_shipment_state, state: shipment.state)
throw :abort
end
Expand Down
2 changes: 1 addition & 1 deletion core/app/models/spree/shipment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ def set_cost_zero_when_nil
end

def ensure_can_destroy
unless pending?
if shipped? || canceled?
errors.add(:state, :cannot_destroy, state: state)
throw :abort
end
Expand Down
7 changes: 3 additions & 4 deletions core/spec/models/spree/inventory_unit_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -289,11 +289,10 @@
expect { inventory_unit.reload }.not_to raise_error
end

it "cannot be destroyed if its shipment is ready" do
it "can be destroyed if its shipment is ready" do
inventory_unit = create(:order_ready_to_ship).inventory_units.first
expect(inventory_unit.destroy).to eq false
expect(inventory_unit.errors.full_messages.join).to match /Cannot destroy/
expect { inventory_unit.reload }.not_to raise_error
expect(inventory_unit.destroy).to be_truthy
expect { inventory_unit.reload }.to raise_error(ActiveRecord::RecordNotFound)
end

it "cannot be destroyed if its shipment is shipped" do
Expand Down
7 changes: 3 additions & 4 deletions core/spec/models/spree/shipment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -724,11 +724,10 @@
expect { shipment.reload }.to raise_error(ActiveRecord::RecordNotFound)
end

it "cannot be destroyed when ready" do
it "can be destroyed when ready" do
shipment = create(:shipment, state: "ready")
expect(shipment.destroy).to eq false
expect(shipment.errors.full_messages.join).to match /Cannot destroy/
expect { shipment.reload }.not_to raise_error
expect(shipment.destroy).to be_truthy
expect { shipment.reload }.to raise_error(ActiveRecord::RecordNotFound)
end

it "cannot be destroyed when shipped" do
Expand Down