mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-08 22:56:06 +00:00
Cosmetics
This commit is contained in:
@@ -44,8 +44,11 @@ module CheckoutHelper
|
||||
end
|
||||
|
||||
def display_checkout_taxes_hash(order)
|
||||
OrderTaxAdjustmentsFetcher.new(order).totals.each_with_object({}) do |(tax_rate, tax_amount), hash|
|
||||
hash[number_to_percentage(tax_rate.amount * 100, precision: 1)] = Spree::Money.new tax_amount, currency: order.currency
|
||||
totals = OrderTaxAdjustmentsFetcher.new(order).totals
|
||||
|
||||
totals.each_with_object({}) do |(tax_rate, tax_amount), hash|
|
||||
hash[number_to_percentage(tax_rate.amount * 100, precision: 1)] =
|
||||
Spree::Money.new tax_amount, currency: order.currency
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# This class will be used to get Tax Adjustments related to an order,
|
||||
# and proceed basic calcultation over them.
|
||||
|
||||
@@ -8,11 +10,7 @@ class OrderTaxAdjustmentsFetcher
|
||||
|
||||
def totals
|
||||
all.each_with_object({}) do |adjustment, hash|
|
||||
tax_rates = TaxRateFinder.tax_rates_of(adjustment)
|
||||
tax_rates_hash = Hash[tax_rates.collect do |tax_rate|
|
||||
tax_amount = tax_rates.one? ? adjustment.included_tax : tax_rate.compute_tax(adjustment.amount)
|
||||
[tax_rate, tax_amount]
|
||||
end]
|
||||
tax_rates_hash = tax_rates_hash(adjustment)
|
||||
hash.update(tax_rates_hash) { |_tax_rate, amount1, amount2| amount1 + amount2 }
|
||||
end
|
||||
end
|
||||
@@ -23,6 +21,21 @@ class OrderTaxAdjustmentsFetcher
|
||||
|
||||
def all
|
||||
order.adjustments.with_tax +
|
||||
order.line_items.includes(:adjustments).map { |li| li.adjustments.with_tax }.flatten
|
||||
order.line_items.includes(:adjustments).map { |li|
|
||||
li.adjustments.with_tax
|
||||
}.flatten
|
||||
end
|
||||
end
|
||||
|
||||
def tax_rates_hash(adjustment)
|
||||
tax_rates = TaxRateFinder.tax_rates_of(adjustment)
|
||||
|
||||
Hash[tax_rates.collect do |tax_rate|
|
||||
tax_amount = if tax_rates.one?
|
||||
adjustment.included_tax
|
||||
else
|
||||
tax_rate.compute_tax(adjustment.amount)
|
||||
end
|
||||
[tax_rate, tax_amount]
|
||||
end]
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user