Handle tax rates for ShippingMethod

Co-Authored-By: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com>
This commit is contained in:
Jean-Baptiste Bellet
2022-02-11 09:23:51 +01:00
parent 7c7a09a75c
commit 405b7e6e17
2 changed files with 17 additions and 1 deletions

View File

@@ -20,11 +20,17 @@ class TaxRateFinder
case originator
when Spree::TaxRate
[originator]
when Spree::ShippingMethod
shipping_method_fee_tax_rates(originator, adjustable)
when EnterpriseFee
enterprise_fee_tax_rates(originator, adjustable)
end
end
def shipping_method_fee_tax_rates(shipping_method, _adjustable)
shipping_method.tax_category ? shipping_method.tax_category.tax_rates : []
end
def enterprise_fee_tax_rates(enterprise_fee, adjustable)
case adjustable
when Spree::LineItem

View File

@@ -8,9 +8,14 @@ describe TaxRateFinder do
let(:tax_rate) {
create(:tax_rate, amount: 0.2, calculator: Calculator::DefaultTax.new, zone: zone)
}
let(:tax_rate_shipping) {
create(:tax_rate, amount: 0.05, calculator: Calculator::DefaultTax.new, zone: zone)
}
let(:tax_category) { create(:tax_category, tax_rates: [tax_rate]) }
let(:tax_category_shipping) { create(:tax_category, tax_rates: [tax_rate_shipping]) }
let(:zone) { create(:zone_with_member) }
let(:shipment) { create(:shipment) }
let(:shipping_method) { create(:shipping_method, tax_category: tax_category_shipping) }
let(:shipment) { create(:shipment_with, :shipping_method, shipping_method: shipping_method) }
let(:line_item) { create(:line_item) }
let(:enterprise_fee) { create(:enterprise_fee, tax_category: tax_category) }
let(:order) { create(:order_with_taxes, zone: zone) }
@@ -22,6 +27,11 @@ describe TaxRateFinder do
expect(rates).to eq [tax_rate]
end
it "finds the tax rate of a shipping_method fee" do
rates = subject.tax_rates(shipping_method, shipment)
expect(rates).to eq [tax_rate_shipping]
end
it "deals with soft-deleted tax rates" do
tax_rate.destroy
rates = subject.tax_rates(tax_rate, shipment)