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

Correctly apply relevant tax rates #4327

Closed
wants to merge 13 commits into from
Closed

Correctly apply relevant tax rates #4327

wants to merge 13 commits into from

Conversation

radar
Copy link
Contributor

@radar radar commented Feb 11, 2014

This is a medium size PR which addresses a couple of things:

1. Shipments were not being taxed correctly if the rate was an inclusive tax.

This is now fixed by shipping methods linking to tax categories, and then when shipping rates are generated the relevant tax rate (if any) is linked to the shipment. As a "side-effect" of this, shipping rates are able to display the amount of tax they will incur.

2. Fixes #4318

I've personally witnessed a case where tax rates from the same tax category were being applied to an item in the order. See my example in #4318. There is now a fix for this within this PR.

3. Altered the Spree::TaxRate specs to call class-level adjust, not instance-level

This means that the fix for point number 2 here is tested. A small difference, but an important one.

4. Pre-tax amounts are now being stored

Previously, if you wanted to gain access to the pre-tax amount for an item you would need to re-calculate that based off the tax for that item. Now it's stored and you don't need to do the calculation. This amount is then used to calculate the amount of tax that should be applied to an item. For instance, a $10 item with 10% inclusive tax should have a tax amount of $0.91, not $1.00. Sales tax of 10% would cause the tax rate to be an additional one of 10%, which would be $1.00 and NOT $0.91.

(Have I mentioned how much fun tax is yet?)

5. Fixed some silly double looping in checkout's sidebar

It was seriously dumb and I think it was my fault. It was causing tax rates to appear not once but twice. Fix was simple.

Build is green on CI.

/cc @cduv @jdurand

@peterberkenbosch
Copy link
Member

👍 :shipit:

@jdurand
Copy link
Contributor

jdurand commented Feb 11, 2014

Will this be merged to 2-0-stable or just 2-1-stable and upwards?

@radar
Copy link
Contributor Author

radar commented Feb 11, 2014

@jdurand Just 2-2-stable and upwards, as that has the proper adjustments on the taxes. 2-1-stable and below have adjustments being applied to sometimes the order and sometimes the line item.

@radar
Copy link
Contributor Author

radar commented Feb 12, 2014

@jdurand Sorry, just realised why you were asking that question. We will of course need to fix the root thing for #4318 within 2-0-stable and 2-1-stable because clearly it's applying the wrong tax rates there. I will look at that later on.

@radar
Copy link
Contributor Author

radar commented Feb 12, 2014

Going to merge this into 2-2-stable and master tomorrow if nobody sees any problems with it. Will fix up 2-1-stable next week.

def display_price
price = display_base_price.to_s
if tax_rate
amount = "#{display_tax_amount} #{tax_rate.name}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be great to have this translatable/localizable

@cduv
Copy link

cduv commented Feb 18, 2014

Hi @radar

We have been testing master and your relevant-taxes branch following your recommendation for European VAT support. Our objective is to try use Spree without modifications to solve the European VAT case. We worked the example of an Spanish company selling to Spain, France and Kenya. We have added screenshots and what we expected to be shown in the following document.

https://docs.google.com/spreadsheet/ccc?key=0Ai2VOmMTsnohdEdiQW14ZDFSSmFpelNoNUtVZTIwMEE&usp=sharing

Our results and comments are:

  1. The case of selling to Spain works perfect and we have used the new field pre_tax_amount ( Excellent idea). The only thing will be to extract the VAT from the shipping costs without VAT.

  2. We haven't succeed with the case of selling to France. We have tested with the different options of the parameter tax included in price. You can see our results in the doc. After testing this I think that for us always will be better to use prices without taxes, but show them with taxes and will be easy to manage the prices, billing, etc... But I understand that is part of your program design and we have to adapt. Lets see if you find what are we doing wrong. Really it should discount the spanish taxes and add the France taxes with same value getting the same result than the spanish case.

  3. The Kenya case works perfect and the result is correct.

  4. About the negative Taxes in a real project we could hide it and only show the positives one that are the real taxes applied.

  5. How can we find the shipping taxes? I think it worked in the other branch.

  6. Getting more in the solution we find that forcing to show prices with vat in our case will be complex to show the price for different countries and VAT included.

Hope this work helps and ask anything you need. I will like to see that Spree is European VAT Ready and well done with the adjustments refactoring .

Thanks

Genís

@radar
Copy link
Contributor Author

radar commented Feb 19, 2014

I've added this PR to master and 2-2-stable today. The 2.2 release is imminent and I think it's worthwhile having this PR in as it addresses some (but admittedly not all) issues with taxes. We can take a look at those issues after 2.2 has been released as part of our work on 2.2.1.

The thing I said I would do for 2-1-stable will also be done at a later stage.

I will be leaving this PR open.

@radar
Copy link
Contributor Author

radar commented Mar 24, 2014

Hi @cduv,

I have done some (read: I started at a little after 9:30am and it's now almost 4pm) work on this today and I think I've solved it. Which probably means that I haven't at all and someone else will find some weird edge case but that's OK. I think.

Without further ado, here's Spain (the default tax zone), France (the not-so-default tax zone) and Australia (no tax zones).

All amounts according to my calculations are correct.

Here are the commits:

radar/spree@850c04e9cd61529b246c83517780c4968c6fb146
radar/spree@181f53b12cf91cf6fe5824590b66ce80a6944528 (with some "light" documentation)
radar/spree@ab1b4464ee59b7e2ac9b3a894cdda9f39bbd4795
radar/spree@0e3402635a1294453a4d6888ed6f6e9b55f07ab9
radar/spree@0595601488d98166170b0eb4587bdaa893862140
radar/spree@2a39e088399766da2da9cd50fec89b59b1dc4941
radar/spree@1fad128db992de7456e09655c75e5288120c1816
radar/spree@4c83cc235a80cd94ed45a2957ee2ccb18894e1b2
radar/spree@02a5b57bd05837b926810fc9de76f4a68838b9aa
radar/spree@10d6ec39d355d90531463b0d14e0653e151bf5fa

And finally:

radar/spree@189f3e1ddf90ac7d39a4e47c7003e238ce205ab4 (which took forever to track down!)

@radar radar added this to the v2.2.1 milestone Mar 24, 2014
@cduv
Copy link

cduv commented Mar 24, 2014

Hi @radar

Great work!!! We are going to check it, but from your results looks that is working nice. I will confirm.

Thanks

radar added a commit that referenced this pull request Mar 25, 2014
…itive adjustment for the order's tax zone if the tax rate is included in the price

This should fix the Spain + France + Kenya problems outlined here: #4327 (comment)
@radar
Copy link
Contributor Author

radar commented Mar 25, 2014

🎉

Thank you @cduv. That confirmation would be very much appreciated, but no rush on it.

radar added a commit that referenced this pull request Mar 26, 2014
…itive adjustment for the order's tax zone if the tax rate is included in the price

This should fix the Spain + France + Kenya problems outlined here: #4327 (comment)
@JDutil
Copy link
Member

JDutil commented May 22, 2014

Run into any issues @cduv or have you confirmed things are working as expected?

@JDutil
Copy link
Member

JDutil commented May 22, 2014

Going to close out, but will reopen if needed.

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.

Taxes being combined incorrectly
6 participants