diff --git a/app/models/spree/tax_rate_decorator.rb b/app/models/spree/tax_rate_decorator.rb index 330312dac4..42eae86b8c 100644 --- a/app/models/spree/tax_rate_decorator.rb +++ b/app/models/spree/tax_rate_decorator.rb @@ -1,7 +1,7 @@ Spree::TaxRate.class_eval do class << self def match_with_sales_tax_registration(order) - return [] unless order.distributor.charges_sales_tax + return [] if order.distributor && !order.distributor.charges_sales_tax match_without_sales_tax_registration(order) end alias_method_chain :match, :sales_tax_registration diff --git a/spec/features/consumer/shopping/checkout_spec.rb b/spec/features/consumer/shopping/checkout_spec.rb index a02d137983..116e52e473 100644 --- a/spec/features/consumer/shopping/checkout_spec.rb +++ b/spec/features/consumer/shopping/checkout_spec.rb @@ -9,7 +9,7 @@ feature "As a consumer I want to check out my cart", js: true do include UIComponentHelper let!(:zone) { create(:zone_with_member) } - let(:distributor) { create(:distributor_enterprise) } + let(:distributor) { create(:distributor_enterprise, charges_sales_tax: true) } let(:supplier) { create(:supplier_enterprise) } let!(:order_cycle) { create(:simple_order_cycle, suppliers: [supplier], distributors: [distributor], coordinator: create(:distributor_enterprise), variants: [product.master]) } let(:enterprise_fee) { create(:enterprise_fee, amount: 1.23, tax_category: product.tax_category) } diff --git a/spec/models/spree/tax_rate_spec.rb b/spec/models/spree/tax_rate_spec.rb index ba13ca4b83..25aad986a0 100644 --- a/spec/models/spree/tax_rate_spec.rb +++ b/spec/models/spree/tax_rate_spec.rb @@ -5,7 +5,7 @@ module Spree let!(:order) { create(:order, distributor: hub, bill_address: create(:address)) } let!(:tax_rate) { create(:tax_rate, included_in_price: true, calculator: Calculator::FlatRate.new(preferred_amount: 0.1), zone: zone) } - context "when the order's hub charges sales tax" do + describe "when the order's hub charges sales tax" do let(:hub) { create(:distributor_enterprise, charges_sales_tax: true) } it "selects all tax rates" do @@ -13,13 +13,21 @@ module Spree end end - context "when the order's hub does not charge sales tax" do + describe "when the order's hub does not charge sales tax" do let(:hub) { create(:distributor_enterprise, charges_sales_tax: false) } it "selects no tax rates" do TaxRate.match(order).should be_empty end end + + describe "when the order does not have a hub" do + let!(:order) { create(:order, distributor: nil, bill_address: create(:address)) } + + it "selects all tax rates" do + TaxRate.match(order).should == [tax_rate] + end + end end end end