From 405b7e6e177d970ad383d4ff9074c4e2723921d5 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Fri, 11 Feb 2022 09:23:51 +0100 Subject: [PATCH] Handle tax rates for ShippingMethod Co-Authored-By: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> --- app/services/tax_rate_finder.rb | 6 ++++++ spec/services/tax_rate_finder_spec.rb | 12 +++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/app/services/tax_rate_finder.rb b/app/services/tax_rate_finder.rb index 1f90304efe..e49d615976 100644 --- a/app/services/tax_rate_finder.rb +++ b/app/services/tax_rate_finder.rb @@ -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 diff --git a/spec/services/tax_rate_finder_spec.rb b/spec/services/tax_rate_finder_spec.rb index 8fcfdb738c..b62b348905 100644 --- a/spec/services/tax_rate_finder_spec.rb +++ b/spec/services/tax_rate_finder_spec.rb @@ -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)