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

Fix calculation of taxes when items are discounted #155

Merged
merged 6 commits into from Nov 14, 2018

Conversation

mraerino
Copy link
Member

@mraerino mraerino commented Nov 2, 2018

Fixes #129

- Summary

The current behavior of GoCommerce is to apply discounts after calculating taxes.
This is valid for neither VAT nor sales tax based systems because taxes need to be applied to the final net amount. See #129 for more info and examples.

This PR includes several refactors to make the change easier.

The central commit (11df6e0) will change the calculation of a single item to this procedure:

  • Get amount from item (net or gross)
  • Subtract discount (fixed or relative) from this amount
  • If prices include taxes, calculate the net amount (saved in field net_total)
  • Calculate taxes from the net amount
  • Calculate total by adding net_total + taxes

Introduces the field NetTotal for orders and price items.
This field represents the net amount of a single item or an order that taxes are calculated based on. While the SubTotal amount is not discounted, the NetTotal is.
This is especially important when prices are expected to include taxes. In these cases discounts are applied to the original price and then the net price is calculated.

Notice: You can not calculate the net amount from the subtotal by subtracting the discount when prices include taxes. The discount will always be based on the original price while the behavior of the subtotal is not changed an will show the non-discounted net total. There are several possible improvements for that problem (e.g. adding a field "original price").

- Test plan

Several tests have been added or updated to reflect this altered calculation behavior.
Since this fixes the behavior of the tax calculation for discounted orders this is where tests needed to change.

- Description for the changelog

Fix calculation to apply discount before taxes

- A picture of a cute animal (not mandatory but encouraged)

@mraerino mraerino force-pushed the fix/calculation-discount-taxes branch from 4904fa7 to 55ab899 Compare November 2, 2018 16:58
@mraerino mraerino changed the title Fix calculation of taxes when items are discounted WIP: Fix calculation of taxes when items are discounted Nov 9, 2018
@mraerino mraerino force-pushed the fix/calculation-discount-taxes branch from a47ff3f to 0be552d Compare November 13, 2018 13:41
Introduces the field "NetTotal" for orders and price items.
This field represents the net amount of a single item or an order
that taxes are calculated based on. While the "subtotal" amount is
not discounted, the "NetTotal" is.
This is especially important when prices are expected to include
taxes. In these cases discounts are applied to the original price
and then the net price is calculated.
Since this fixes the behavior of the tax calculation for discounted
orders this is where tests needed to change.
@mraerino mraerino force-pushed the fix/calculation-discount-taxes branch from 0be552d to cac1d86 Compare November 13, 2018 13:47
@mraerino mraerino changed the title WIP: Fix calculation of taxes when items are discounted Fix calculation of taxes when items are discounted Nov 13, 2018
@mraerino
Copy link
Member Author

mraerino commented Nov 13, 2018

@bcomnes this has been refined to not be a breaking change and is ready for review now 🙂

@bcomnes
Copy link
Contributor

bcomnes commented Nov 14, 2018

@bcomnes this has been refined to not be a breaking change and is ready for review now 🙂

Fantastic thank you.

@bcomnes bcomnes merged commit e8c9056 into netlify:master Nov 14, 2018
@indysigner
Copy link

Brilliant, thank you @mraerino

@bcomnes
Copy link
Contributor

bcomnes commented Nov 14, 2018

@mraerino Did this have anything to do with #153 ?

@mraerino
Copy link
Member Author

@bcomnes nope. that was not part of my contract since it arrived later. it is only partly related as well

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

Successfully merging this pull request may close these issues.

Tax calculation disregards discounts [CRITICAL]
3 participants