Fix display_checkout_taxes_hash in invoice_table4 template

This commit is contained in:
Matt-Yorkley
2023-05-09 14:59:05 +01:00
committed by Konrad
parent 68ab539ed3
commit 352ad20681
3 changed files with 15 additions and 3 deletions

View File

@@ -65,6 +65,18 @@ class Invoice
adjustments
end
def display_checkout_taxes_hash
totals = OrderTaxAdjustmentsFetcher.new(nil).totals(all_tax_adjustments)
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),
rate_amount: tax_rate.amount,
}
end.sort_by { |tax| tax[:rate_amount] }
end
def all_tax_adjustments
all_eligible_adjustments.select { |a| a.originator_type == 'Spree::TaxRate' }
end

View File

@@ -7,8 +7,8 @@ class OrderTaxAdjustmentsFetcher
@order = order
end
def totals
order.all_adjustments.tax.each_with_object({}) do |adjustment, hash|
def totals(tax_adjustments = nil)
(tax_adjustments ||= order.all_adjustments.tax).each_with_object({}) do |adjustment, hash|
tax_rate = adjustment.originator
hash[tax_rate] = hash[tax_rate].to_f + adjustment.amount
end

View File

@@ -47,7 +47,7 @@
%strong= @invoice_presenter.has_taxes_included ? t(:total_incl_tax) : t(:total_excl_tax)
%td{:align => "right", :colspan => "2"}
%strong= @invoice_presenter.has_taxes_included ? @invoice_presenter.display_total : @invoice_presenter.display_checkout_total_less_tax
- display_checkout_taxes_hash(@invoice_presenter).each do |tax|
- @invoice_presenter.display_checkout_taxes_hash.each do |tax|
%tr
%td{:align => "right", :colspan => "3"}
= t(:tax_total, rate: tax[:percentage])