Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

avalara_response[:totalTax] is always nil #96

Closed
prdanelli opened this issue Apr 26, 2018 · 5 comments
Closed

avalara_response[:totalTax] is always nil #96

prdanelli opened this issue Apr 26, 2018 · 5 comments

Comments

@prdanelli
Copy link

prdanelli commented Apr 26, 2018

The conditional return 0 if avalara_response[:totalTax] == 0.0, but not as intended, as avalara_response[:totalTax] always returns nil because it will not be found in the hash.

Should be...

module Spree
  class Calculator::AvalaraTransaction < Calculator::DefaultTax
    # ...

    def tax_for_item(item, avalara_response)
      prev_tax_amount = prev_tax_amount(item)

      return prev_tax_amount if avalara_response.nil?
      return 0 if avalara_response['totalTax'] == 0.0

      avalara_response['lines'].each do |line|
        if line['lineNumber'] == "#{item.id}-#{item.avatax_line_code}"
          return line['taxCalculated']
        end
      end
      0
    end
  end
end
@prdanelli prdanelli changed the title avalara_response[:totalTax] returns nil without indifferent access enabled avalara_response[:totalTax] returns but not as intended Apr 26, 2018
@prdanelli prdanelli changed the title avalara_response[:totalTax] returns but not as intended avalara_response[:totalTax] is always nil Apr 26, 2018
@dhonig
Copy link
Contributor

dhonig commented Apr 26, 2018

@prwhitehead thanks for the contributions. The team will be able to take a look at this shortly. @acreilly @jasonfb

@acreilly
Copy link
Contributor

@prwhitehead Which branch are you working off of?

The reasoning behind this is because if either tax calculation or document committing are set to false:
https://github.com/boomerdigital/solidus_avatax_certified/blob/master/app/models/spree/avalara_transaction.rb#L21

Or if an error arises:
https://github.com/boomerdigital/solidus_avatax_certified/blob/master/app/models/spree/avalara_transaction.rb#L63

We want a quick way to return 0 since there will be no avalara_response['lines']

If avalara_response[:totalTax] is not found in the hash, then that is because it has calculated properly.
@dhonig thoughts?

@dhonig
Copy link
Contributor

dhonig commented Apr 26, 2018

@jasonfb @acreilly maybe check for this condition and set a sensible default?

@prdanelli
Copy link
Author

@acreilly sorry I dont think I explained as well as I could. The hash is not set with_indifferent_access, so avalara_response[:totalTax] will always return nil as the key is (string) "totalTax" not (symbol) :totalTax.

@acreilly
Copy link
Contributor

#113

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants