Merge pull request #9611 from mkllnk/9605-tax-total

Index tax totals correctly for invoice display
This commit is contained in:
Maikel
2022-09-08 12:04:19 +10:00
committed by GitHub
5 changed files with 106 additions and 14 deletions

View File

@@ -24,6 +24,98 @@ describe CheckoutHelper, type: :helper do
end
end
describe "#display_checkout_taxes_hash" do
let(:order) { build(:order_with_totals) }
let(:tax_rate10) { build(:tax_rate, amount: 0.1) }
let(:tax_rate20) { build(:tax_rate, amount: 0.2) }
let(:other_tax_rate20) { build(:tax_rate, amount: 0.2) }
let(:adjustment1) {
build(:adjustment, amount: 1, label: "10% tax", originator: tax_rate10)
}
let(:adjustment2) {
build(:adjustment, amount: 2, label: "20% tax", originator: tax_rate20)
}
let(:other_adjustment2) {
build(:adjustment, amount: 2, label: "20% tax", originator: other_tax_rate20)
}
it "produces an empty array without taxes" do
expect(helper.display_checkout_taxes_hash(order)).to eq([])
end
it "shows a single tax adjustment" do
order.all_adjustments << adjustment1
order.save!
expect(helper.display_checkout_taxes_hash(order)).to eq [
{
amount: Spree::Money.new(1, currency: order.currency),
percentage: "10.0%",
rate_amount: 0.1,
}
]
end
it "shows multiple tax adjustments" do
order.all_adjustments << adjustment1
order.all_adjustments << adjustment2
order.save!
expect(helper.display_checkout_taxes_hash(order)).to eq [
{
amount: Spree::Money.new(1, currency: order.currency),
percentage: "10.0%",
rate_amount: 0.1,
},
{
amount: Spree::Money.new(2, currency: order.currency),
percentage: "20.0%",
rate_amount: 0.2,
},
]
end
it "sorts adjustments by percentage" do
order.all_adjustments << adjustment2
order.all_adjustments << adjustment1
order.save!
expect(helper.display_checkout_taxes_hash(order)).to eq [
{
amount: Spree::Money.new(1, currency: order.currency),
percentage: "10.0%",
rate_amount: 0.1,
},
{
amount: Spree::Money.new(2, currency: order.currency),
percentage: "20.0%",
rate_amount: 0.2,
},
]
end
it "shows multiple tax adjustments with same percentage" do
order.all_adjustments << adjustment2
order.all_adjustments << other_adjustment2
order.save!
expect(helper.display_checkout_taxes_hash(order)).to eq [
{
amount: Spree::Money.new(2, currency: order.currency),
percentage: "20.0%",
rate_amount: 0.2,
},
{
amount: Spree::Money.new(2, currency: order.currency),
percentage: "20.0%",
rate_amount: 0.2,
},
]
expect(helper.display_checkout_taxes_hash(order).size).to eq 2
end
end
it "knows if guests can checkout" do
distributor = create(:distributor_enterprise)
order = create(:order, distributor: distributor)

View File

@@ -92,10 +92,7 @@ describe '
end
def taxes_in_print_data
display_checkout_taxes_hash(order).map { |tax_rate, tax_value|
[tax_rate,
tax_value.format(with_currency: false)]
}
[["10.0%", "$11.00"]]
end
end
end