Remove tax_rates shortcut from adjustment

Becoming less dependent on Spree, using our own namespace, keeping
decorators small.
This commit is contained in:
Maikel Linke
2018-12-19 14:42:38 +11:00
parent fc1b182275
commit a978e992bf
5 changed files with 13 additions and 8 deletions

View File

@@ -54,7 +54,7 @@ module CheckoutHelper
end
def display_adjustment_tax_rates(adjustment)
tax_rates = adjustment.tax_rates
tax_rates = TaxRateFinder.tax_rates_of(adjustment)
tax_rates.map { |tr| number_to_percentage(tr.amount * 100, :precision => 1) }.join(", ")
end

View File

@@ -40,11 +40,6 @@ module Spree
included_tax > 0
end
# @return [Array<Spree::TaxRate>]
def tax_rates
TaxRateFinder.new.tax_rates(originator, source, amount, included_tax)
end
def self.without_callbacks
skip_callback :save, :after, :update_adjustable
skip_callback :destroy, :after, :update_adjustable

View File

@@ -293,7 +293,7 @@ Spree::Order.class_eval do
def tax_adjustment_totals
tax_adjustments.each_with_object(Hash.new) do |adjustment, hash|
tax_rates = adjustment.tax_rates
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]

View File

@@ -2,6 +2,16 @@
# For example a packaging fee may contain VAT. This service finds the VAT rate
# for the tax included in the packaging fee.
class TaxRateFinder
# @return [Array<Spree::TaxRate>]
def self.tax_rates_of(adjustment)
new.tax_rates(
adjustment.originator,
adjustment.source,
adjustment.amount,
adjustment.included_tax
)
end
# @return [Array<Spree::TaxRate>]
def tax_rates(originator, source, amount, included_tax)
find_associated_tax_rate(originator, source) ||

View File

@@ -32,7 +32,7 @@ module OpenFoodNetwork
end
def adjustment_tax(adjustable, adjustment)
tax_rates = adjustment.tax_rates
tax_rates = TaxRateFinder.tax_rates_of(adjustment)
tax_rates.select(&:included_in_price).sum do |rate|
rate.compute_tax adjustment.amount