diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 757cecd578..5d75ccf537 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -17,7 +17,7 @@ class ApplicationController < ActionController::Base helper 'spree/orders' helper 'spree/payment_methods' helper 'shared' - helper 'adjustments' + helper 'tax' helper 'enterprises' helper 'order_cycles' helper 'order' diff --git a/app/helpers/adjustments_helper.rb b/app/helpers/adjustments_helper.rb deleted file mode 100644 index 7b7206ca2c..0000000000 --- a/app/helpers/adjustments_helper.rb +++ /dev/null @@ -1,19 +0,0 @@ -# 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 - - def display_adjustment_total_with_tax(adjustment) - total = adjustment.amount + adjustment.additional_tax_total - Spree::Money.new(total, currency: adjustment.currency) - end -end diff --git a/app/helpers/tax_helper.rb b/app/helpers/tax_helper.rb new file mode 100644 index 0000000000..0a3e471071 --- /dev/null +++ b/app/helpers/tax_helper.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +module TaxHelper + def display_taxes(taxable, display_zero: true) + if !taxable.included_tax_total.zero? + amount = Spree::Money.new(taxable.included_tax_total, currency: taxable.currency) + I18n.t(:tax_amount_included, amount: amount) + elsif !taxable.additional_tax_total.zero? + Spree::Money.new(taxable.additional_tax_total, currency: taxable.currency) + else + Spree::Money.new(0.00, currency: taxable.currency) if display_zero + end + end + + def display_total_with_tax(taxable) + total = taxable.amount + taxable.additional_tax_total + Spree::Money.new(total, currency: taxable.currency) + end +end diff --git a/app/views/spree/admin/adjustments/_adjustments_table.html.haml b/app/views/spree/admin/adjustments/_adjustments_table.html.haml index b24f650de7..1cf986e40e 100644 --- a/app/views/spree/admin/adjustments/_adjustments_table.html.haml +++ b/app/views/spree/admin/adjustments/_adjustments_table.html.haml @@ -25,9 +25,9 @@ %td.align-center.tax-category = taxable.tax_category&.name || "-" %td.align-center.tax - = display_adjustment_taxes(taxable) + = display_taxes(taxable) %td.align-center.total - = display_adjustment_total_with_tax(taxable) + = display_total_with_tax(taxable) - 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 878724659a..c847bd81c9 100644 --- a/app/views/spree/admin/orders/_invoice_table.html.haml +++ b/app/views/spree/admin/orders/_invoice_table.html.haml @@ -24,13 +24,14 @@ %td{:align => "right"} = item.display_amount_with_adjustments - checkout_adjustments_for(@order, exclude: [:line_item]).reject{ |a| a.amount == 0 }.reverse_each do |adjustment| + - taxable = adjustment.adjustable_type == "Spree::Shipment" ? adjustment.adjustable : adjustment %tr %td %strong= "#{raw(adjustment.label)}" %td{:align => "right"} 1 %td{:align => "right"} - = display_adjustment_taxes(adjustment) + = display_taxes(taxable, display_zero: false) %td{:align => "right"} = adjustment.display_amount %tfoot