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

Add display shipment total before tax #4423

Merged
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
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(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

: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