Skip to content
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 @@ -133,7 +133,7 @@ def inventory_units_for_item(line_item, variant = nil)
end

def item_cost
line_items.sum(&:total)
manifest.sum(&:item_cost)
end

def ready_or_pending?
Expand Down
6 changes: 5 additions & 1 deletion core/app/models/spree/shipping_manifest.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
# frozen_string_literal: true

class Spree::ShippingManifest
ManifestItem = Struct.new(:line_item, :variant, :quantity, :states)
ManifestItem = Struct.new(:line_item, :variant, :quantity, :states) do
def item_cost
line_item.total * quantity / line_item.quantity
end
end

attr_reader :inventory_units, :order

Expand Down
20 changes: 20 additions & 0 deletions core/spec/models/spree/shipment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,26 @@
it "should equal line items final amount with tax" do
expect(shipment.item_cost).to eql(11.0)
end

context "with more shipments for the same line_item" do
let(:order) do
create(
:order_with_line_items,
line_items_attributes: [{price: 10, variant: variant, quantity: 2}],
ship_address: ship_address
)
end
let(:other_shipment) { order.shipments.create(stock_location: shipment.stock_location) }

it "returns shipment line items amount with tax" do
expect(order.shipments.first.item_cost).to eql(22.0)
expect {
order.inventory_units.last.update(shipment_id: other_shipment.id)
}.to change { order.shipments.reload.first.item_cost }.from(22.0).to(11.0)

expect(order.shipments.second.item_cost).to eql(11.0)
end
end
end

describe "#total_before_tax" do
Expand Down
Loading