Find approximate tax rate if no other is found

There are several cases in which a tax rate is not associated with an
adjustment. We find the closest one for reporting here. It is not a good
solution, but a workaround introduced for reporting:
https://github.com/openfoodfoundation/openfoodnetwork/pull/1496
This commit is contained in:
Maikel Linke
2018-12-18 17:45:12 +11:00
parent a341561446
commit 3169a384ba
2 changed files with 8 additions and 5 deletions

View File

@@ -4,6 +4,13 @@
class TaxRateFinder
# @return [Array<Spree::TaxRate>]
def tax_rates(originator, source, amount, included_tax)
find_associated_tax_rate(originator, source) ||
find_closest_tax_rates_from_included_tax(amount, included_tax)
end
private
def find_associated_tax_rate(originator, source)
case originator
when Spree::TaxRate
[originator]
@@ -15,13 +22,9 @@ class TaxRateFinder
when Spree::Order
originator.tax_category ? originator.tax_category.tax_rates.match(source) : []
end
else
find_closest_tax_rates_from_included_tax(amount, included_tax)
end
end
private
# shipping fees and adjustments created from the admin panel have
# taxes set at creation in the included_tax field without relation
# to the corresponding TaxRate, so we look for the closest one

View File

@@ -51,7 +51,7 @@ describe TaxRateFinder do
# There is a bug that leaves orphan adjustments on an order after
# associated line items have been removed.
# https://github.com/openfoodfoundation/openfoodnetwork/issues/3127
pending "deals with a missing line item" do
it "deals with a missing line item" do
rates = TaxRateFinder.new.tax_rates(
enterprise_fee,
nil,