From 81324f3cc41f6db560ce99a7d484ea5c8905976a Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Thu, 9 Apr 2015 11:04:54 +1000 Subject: [PATCH] Do not charge tax on shipments when distributor does not charge sales tax --- app/models/spree/shipment_decorator.rb | 6 +++++- spec/models/spree/adjustment_spec.rb | 10 +++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/app/models/spree/shipment_decorator.rb b/app/models/spree/shipment_decorator.rb index ee9189efdd..460fae4985 100644 --- a/app/models/spree/shipment_decorator.rb +++ b/app/models/spree/shipment_decorator.rb @@ -3,7 +3,11 @@ module Spree def ensure_correct_adjustment_with_included_tax ensure_correct_adjustment_without_included_tax - adjustment.set_included_tax! Config.shipping_tax_rate if Config.shipment_inc_vat + if Config.shipment_inc_vat && (order.distributor.nil? || order.distributor.charges_sales_tax) + adjustment.set_included_tax! Config.shipping_tax_rate + else + adjustment.set_included_tax! 0 + end end alias_method_chain :ensure_correct_adjustment, :included_tax diff --git a/spec/models/spree/adjustment_spec.rb b/spec/models/spree/adjustment_spec.rb index e69d04da6f..0f559f60cd 100644 --- a/spec/models/spree/adjustment_spec.rb +++ b/spec/models/spree/adjustment_spec.rb @@ -30,7 +30,8 @@ module Spree end describe "Shipment adjustments" do - let!(:order) { create(:order, shipping_method: shipping_method) } + let!(:order) { create(:order, distributor: hub, shipping_method: shipping_method) } + let(:hub) { create(:distributor_enterprise, charges_sales_tax: true) } let!(:line_item) { create(:line_item, order: order) } let(:shipping_method) { create(:shipping_method, calculator: Calculator::FlatRate.new(preferred_amount: 50.0)) } let(:adjustment) { order.adjustments(:reload).shipping.first } @@ -80,6 +81,13 @@ module Spree adjustment.included_tax.should == 0 end + + it "records 0% tax on shipments when the distributor does not charge sales tax" do + order.distributor.update_attributes! charges_sales_tax: false + order.reload.create_shipment! + + adjustment.included_tax.should == 0 + end end end