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

Possible miscalculation of discounts in transactions #41

Open
jkelleyj opened this issue Oct 2, 2018 · 3 comments
Open

Possible miscalculation of discounts in transactions #41

jkelleyj opened this issue Oct 2, 2018 · 3 comments

Comments

@jkelleyj
Copy link

jkelleyj commented Oct 2, 2018

In transactions, the "weightage" function used to distribute the discounts across line items is a little off. It uses the unit_price instead of the unit_price * quantity https://github.com/vinsol-spree-contrib/spree_taxjar/blob/master/app/models/spree/taxjar.rb#L207

I believe this will under-represents the discounts, though this may have no bearing on the tax reported if TaxJar uses the amount field exclusively.

Have you experienced any API validation errors regarding the discounts not matching the totals?

@avneetmalhotra
Copy link

Hi @jkelleyj

Thanks for reporting this issue. We will fix it soon.

@jkelleyj
Copy link
Author

jkelleyj commented Oct 4, 2018

Thanks @avneetmalhotra

I've been working with the extension and making some changes in my own repo, so I haven't fully confirmed this issue. According to TaxJar's api, the discounts on the line item should be the full discount amount for that line (not the per unit discount):
https://developers.taxjar.com/api/reference/#post-create-an-order-transaction

It says the API will raise a 400 error if the amount and the line item amounts + discounts don't line up, so I'm surprised no one using this extension has seen that error if this is actually a bug. Will let you know as I find more details in our testing.

@jkelleyj
Copy link
Author

jkelleyj commented Oct 4, 2018

I'm also a little suspicious of using @order.item_total as the denominator in that weightage calculation since this is defined as sum(price*quantity) and does not factor in line item discounts as taxable_amount would.

Maybe a better approach is: weightage = @order.adjustments.sum(:amount) / @order.line_items.map(&:taxable_amount).sum

This weightage could be multiplied by the taxable amount of the line item so we get a pure ratio that will be guaranteed to add up to 100% of the adjustments sum

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

2 participants