Skip to content

Commit

Permalink
Merge pull request #4423 from mamhoff/add-display-shipment-total-befo…
Browse files Browse the repository at this point in the history
…re-tax

Add display shipment total before tax
  • Loading branch information
waiting-for-dev authored Jun 22, 2022
2 parents 7f7071c + 0c389ab commit 64b9e15
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 3 deletions.
22 changes: 19 additions & 3 deletions core/app/models/spree/order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,21 @@ def initialize(message = nil, items: {})
class CannotRebuildShipments < StandardError; end

extend Spree::DisplayMoney
money_methods :outstanding_balance, :item_total, :adjustment_total,
:included_tax_total, :additional_tax_total, :tax_total,
:shipment_total, :total, :order_total_after_store_credit, :total_available_store_credit
money_methods(
:outstanding_balance,
:item_total,
:adjustment_total,
:included_tax_total,
:additional_tax_total,
:tax_total,
:shipment_total,
:total,
:order_total_after_store_credit,
:total_available_store_credit,
:item_total_before_tax,
:shipment_total_before_tax,
:item_total_excluding_vat
)
alias :display_ship_total :display_shipment_total

checkout_flow do
Expand Down Expand Up @@ -195,6 +207,10 @@ def item_total_before_tax
line_items.to_a.sum(&:total_before_tax)
end

def shipment_total_before_tax
shipments.to_a.sum(&:total_before_tax)
end

# Sum of all line item amounts pre-tax
def item_total_excluding_vat
line_items.to_a.sum(&:total_excluding_vat)
Expand Down
33 changes: 33 additions & 0 deletions core/spec/models/spree/order_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1004,6 +1004,39 @@ def generate
]
# (2*10)-15 + 30-16 = 5 + 14 = 19
expect(subject.item_total_excluding_vat).to eq 19.0
expect(subject.display_item_total_excluding_vat).to eq Spree::Money.new(19)
end
end

describe "#item_total_before_tax" do
it "sums all of the line items totals before tax" do
subject.line_items = [
Spree::LineItem.new(price: 10, quantity: 2, included_tax_total: 15.0).tap do |li|
li.adjustments.build(eligible: true, amount: -2)
end,
Spree::LineItem.new(price: 30, quantity: 1, included_tax_total: 16.0).tap do |li|
li.adjustments.build(eligible: true, amount: -3)
end
]
# (2*10)-2 + 30-3 = 18 + 27 = 14
expect(subject.item_total_before_tax).to eq 45.0
expect(subject.display_item_total_before_tax).to eq Spree::Money.new(45)
end
end

describe "#shipment_total_before_tax" do
it "sums all of the line items totals before tax" do
subject.shipments = [
Spree::Shipment.new(cost: 20, included_tax_total: 15.0).tap do |li|
li.adjustments.build(eligible: true, amount: -2)
end,
Spree::Shipment.new(cost: 30, included_tax_total: 16.0).tap do |li|
li.adjustments.build(eligible: true, amount: -3)
end
]
# 20-2 + 30-3 = 18 + 27 = 14
expect(subject.shipment_total_before_tax).to eq 45.0
expect(subject.display_shipment_total_before_tax).to eq Spree::Money.new(45)
end
end

Expand Down

0 comments on commit 64b9e15

Please sign in to comment.