mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Remove tax_rates shortcut from adjustment
Becoming less dependent on Spree, using our own namespace, keeping decorators small.
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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) ||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user