You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Using this extension on a fairly large production Spree installation and were running into problems when calculating taxes when an order promotion was involved.
Example: An item is $50, but there is a whole order promotion for 50% off, so the line item is $25, however taxes are based on the individual line items, so the customer pays tax for $50.
This is probably a deal breaker for most people wanting to use this extension, so I came up with a way to take discounts into account when calculating tax rates.
First step is to understand how to get the "final" price of the line item so the proper tax rate can be calculated. This is not so bad when there are %off promos, but it gets dicey when there are $off promotions because it becomes hard to tell where those discounts are going. As a general rule, I will distribute all discount amounts across the line items evenly. Here's how the equation looks in code:
The to_d.truncate(2).to_f is a little weird, because I kept getting rounding issues, but that combination seemed to fix it.
This has been working well for awhile, however there are a few other places where I needed to append values to a model's tax_cloud_cache_key or re-trigger tax rates manually in certain places. There were many times where orders would change, but taxes would not get re-calculated, or it would just return a cached value that wasn't correct.
I'd love to open up a discussion about this problem, and if anyone thinks the code I came up with this is useful, I could submit a PR with the additions.
Thanks!
The text was updated successfully, but these errors were encountered:
Using this extension on a fairly large production Spree installation and were running into problems when calculating taxes when an order promotion was involved.
Example: An item is $50, but there is a whole order promotion for 50% off, so the line item is $25, however taxes are based on the individual line items, so the customer pays tax for $50.
This is probably a deal breaker for most people wanting to use this extension, so I came up with a way to take discounts into account when calculating tax rates.
First step is to understand how to get the "final" price of the line item so the proper tax rate can be calculated. This is not so bad when there are %off promos, but it gets dicey when there are $off promotions because it becomes hard to tell where those discounts are going. As a general rule, I will distribute all discount amounts across the line items evenly. Here's how the equation looks in code:
The
to_d.truncate(2).to_f
is a little weird, because I kept getting rounding issues, but that combination seemed to fix it.This has been working well for awhile, however there are a few other places where I needed to append values to a model's
tax_cloud_cache_key
or re-trigger tax rates manually in certain places. There were many times where orders would change, but taxes would not get re-calculated, or it would just return a cached value that wasn't correct.I'd love to open up a discussion about this problem, and if anyone thinks the code I came up with this is useful, I could submit a PR with the additions.
Thanks!
The text was updated successfully, but these errors were encountered: