Files
openfoodnetwork/app/helpers/tax_helper.rb
Gaetan Craig-Riou b28e63174d Update display_line_items_taxes
Make sure we add the correct enterprise fee tax amount based on tax
being included in the price or not.
2024-01-23 10:36:43 +11:00

38 lines
1.3 KiB
Ruby

# 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:)
elsif !taxable.additional_tax_total.zero?
Spree::Money.new(taxable.additional_tax_total, currency: taxable.currency)
elsif display_zero
Spree::Money.new(0.00, currency: taxable.currency)
end
end
def display_line_items_taxes(line_item, display_zero: true)
if line_item.included_tax.positive?
tax = line_item.included_tax + enterprise_fee_adjustments(line_item).total_included_tax
Spree::Money.new(tax, currency: line_item.currency)
elsif line_item.added_tax.positive?
tax = line_item.added_tax + enterprise_fee_adjustments(line_item).total_additional_tax
Spree::Money.new(tax, currency: line_item.currency)
elsif display_zero
Spree::Money.new(0.00, currency: line_item.currency)
end
end
def display_total_with_tax(taxable)
total = taxable.amount + taxable.additional_tax_total
Spree::Money.new(total, currency: taxable.currency)
end
private
def enterprise_fee_adjustments(line_item)
EnterpriseFeeAdjustments.new(line_item.enterprise_fee_adjustments)
end
end