From c60554a14a0a0b218e1ed4f37ccd2e6edc2f5401 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Wed, 16 Jun 2021 18:13:56 +0100 Subject: [PATCH] Update display of associated tax amounts --- app/controllers/application_controller.rb | 1 + app/helpers/adjustments_helper.rb | 14 ++++++++++++++ app/models/spree/adjustment.rb | 8 ++++++++ .../admin/adjustments/_adjustments_table.html.haml | 14 +++++++++----- .../spree/admin/orders/_invoice_table.html.haml | 2 +- config/locales/en.yml | 2 ++ 6 files changed, 35 insertions(+), 6 deletions(-) create mode 100644 app/helpers/adjustments_helper.rb diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 077a264695..4570ed53cf 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -16,6 +16,7 @@ class ApplicationController < ActionController::Base helper 'spree/orders' helper 'spree/payment_methods' helper 'shared' + helper 'adjustments' helper 'enterprises' helper 'order_cycles' helper 'order' diff --git a/app/helpers/adjustments_helper.rb b/app/helpers/adjustments_helper.rb new file mode 100644 index 0000000000..775f5b6d42 --- /dev/null +++ b/app/helpers/adjustments_helper.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +module AdjustmentsHelper + def display_adjustment_taxes(adjustment) + if adjustment.included_tax_total > 0 + amount = Spree::Money.new(adjustment.included_tax_total, currency: adjustment.currency) + I18n.t(:tax_amount_included, amount: amount) + elsif adjustment.additional_tax_total > 0 + Spree::Money.new(adjustment.additional_tax_total, currency: adjustment.currency) + else + Spree::Money.new(0.00, currency: adjustment.currency) + end + end +end diff --git a/app/models/spree/adjustment.rb b/app/models/spree/adjustment.rb index 4f3ab3da96..38b6d845c5 100644 --- a/app/models/spree/adjustment.rb +++ b/app/models/spree/adjustment.rb @@ -137,6 +137,14 @@ module Spree tax_total.positive? end + def included_tax_total + adjustments.tax.inclusive.sum(:amount) + end + + def additional_tax_total + adjustments.tax.additional.sum(:amount) + end + private def tax_total diff --git a/app/views/spree/admin/adjustments/_adjustments_table.html.haml b/app/views/spree/admin/adjustments/_adjustments_table.html.haml index f139608f61..2d67f6e4e1 100644 --- a/app/views/spree/admin/adjustments/_adjustments_table.html.haml +++ b/app/views/spree/admin/adjustments/_adjustments_table.html.haml @@ -4,7 +4,7 @@ %th= "#{t('spree.date')}/#{t('spree.time')}" %th= t(:description) %th= t(:amount) - %th= t(:included_tax) + %th= t(:tax) %th.actions %tbody - @collection.each do |adjustment| @@ -13,10 +13,14 @@ - tr_class = cycle('odd', 'even') - tr_id = spree_dom_id(adjustment) %tr{:class => tr_class, "data-hook" => "adjustment_row", :id => tr_id} - %td.align-center.created_at= pretty_time(adjustment.created_at) - %td.align-center.label= adjustment.label - %td.align-center.amount= adjustment.display_amount.to_html - %td.align-center.included-tax= adjustment.display_included_tax.to_html + %td.align-center.created_at + = pretty_time(adjustment.created_at) + %td.align-center.label + = adjustment.label + %td.align-center.amount + = adjustment.display_amount.to_html + %td.align-center.tax + = display_adjustment_taxes(adjustment) - unless @order.canceled? %td.actions - if adjustment.originator_type.nil? diff --git a/app/views/spree/admin/orders/_invoice_table.html.haml b/app/views/spree/admin/orders/_invoice_table.html.haml index c96099edb6..878724659a 100644 --- a/app/views/spree/admin/orders/_invoice_table.html.haml +++ b/app/views/spree/admin/orders/_invoice_table.html.haml @@ -30,7 +30,7 @@ %td{:align => "right"} 1 %td{:align => "right"} - = adjustment.included_tax > 0 ? adjustment.display_included_tax : "" + = display_adjustment_taxes(adjustment) %td{:align => "right"} = adjustment.display_amount %tfoot diff --git a/config/locales/en.yml b/config/locales/en.yml index 84140e72bc..549806905e 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -2162,6 +2162,8 @@ See the %{link} to find out more about %{sitename}'s features and to start using fundraising_fee: "Fundraising fee" price_graph: "Price graph" included_tax: "Included tax" + tax: "Tax" + tax_amount_included: "%{amount} (included)" remove_tax: "Remove tax" balance: "Balance" transaction: "Transaction"