mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-31 21:37:16 +00:00
Fix display_checkout_taxes_hash in invoice_table4 template
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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])
|
||||
|
||||
Reference in New Issue
Block a user