Allow more tax data in the summary

I converted the value to a hash so that we can put all information in
there and we won't need the current hash key as percentage any more.
This commit is contained in:
Maikel Linke
2022-08-30 17:58:45 +10:00
parent f4466b1aad
commit f37b681fac
4 changed files with 14 additions and 10 deletions

View File

@@ -72,7 +72,9 @@ module CheckoutHelper
totals.each_with_object({}) do |(tax_rate, tax_amount), hash|
hash[number_to_percentage(tax_rate.amount * 100, precision: 1)] =
Spree::Money.new tax_amount, currency: order.currency
{
amount: Spree::Money.new(tax_amount, currency: order.currency),
}
end
end

View File

@@ -47,12 +47,12 @@
%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_value|
- display_checkout_taxes_hash(@order).each do |tax_rate, tax|
%tr
%td{:align => "right", :colspan => "3"}
= t(:tax_total, rate: tax_rate)
%td{:align => "right", :colspan => "2"}
= tax_value
= tax[:amount]
%tr
%td{:align => "right", :colspan => "3"}
= @order.has_taxes_included ? t(:total_excl_tax) : t(:total_incl_tax)

View File

@@ -58,10 +58,10 @@
j(@order.display_total.format(with_currency: false))]}",
'\x1B' + '\x45' + '\x0A', // bold off
'\x0A',
"#{display_checkout_taxes_hash(@order).map { |tax_rate, tax_value|
"#{display_checkout_taxes_hash(@order).map { |tax_rate, tax|
'%31s%10s' %
[j(t(:tax_total, rate: tax_rate)),
j(tax_value.format(with_currency: false))] +
j(tax[:amount].format(with_currency: false))] +
'" + \'\x0A\' + "'}.join }",
"#{'%31s%10s' %
[j(t(:total_excl_tax)),

View File

@@ -48,7 +48,9 @@ describe CheckoutHelper, type: :helper do
order.save!
expect(helper.display_checkout_taxes_hash(order)).to eq(
"10.0%" => Spree::Money.new(1, currency: order.currency)
"10.0%" => {
amount: Spree::Money.new(1, currency: order.currency),
}
)
end
@@ -58,8 +60,8 @@ describe CheckoutHelper, type: :helper do
order.save!
expect(helper.display_checkout_taxes_hash(order)).to eq(
"10.0%" => Spree::Money.new(1, currency: order.currency),
"20.0%" => Spree::Money.new(2, currency: order.currency),
"10.0%" => { amount: Spree::Money.new(1, currency: order.currency) },
"20.0%" => { amount: Spree::Money.new(2, currency: order.currency) },
)
end
@@ -71,8 +73,8 @@ describe CheckoutHelper, type: :helper do
# This passes because we override the hash entry exactly
# like the original code.
expect(helper.display_checkout_taxes_hash(order)).to eq(
"20.0%" => Spree::Money.new(2, currency: order.currency),
"20.0%" => Spree::Money.new(2, currency: order.currency),
"20.0%" => { amount: Spree::Money.new(2, currency: order.currency) },
"20.0%" => { amount: Spree::Money.new(2, currency: order.currency) },
)
pending "https://github.com/openfoodfoundation/openfoodnetwork/issues/9605"