Skip to content

Commit

Permalink
Do not consider pending inventory units cancelable
Browse files Browse the repository at this point in the history
Before an order is complete, all its inventory units are marked as "pending". Once
the order passes the `complete` step, the inventory units' `pending` attribute is
set to false.

Item cancelations were designed for completed orders only, as before that, one could
just change inventory on line items. Therefore, we should not consider pending inventory
units as cancelable.
  • Loading branch information
mamhoff committed Mar 31, 2017
1 parent 54a4980 commit beab2f3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
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 @@ -30,7 +30,7 @@ class InventoryUnit < Spree::Base
scope :returned, -> { where state: 'returned' }
scope :canceled, -> { where(state: 'canceled') }
scope :not_canceled, -> { where.not(state: 'canceled') }
scope :cancelable, -> { where(state: Spree::InventoryUnit::CANCELABLE_STATES) }
scope :cancelable, -> { where(state: Spree::InventoryUnit::CANCELABLE_STATES, pending: false) }
scope :backordered_per_variant, ->(stock_item) do
includes(:shipment, :order)
.where("spree_shipments.state != 'canceled'").references(:shipment)
Expand Down
9 changes: 9 additions & 0 deletions core/spec/models/spree/inventory_unit_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@
let(:stock_item) { stock_location.stock_items.order(:id).first }
let(:line_item) { create(:line_item, variant: stock_item.variant) }

describe ".cancelable" do
let!(:pending_unit) { create(:inventory_unit, pending: true) }
let!(:non_pending_unit) { create(:inventory_unit, pending: false) }

subject { described_class.cancelable }

it { is_expected.to contain_exactly(non_pending_unit) }
end

context "#backordered_for_stock_item" do
let(:order) do
order = create(:order, state: 'complete', ship_address: create(:ship_address))
Expand Down

0 comments on commit beab2f3

Please sign in to comment.