mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
fix bad return value
in method Spree::Adjustment#find_closest_tax_rates_from_included_tax
This commit is contained in:
committed by
Rob Harrington
parent
6972822c49
commit
a6ed4a2c6a
@@ -55,7 +55,6 @@ module CheckoutHelper
|
||||
|
||||
def display_adjustment_tax_rates(adjustment)
|
||||
tax_rates = adjustment.tax_rates
|
||||
return "" if adjustment.amount == adjustment.included_tax
|
||||
tax_rates.map { |tr| number_to_percentage(tr.amount * 100, :precision => 1) }.join(", ")
|
||||
end
|
||||
|
||||
|
||||
@@ -47,14 +47,14 @@ module Spree
|
||||
return originator.tax_category ? originator.tax_category.tax_rates.match(source) : []
|
||||
end
|
||||
else
|
||||
[find_closest_tax_rate_from_included_tax]
|
||||
find_closest_tax_rates_from_included_tax
|
||||
end
|
||||
end
|
||||
|
||||
def find_closest_tax_rate_from_included_tax
|
||||
def find_closest_tax_rates_from_included_tax
|
||||
approximation = (included_tax / (amount - included_tax))
|
||||
return nil if approximation.infinite? or approximation.zero?
|
||||
Spree::TaxRate.order("ABS(amount - #{approximation})").first
|
||||
return [] if approximation.infinite? or approximation.zero?
|
||||
[Spree::TaxRate.order("ABS(amount - #{approximation})").first]
|
||||
end
|
||||
|
||||
|
||||
|
||||
@@ -288,12 +288,12 @@ module Spree
|
||||
let!(:tax_rate) { create(:tax_rate, calculator: Spree::Calculator::DefaultTax.new, amount: 0.25) }
|
||||
let!(:other_tax_rate) { create(:tax_rate, calculator: Spree::Calculator::DefaultTax.new, amount: 0.3) }
|
||||
|
||||
it "returns nil if there is no included tax" do
|
||||
adjustment_without_tax.find_closest_tax_rate_from_included_tax.should == nil
|
||||
it "returns [] if there is no included tax" do
|
||||
adjustment_without_tax.find_closest_tax_rates_from_included_tax.should == []
|
||||
end
|
||||
|
||||
it "returns the most accurate tax rate" do
|
||||
adjustment_with_tax.find_closest_tax_rate_from_included_tax.should == tax_rate
|
||||
adjustment_with_tax.find_closest_tax_rates_from_included_tax.should == [tax_rate]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user