Merge pull request #7989 from Matt-Yorkley/invoice-display

Invoice display
This commit is contained in:
Matt-Yorkley
2021-08-10 14:14:41 +02:00
committed by GitHub
6 changed files with 86 additions and 23 deletions

View File

@@ -19,7 +19,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'

View File

@@ -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

19
app/helpers/tax_helper.rb Normal file
View File

@@ -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

View File

@@ -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?

View File

@@ -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

View File

@@ -0,0 +1,62 @@
# frozen_string_literal: true
require 'spec_helper'
describe TaxHelper, type: :helper do
let(:line_item) { create(:line_item) }
let!(:tax_rate) { create(:tax_rate, amount: 0.1) }
let!(:tax_rate2) { create(:tax_rate, amount: 0.2, included_in_price: false) }
let!(:included_tax_adjustment) {
create(:adjustment, originator: tax_rate, adjustable: line_item, state: "closed")
}
let!(:additional_tax_adjustment) {
create(:adjustment, originator: tax_rate2, adjustable: line_item, state: "closed")
}
let!(:no_tax_adjustment) {
create(:adjustment, amount: 0, adjustable: line_item, state: "closed")
}
describe "#display_taxes" do
it "displays included tax" do
expect(
helper.display_taxes(included_tax_adjustment)
).to eq Spree::Money.new(included_tax_adjustment.included_tax_total)
end
it "displays additional tax" do
expect(
helper.display_taxes(additional_tax_adjustment)
).to eq Spree::Money.new(additional_tax_adjustment.additional_tax_total)
end
it "displays formatted 0.00 amount when amount is zero" do
expect(
helper.display_taxes(no_tax_adjustment)
).to eq Spree::Money.new(0.00)
end
it "optionally displays nothing when amount is zero" do
expect(
helper.display_taxes(no_tax_adjustment, display_zero: false)
).to be_nil
end
end
describe "#display_total_with_tax" do
it "displays total with included tax" do
expect(
helper.display_total_with_tax(included_tax_adjustment)
).to eq Spree::Money.new(
included_tax_adjustment.amount + + included_tax_adjustment.included_tax_total
)
end
it "displays total with additional tax" do
expect(
helper.display_total_with_tax(additional_tax_adjustment)
).to eq Spree::Money.new(
additional_tax_adjustment.amount + additional_tax_adjustment.additional_tax_total
)
end
end
end