Skip to content

Commit

Permalink
if iseligible is false, do not allow calculator to hit api
Browse files Browse the repository at this point in the history
  • Loading branch information
acreilly committed Aug 2, 2016
1 parent 01459c5 commit 6ac9a36
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions app/models/spree/calculator/avalara_transaction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def compute_shipment_or_line_item(item)
item_address = order.ship_address || order.billing_address
prev_tax_amount = prev_tax_amount(item)

return prev_tax_amount unless Spree::AvalaraPreference.iseligible.is_true?
return prev_tax_amount if %w(address cart).include?(order.state)
return prev_tax_amount if item_address.nil?
return prev_tax_amount unless calculable.zone.include?(item_address)
Expand Down
11 changes: 9 additions & 2 deletions spec/models/spree/calculator/avalara_transaction_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,25 @@
expect(calculator.compute(line_item)).to eq(0.4)
end

it 'should be equal to the previous additional_tax_total is order is at cart' do
it 'should be equal to the previous additional_tax_total if order is at cart' do
order.state = 'cart'
line_item.additional_tax_total = 0.1
expect(calculator.compute(line_item)).to eq(0.1)
end

it 'should be equal to the previous additional_tax_total is order is at address' do
it 'should be equal to the previous additional_tax_total if order is at address' do
order.state = 'address'
line_item.additional_tax_total = 0.1
expect(calculator.compute(line_item)).to eq(0.1)
end

it 'should be equal to the previous tax total if preference iseligible is false' do
Spree::AvalaraPreference.iseligible.update_attributes(value: 'false')

line_item.additional_tax_total = 0.1
expect(calculator.compute(line_item)).to eq(0.1)
end

context 'when the order is discounted' do
let(:promotion) { create(:promotion, :with_order_adjustment) }

Expand Down

0 comments on commit 6ac9a36

Please sign in to comment.