boomerdigital / spree_avatax_certified

Improve your Spree store's sales tax decision automation with Avalara AvaTax
Other
12 stars 42 forks source link

[2-3-stable] RMAs can be processed multiple times #50

Closed kknd113 closed 9 years ago

kknd113 commented 9 years ago

Suppose there are multiple returns (therefore multiple return_authorizations) on same order. When i th RMA is received/processed, we are sending every single order.return_authorizations to Avalara (1st, 2nd... i th RMAs).

Expected behavior: When i th RMA is received, i-1, i-2 th, ... RMA should not be considered since they are already committed to Avalara previously

Relevant code in avalara_transaction.rb

order_details.return_authorizations.each do |return_auth|

          line = Hash.new
          i += 1
          line[:LineNo] = "#{i}-RA"
          line[:ItemCode] = "Return Authorization"
          line[:Qty] = 1
          if invoice_detail == "ReturnInvoice" || invoice_detail == "ReturnOrder"
            line[:Amount] = -return_auth.amount.to_f
          else
            line[:Amount] = return_auth.amount.to_f

          end
          line[:OriginCode] = "Orig"
          line[:DestinationCode] = "Dest"

          if myusecode
            line[:CustomerUsageType] = myusecode.try(:use_code)
          end

          line[:Description] = return_auth.reason
          line[:TaxCode] = ""

          AVALARA_TRANSACTION_LOGGER.debug line.to_xml

          tax_line_items<<line
        end
acreilly commented 9 years ago

Hah, I am actually working on fixing that right now.

acreilly commented 9 years ago

https://github.com/railsdog/spree_avatax_certified/commit/ca7358a8cb4a719e85115dfa565d5a9e6459fbd6

kknd113 commented 9 years ago

@acreilly Fix looks perfect. Thanks