medusajs / medusa

The world's most flexible commerce platform.
https://medusajs.com
MIT License
25.85k stars 2.59k forks source link

Current shipping rate VAT calculation is incorrect more often than not #2814

Closed josetr closed 11 months ago

josetr commented 1 year ago

Bug report

Describe the bug

A clear and concise description of what the bug is.

https://www.taxdoo.com/en/blog/how-to-determine-the-vat-rate-on-shipping-costs-etc-and-how-to-reduce-the-vat-rate-on-some-products-7795/

If the shipping cost is 6 euros 

Book “Effect of spices”: 10 euros plus 0.70 euros Value Added Tax (7 percent Value Added Tax)
Tonka beans: 20 euros plus 3.80 euros Value Added Tax (19 percent Value Added Tax)
Shipping costs (book): 2 euros plus 0.14 euros Value Added Tax (7 percentValue Added Tax)
Shipping costs (tonka beans): 4 euros plus 0.76 euros Value Added Tax (19 percent Value Added Tax).

System information

Medusa version (including plugins): 1.7.0 Node.js version: v16.18.1 Database: PostgreSQL Operating system: Windows 10

Steps to reproduce the behavior

  1. npm run seed
  2. Go to tax settings / EU 2.1. Change default tax rate to 21% 2.2 Add a new reduced 7% tax rate with an override for the Medusa Mug
  3. Create a draft order that only contains the single Medusa Mug and uses PostFake Standard

image

Screenshots

image

Expected behavior

Tax should be 1.40€

Current behavior

Tax is 2.80€

olivermrbl commented 1 year ago

Thanks for reporting this in @josetr. Can I get you to provide details on your environment and setup, so I can try to reproduce?

josetr commented 1 year ago

Added more context, I hope it's enough.

@olivermrbl Can someone pay some attention to my 3 PR's? I'm trying to wait patiently but it's been a while.

olivermrbl commented 1 year ago

This is great - thanks!

Yes, I'll make sure to attend to them over the weekend.

olivermrbl commented 1 year ago

@josetr Did you also configure a tax rate override for the shipping option?

I believe the behavior described here is expected, as the shipping option uses the default tax rate in case no override exists. I've tried the exact steps here - with a shipping override - and the calculations are as you have described in the expected behavior section.

josetr commented 1 year ago

The shipping override option does not help because the shipping VAT % is not supposed to be independent of the product VAT, the shipping VAT % is linked to the product VAT %.

If you now add a 7% override for the shipping, and you have a single Medusa Shirt that has a 21% VAT, the shipping VAT will still be 7%, which is wrong.

See "How is the tax rate on shipping costs and Co. for mixed shopping baskets determined?" section in taxdoo's article.

olivermrbl commented 1 year ago

Got it - thanks for elaborating. I understand your concern now, but to be sure, I'll try to outline it here.

You would like the calculation of the shipping tax total to be proportionate to the cost of the products in your cart. So instead of calculating shipping taxes separately from product taxes, these should be tightly coupled. For each item - with a potentially different tax rate - you calculate their specific shipping tax.

Example cart:

Tax calculation (updated based on following message)

Tax total: $6.53

The above example is what you are requesting right? Please correct me if I am wrong.

Still, if you choose to create a shipping tax override for the option Shipping 1 with a tax rate of 5%, the calculation would be as follows:

Tax calculation (with shipping tax override)

Tax total: $5.4

Because we have applied an override, I would argue this is expected, but I would like to hear your thoughts on this case.

josetr commented 1 year ago

The first tax calculation you've shown is still not quite right because you first have to distribute the 10$ shipping cost, and only then calculate each individual tax line

**Example cart:**

Product 1, $10, 7% VAT
Product 2, $20, 21% VAT
Shipping 1 $10

# Wrong
Product 1 VAT: $0.7
Product 1 shipping VAT: $0.7
Product 2 VAT: $4.2
Product 2 shipping VAT: $2,1

# Correct
Product 1 VAT: $0.7
Product 1 shipping VAT: $0.23 (10 * 0.3333 * 0.07)
Product 2 VAT: $4.2
Product 2 shipping VAT: $1.4 (10 * 0.6666 * 0.21)
olivermrbl commented 1 year ago

Makes sense - thanks for the correction. I've updated the example.

What's your thoughts around the case with overrides?

josetr commented 1 year ago

Makes sense - thanks for the correction. I've updated the example.

What's your thoughts around the case with overrides?

I think the 2nd tax calculation that you've provided is also wrong

The VAT calculation + override that we currently have is enough for those countries where the shipping VAT % is fixed and doesn't depend on the products, but in most US States, the shipping tax depends on the products sale tax. If there is no sale tax, there is no shipping tax.

In some EU countries, the behaviour that I've explained is the one used, but in others, the highest product VAT in the basket is the one used as the shipping VAT.

At the end of the day, the whole thing is very complicated, but I think the VAT calculation that I've suggested is the one that should be the default as I think it's the most common and the most fair.

olivermrbl commented 1 year ago

I think the 2nd tax calculation that you've provided is also wrong

The override is for the shipping option with a price of $10 (I updated my example as I noticed it was missing the option), so I don't think it's directly wrong - at least not in all cases. As you mention, it depends on the country you're shipping to and how you calculate shipping tax. Right now, we do it in isolation from products. But let us not dwell on details here.

I think your suggestion on making shipping tax depend on products rather than being a separate calculation is reasonable, and I will bring this up for our tax specialists.

Yes, taxes are indeed notoriously complex and hard to handle. Our current way of calculating taxes likely falls short in some areas and can be inadequate for merchants. For those cases, I recommend integrating with an advanced taxes engine like TaxJar or Avalara. These are specialized tools built to cover all cases. We've created a tax-provider interface, that should make the integration work less heavy. Alternatively, you can also build your own tax-calculation strategy giving you full control of the calculation done on items in your cart.

I will get back with an update from our taxes team soon :)

josetr commented 1 year ago

My bad, I meant the math was wrong, not the tax calculation method itself.

I do agree that using TaxJar / Avalara is the right way to do it, but those options are not free, and adding the option that I'm suggesting will be enough for a lot of people, especially those that are only making domestic sales (as long as it's not the US).

adrien2p commented 11 months ago

Hi there. We highly appreciate you filing an issue and showing an interest in improving Medusa.

I apologize for the delayed response.

Moving forward, we aim to do better. But we would like to start fresh. Therefore, we are considering all older issues as stale and closing them, even though they might still be relevant.

Please don't hesitate to re-open the issue (or create a new one) if you still need a resolution or an answer.

Thanks ❤️