diff --git a/lib/open_food_network/enterprise_fee_applicator.rb b/lib/open_food_network/enterprise_fee_applicator.rb index f59c94f119..070cb4a91c 100644 --- a/lib/open_food_network/enterprise_fee_applicator.rb +++ b/lib/open_food_network/enterprise_fee_applicator.rb @@ -32,7 +32,9 @@ module OpenFoodNetwork end def adjustment_tax(order, adjustment) - enterprise_fee.tax_category.tax_rates.match(order).sum do |rate| + tax_rates = enterprise_fee.tax_category ? enterprise_fee.tax_category.tax_rates.match(order) : [] + + tax_rates.sum do |rate| compute_tax rate, adjustment.amount end end diff --git a/spec/models/spree/adjustment_spec.rb b/spec/models/spree/adjustment_spec.rb index 0922597c2a..35746b28fd 100644 --- a/spec/models/spree/adjustment_spec.rb +++ b/spec/models/spree/adjustment_spec.rb @@ -84,7 +84,6 @@ module Spree let!(:zone_member) { ZoneMember.create!(zone: zone, zoneable: Country.find_by_name('Australia')) } let(:tax_rate) { create(:tax_rate, included_in_price: true, calculator: Calculator::DefaultTax.new, zone: zone, amount: 0.1) } let(:tax_category) { create(:tax_category, tax_rates: [tax_rate]) } - let(:tax_category_untaxed) { create(:tax_category) } let(:coordinator) { create(:distributor_enterprise) } let(:variant) { create(:variant) } @@ -120,7 +119,7 @@ module Spree describe "when enterprise fees have no tax" do before do - enterprise_fee.tax_category = tax_category_untaxed + enterprise_fee.tax_category = nil enterprise_fee.save! order.update_distribution_charge! end