mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-05 02:41:33 +00:00
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:
@@ -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
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user