Skip to content
Open
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: 3 additions & 1 deletion core/app/models/spree/shipment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,9 @@ def tax_total
def to_package
package = Stock::Package.new(stock_location)
package.shipment = self
inventory_units.includes(variant: :product).joins(:variant).group_by(&:state).each do |state, state_inventory_units|
# Canceled units must not contribute to shipping rate calculation: every
# caller of this method feeds the result to the shipping estimator/calculators.
inventory_units.not_canceled.includes(variant: :product).joins(:variant).group_by(&:state).each do |state, state_inventory_units|
package.add_multiple state_inventory_units, state.to_sym
end
package
Expand Down
16 changes: 15 additions & 1 deletion core/spec/models/spree/shipment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@
before do
allow(line_item).to receive(:order) { order }
shipment.inventory_units = inventory_units
allow(shipment.inventory_units).to receive_message_chain(:includes, :joins).and_return inventory_units
allow(shipment.inventory_units).to receive_message_chain(:not_canceled, :includes, :joins).and_return inventory_units
end

it "should use symbols for states when adding contents to package" do
Expand All @@ -316,6 +316,20 @@
it "should set the shipment to itself" do
expect(shipment.to_package.shipment).to eq(shipment)
end

context "with a canceled inventory unit on the shipment" do
let(:order_with_units) { create(:order_ready_to_ship, line_items_count: 2) }
let(:real_shipment) { order_with_units.shipments.first }

it "excludes canceled inventory units from the package" do
kept_unit, canceled_unit = real_shipment.inventory_units.to_a
canceled_unit.update_columns(state: "canceled")

package = real_shipment.to_package

expect(package.contents.map(&:inventory_unit)).to contain_exactly(kept_unit)
end
end
end
end
end
Expand Down
Loading