diff --git a/app/models/invoice/data_presenter.rb b/app/models/invoice/data_presenter.rb index 82c0d8954e..c8aa8aef54 100644 --- a/app/models/invoice/data_presenter.rb +++ b/app/models/invoice/data_presenter.rb @@ -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 diff --git a/app/services/order_tax_adjustments_fetcher.rb b/app/services/order_tax_adjustments_fetcher.rb index 83ea65dfc1..97254a928c 100644 --- a/app/services/order_tax_adjustments_fetcher.rb +++ b/app/services/order_tax_adjustments_fetcher.rb @@ -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 diff --git a/app/views/spree/admin/orders/_invoice_table4.html.haml b/app/views/spree/admin/orders/_invoice_table4.html.haml index e1c40bd284..c0ebb69362 100644 --- a/app/views/spree/admin/orders/_invoice_table4.html.haml +++ b/app/views/spree/admin/orders/_invoice_table4.html.haml @@ -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])