mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Simplify tax totals helper
This commit is contained in:
@@ -70,12 +70,11 @@ module CheckoutHelper
|
||||
def display_checkout_taxes_hash(order)
|
||||
totals = OrderTaxAdjustmentsFetcher.new(order).totals
|
||||
|
||||
totals.each_with_object({}) do |(tax_rate, tax_amount), hash|
|
||||
hash[tax_rate] =
|
||||
{
|
||||
amount: Spree::Money.new(tax_amount, currency: order.currency),
|
||||
percentage: number_to_percentage(tax_rate.amount * 100, precision: 1),
|
||||
}
|
||||
totals.map do |tax_rate, tax_amount|
|
||||
{
|
||||
amount: Spree::Money.new(tax_amount, currency: order.currency),
|
||||
percentage: number_to_percentage(tax_rate.amount * 100, precision: 1),
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@
|
||||
%strong= @order.has_taxes_included ? t(:total_incl_tax) : t(:total_excl_tax)
|
||||
%td{:align => "right", :colspan => "2"}
|
||||
%strong= @order.has_taxes_included ? @order.display_total : display_checkout_total_less_tax(@order)
|
||||
- display_checkout_taxes_hash(@order).each do |tax_rate, tax|
|
||||
- display_checkout_taxes_hash(@order).each do |tax|
|
||||
%tr
|
||||
%td{:align => "right", :colspan => "3"}
|
||||
= t(:tax_total, rate: tax[:percentage])
|
||||
|
||||
@@ -58,7 +58,7 @@
|
||||
j(@order.display_total.format(with_currency: false))]}",
|
||||
'\x1B' + '\x45' + '\x0A', // bold off
|
||||
'\x0A',
|
||||
"#{display_checkout_taxes_hash(@order).map { |tax_rate, tax|
|
||||
"#{display_checkout_taxes_hash(@order).map { |tax|
|
||||
'%31s%10s' %
|
||||
[j(t(:tax_total, rate: tax[:percentage])),
|
||||
j(tax[:amount].format(with_currency: false))] +
|
||||
|
||||
@@ -39,20 +39,20 @@ describe CheckoutHelper, type: :helper do
|
||||
build(:adjustment, amount: 2, label: "20% tax", originator: other_tax_rate20)
|
||||
}
|
||||
|
||||
it "produces an empty hash without taxes" do
|
||||
expect(helper.display_checkout_taxes_hash(order)).to eq({})
|
||||
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(
|
||||
tax_rate10 => {
|
||||
expect(helper.display_checkout_taxes_hash(order)).to eq [
|
||||
{
|
||||
amount: Spree::Money.new(1, currency: order.currency),
|
||||
percentage: "10.0%",
|
||||
}
|
||||
)
|
||||
]
|
||||
end
|
||||
|
||||
it "shows multiple tax adjustments" do
|
||||
@@ -60,16 +60,16 @@ describe CheckoutHelper, type: :helper do
|
||||
order.all_adjustments << adjustment2
|
||||
order.save!
|
||||
|
||||
expect(helper.display_checkout_taxes_hash(order)).to eq(
|
||||
tax_rate10 => {
|
||||
expect(helper.display_checkout_taxes_hash(order)).to match_array [
|
||||
{
|
||||
amount: Spree::Money.new(1, currency: order.currency),
|
||||
percentage: "10.0%",
|
||||
},
|
||||
tax_rate20 => {
|
||||
{
|
||||
amount: Spree::Money.new(2, currency: order.currency),
|
||||
percentage: "20.0%",
|
||||
},
|
||||
)
|
||||
]
|
||||
end
|
||||
|
||||
it "shows multiple tax adjustments with same percentage" do
|
||||
@@ -77,16 +77,16 @@ describe CheckoutHelper, type: :helper do
|
||||
order.all_adjustments << other_adjustment2
|
||||
order.save!
|
||||
|
||||
expect(helper.display_checkout_taxes_hash(order)).to eq(
|
||||
tax_rate20 => {
|
||||
expect(helper.display_checkout_taxes_hash(order)).to match_array [
|
||||
{
|
||||
amount: Spree::Money.new(2, currency: order.currency),
|
||||
percentage: "20.0%",
|
||||
},
|
||||
other_tax_rate20 => {
|
||||
{
|
||||
amount: Spree::Money.new(2, currency: order.currency),
|
||||
percentage: "20.0%",
|
||||
},
|
||||
)
|
||||
]
|
||||
|
||||
expect(helper.display_checkout_taxes_hash(order).size).to eq 2
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user