fix display_checkout_taxes_hash

This commit is contained in:
Mohamed ABDELLANI
2023-07-14 23:55:02 +01:00
parent 7eabb9a170
commit 9950dd90f7

View File

@@ -69,11 +69,10 @@ class Invoice
end
def display_checkout_taxes_hash
totals = OrderTaxAdjustmentsFetcher.new(nil).totals(all_tax_adjustments)
totals.map do |tax_rate, tax_amount|
tax_adjustment_totals.map do |tax_rate_id, tax_amount|
tax_rate = tax_rate_by_id[tax_rate_id]
{
amount: Spree::Money.new(tax_amount, currency: order.currency),
amount: Spree::Money.new(tax_amount, currency: currency),
percentage: number_to_percentage(tax_rate.amount * 100, precision: 1),
rate_amount: tax_rate.amount,
}
@@ -84,6 +83,22 @@ class Invoice
I18n.l(invoice_date.to_date, format: :long)
end
def all_tax_adjustments
all_eligible_adjustments.select { |a| a.originator.type == 'Spree::TaxRate' }
end
def tax_adjustment_totals
all_tax_adjustments.each_with_object(Hash.new(0)) do |adjustment, totals|
totals[adjustment.originator.id] += adjustment.amount
end
end
def tax_rate_by_id
all_tax_adjustments.each_with_object({}) do |adjustment, tax_rates|
tax_rates[adjustment.originator.id] = adjustment.originator
end
end
def all_tax_adjustments
all_eligible_adjustments.select { |a| a.originator_type == 'Spree::TaxRate' }
end