magento / magento2

Prior to making any Submission(s), you must sign an Adobe Contributor License Agreement, available here at: https://opensource.adobe.com/cla.html. All Submissions you make to Adobe Inc. and its affiliates, assigns and subsidiaries (collectively “Adobe”) are subject to the terms of the Adobe Contributor License Agreement.
http://www.magento.com
Open Software License 3.0
11.47k stars 9.28k forks source link

Cross Border Trade kicks in even when no tax should be calculated #35592

Open hostep opened 2 years ago

hostep commented 2 years ago

Preconditions and environment

Steps to reproduce

  1. Install a clean Magento

  2. After bin/magento setup:install ... was executed, further configure your instance like this:

    bin/magento config:set   currency/options/allow                       EUR
    bin/magento config:set   currency/options/base                        EUR
    bin/magento config:set   currency/options/default                     EUR
    bin/magento config:set   general/country/default                      BE
    bin/magento config:set   general/locale/timezone                      Europe/Brussels
    bin/magento config:set   general/single_store_mode/enabled            0
    bin/magento config:set   shipping/origin/country_id                   BE
    bin/magento config:set   shipping/origin/postcode                     9000
    bin/magento config:set   shipping/origin/region_id                    628
    bin/magento config:set   tax/calculation/cross_border_trade_enabled   1
    bin/magento config:set   tax/calculation/discount_tax                 1
    bin/magento config:set   tax/calculation/price_includes_tax           1
    bin/magento config:set   tax/calculation/shipping_includes_tax        1
    bin/magento config:set   tax/cart_display/full_summary                1
    bin/magento config:set   tax/cart_display/grandtotal                  1
    bin/magento config:set   tax/cart_display/price                       2
    bin/magento config:set   tax/cart_display/shipping                    2
    bin/magento config:set   tax/cart_display/subtotal                    2
    bin/magento config:set   tax/cart_display/zero_tax                    1
    bin/magento config:set   tax/classes/shipping_tax_class               2
    bin/magento config:set   tax/defaults/country                         BE
    bin/magento config:set   tax/display/shipping                         2
    bin/magento config:set   tax/display/type                             2
    bin/magento config:set   tax/notification/ignore_apply_discount       0
    bin/magento config:set   tax/notification/ignore_discount             0
    bin/magento config:set   tax/notification/ignore_price_display        0
    bin/magento config:set   tax/sales_display/full_summary               1
    bin/magento config:set   tax/sales_display/grandtotal                 1
    bin/magento config:set   tax/sales_display/price                      2
    bin/magento config:set   tax/sales_display/shipping                   2
    bin/magento config:set   tax/sales_display/subtotal                   2
    bin/magento config:set   tax/sales_display/zero_tax                   1
  3. Setup these tax rates tax-rates

  4. Setup this one tax rule - while setting it up, make sure to also create the Customer Tax Class 'Other Customer', but don't check it in this tax rule tax-rule

  5. Create a customer group 'Other Customer' and associate it with the 'Other Customer' Tax Class that you setup in the previous step

  6. In the backoffice, create these 2 customers with these addresses as default shipping & billing address:

Name Customer Group Country City Postal code Street
With Tax General Luxembourg City 1234 Street
Without Tax Other Customer Luxembourg City 1234 Street
  1. In the backoffice, create a category
  2. And also create a simple product to associate with the category and with these details:
Price Tax Class Quantity Stock Status
100 EUR Taxable Goods 9999 In Stock
  1. Use 2 different browsers to visit the frontend, login with the first customer in your first browser and with the second customer in your second browser (the customers you created in step 6)
  2. In both browsers, put the newly created product in your cart and navigate to the shopping cart page

Expected result

Following totals should be displayed:

Customer Subtotal Shipping Tax Order Incl Tax Order Excl Tax
With Tax 100 5 15.26 105 89.74
Without Tax 85.47 4.27 0 89.74 89.74

Actual result

Following totals are being displayed:

Customer Subtotal Shipping Tax Order Incl Tax Order Excl Tax
With Tax 100 5 15.26 105 89.74
Without Tax 100 5 0 105 105

Additional information

So the cross border trade option in Magento is used to show prices inclusive tax the same across all EU countries even if each EU member state has a different tax rate for a product (well, in Magento it's implemented for ALL countries, instead of only for EU countries, but that's another bug I still need to report => update: probably not really a bug but a config option for this would be nice). It does so by changing the prices excl tax so those are different between the EU member states.

However, when a customer doesn't have to pay taxes - in the case of a B2B order from one EU member state to another member state for example (which I'm simulating here with the different customer groups that are assigned to the 2 customers) - it makes little sense for the cross border trade option to kick in when no taxes should be calculated.

Possible solution that I found so far but it's maybe not accurate:

diff --git a/app/code/Magento/Tax/Model/Calculation/AbstractCalculator.php b/app/code/Magento/Tax/Model/Calculation/AbstractCalculator.php
index 8cfe3079424..95128d1d741 100644
--- a/app/code/Magento/Tax/Model/Calculation/AbstractCalculator.php
+++ b/app/code/Magento/Tax/Model/Calculation/AbstractCalculator.php
@@ -276,7 +276,7 @@ abstract class AbstractCalculator
      */
     protected function isSameRateAsStore($rate, $storeRate)
     {
-        if ((bool)$this->config->crossBorderTradeEnabled($this->storeId)) {
+        if ((bool)$this->config->crossBorderTradeEnabled($this->storeId) && $rate > 0.0) {
             return true;
         } else {
             return (abs($rate - $storeRate) < 0.00001);

The added check on the $rate to be higher than 0, means that the cross border trade option does not kick in when no taxes should be calculated. However, the end result is not correct, as it calculates the price excl tax based on the Belgium rate (21%) instead of the Luxembourg rate (17%). So the end result looks like this with this solution:

Customer Subtotal Shipping Tax Order Incl Tax Order Excl Tax
With Tax 100 5 15.26 105 89.74
Without Tax 82.64 4.13 0 86.77 86.77

Which is in my opinion still not correct.

So to have a full fix, we'll somehow need to calculate 17% tax instead of 21% for prices excl tax in this case when the tax rate is 0.

Update: I'm not longer convinced this is a correct assumption. The outcome with this fix might be correct because in the case when you sell to countries outside of the EU, it also subtracts 21% from the price incl tax. So maybe this is the correct outcome then for B2B sales to other EU member states after all... But I'm not an expert in international trade, so I'm not sure ...

Hope this makes sense, because it's quite complicated 🙂

Release note

When this issue gets fixed, release notes:

Fixes subtotal for orders with zero tax when cross border trade is enabled.

Triage and priority

m2-assistant[bot] commented 2 years ago

Hi @hostep. Thank you for your report. To speed up processing of this issue, make sure that you provided the following information:

Make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, Add a comment to the issue:

@magento give me 2.4-develop instance - upcoming 2.4.x release

For more details, review the Magento Contributor Assistant documentation.

Add a comment to assign the issue: @magento I am working on this

To learn more about issue processing workflow, refer to the Code Contributions.


:clock10: You can find the schedule on the Magento Community Calendar page.

:telephone_receiver: The triage of issues happens in the queue order. If you want to speed up the delivery of your contribution, join the Community Contributions Triage session to discuss the appropriate ticket.

:pencil2: Feel free to post questions/proposals/feedback related to the Community Contributions Triage process to the corresponding Slack Channel

m2-assistant[bot] commented 2 years ago

Hi @engcom-Lima. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:

engcom-Lima commented 2 years ago

@magento give me 2.4-develop instance

engcom-Lima commented 2 years ago

@magento give me 2.4-develop instance

magento-deployment-service[bot] commented 2 years ago

Hi @engcom-Lima. Thank you for your request. I'm working on Magento instance for you.

magento-deployment-service[bot] commented 2 years ago

Hi @engcom-Lima, here is your Magento Instance: https://0da443ed116034647d637f0a5494741e.instances.magento-community.engineering Admin access: https://0da443ed116034647d637f0a5494741e.instances.magento-community.engineering/admin_eca3 Login: 692f3262 Password: 588a7cdbda64

engcom-Lima commented 2 years ago

:heavy_check_mark: Issue confirmed

Issue got reproduced in 2.4-develop branch.

Description: Cross Border Trade kicks in even when no tax should be calculated Pre-requisite:

Steps to reproduce:

  1. After installation of magento, run below set of commands:
    
    bin/magento config:set   currency/options/allow                       EUR
    bin/magento config:set   currency/options/base                        EUR
    bin/magento config:set   currency/options/default                     EUR
    bin/magento config:set   general/country/default                      BE
    bin/magento config:set   general/locale/timezone                      Europe/Brussels
    bin/magento config:set   general/single_store_mode/enabled            0
    bin/magento config:set   shipping/origin/country_id                   BE
    bin/magento config:set   shipping/origin/postcode                     9000
    bin/magento config:set   shipping/origin/region_id                    628
    bin/magento config:set   tax/calculation/cross_border_trade_enabled   1
    bin/magento config:set   tax/calculation/discount_tax                 1
    bin/magento config:set   tax/calculation/price_includes_tax           1
    bin/magento config:set   tax/calculation/shipping_includes_tax        1
    bin/magento config:set   tax/cart_display/full_summary                1
    bin/magento config:set   tax/cart_display/grandtotal                  1
    bin/magento config:set   tax/cart_display/price                       2
    bin/magento config:set   tax/cart_display/shipping                    2
    bin/magento config:set   tax/cart_display/subtotal                    2
    bin/magento config:set   tax/cart_display/zero_tax                    1
    bin/magento config:set   tax/classes/shipping_tax_class               2
    bin/magento config:set   tax/defaults/country                         BE
    bin/magento config:set   tax/display/shipping                         2
    bin/magento config:set   tax/display/type                             2
    bin/magento config:set   tax/notification/ignore_apply_discount       0
    bin/magento config:set   tax/notification/ignore_discount             0
    bin/magento config:set   tax/notification/ignore_price_display        0
    bin/magento config:set   tax/sales_display/full_summary               1
    bin/magento config:set   tax/sales_display/grandtotal                 1
    bin/magento config:set   tax/sales_display/price                      2
    bin/magento config:set   tax/sales_display/shipping                   2
    bin/magento config:set   tax/sales_display/subtotal                   2
    bin/magento config:set   tax/sales_display/zero_tax                   1

2. Setup tax rates 
![image](https://user-images.githubusercontent.com/60198022/179519018-5de57a15-e203-49e0-ba5b-f900534c0976.png)
3. Setup this one tax rule - while setting it up, make sure to also create the Customer Tax Class 'Other Customer', but don't check it in this tax rule
![image](https://user-images.githubusercontent.com/60198022/179519097-5864a9ee-a914-403b-8d93-53953b2421bc.png)
4. Create a customer group 'Other Customer' and associate it with the 'Other Customer' Tax Class that you setup in the previous step.
5. In the backoffice, create these 2 customers with these addresses as default shipping & billing address:
![image](https://user-images.githubusercontent.com/60198022/179520888-5a037683-eeed-4585-bf30-6e680b4c3c44.png)

6 In the backoffice, create a category.
7.And also create a simple product to associate with the category and with these details:
![image](https://user-images.githubusercontent.com/60198022/179521176-06707091-7adb-4152-840a-816c4c85cbab.png)
8. Login and place an order from both the customers.

**Expected result:** 
![image](https://user-images.githubusercontent.com/60198022/179522476-d9bcb230-6b21-4d73-8b90-8151370c049d.png)

**Actual result:** 
**Without Tax-**
![image](https://user-images.githubusercontent.com/60198022/179521864-f9614099-9ae4-4f76-9ea2-6e36be8bba5f.png)
**With Tax**
![image](https://user-images.githubusercontent.com/60198022/179522416-ca9a211f-a9d1-4f30-97bf-fa8b5beb642f.png)
github-jira-sync-bot commented 2 years ago

:white_check_mark: Jira issue https://jira.corp.magento.com/browse/AC-5982 is successfully created for this GitHub issue.

m2-assistant[bot] commented 2 years ago

:white_check_mark: Confirmed by @engcom-Lima. Thank you for verifying the issue.
Issue Available: @engcom-Lima, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.

hostep commented 2 years ago

@engcom-Lima: thank you very much for testing!

Could you also try to drag in the product owner of this part of Magento in this discussion and ask their opinion? To make sure this is a valid request?

engcom-Lima commented 2 years ago

Hi @hostep

Thanks for your detailed information provided by you.

In order to involve product owner I will confirm with my internal team members. Then, I will update you further on this.

Thanks!!

engcom-Hotel commented 2 years ago

Hello @hostep,

We are putting this issue on hold to confirm the expected behavior with the PO.

Thanks

engcom-Lima commented 2 years ago

Mail has been sent to PO for his confirmation on the expected result. After his confirmation on the expected result we will proceed further.

Thanks

hostep commented 1 year ago

@engcom-Lima, @engcom-Hotel: this makes no sense, why did the issue got closed? Never even got feedback from the PO so I don't understand why this got closed for no good reason?

Update: I just noticed those PR in progress and done labels, so I'm going to guess this is already fixed internally? Are there already some commits you can link to? Great communication here (again) ... 😛

hostep commented 1 year ago

Hey @engcom-Lima: is there already some feedback from the PO about this? And if not, how long is it still going to take? Thanks!

tprocter-ldg commented 1 year ago

Hello, is there any further update on this issue or the PR that is in progress please?

Also, thank you @hostep for writing this very detailed description of my biggest headache :)

hostep commented 1 year ago

@engcom-Lima, @engcom-Hotel: is there already feedback from the PO? You said a mail was send to him/her about 8 months ago, I'm assuming it got forgotten, maybe send a reminder (or even better: let the PO answer in public here, it will be much easier to discuss the options that way) ...

engcom-Lima commented 1 year ago

Hi @hostep,

Thanks for your patience.

As per jira PO had provided feedback as "This issue will be consider as Feature Request and Tax expert input would be needed to handle these complex scenarios" .

Thanks

hostep commented 1 year ago

Thanks @engcom-Lima, am I correct in understanding that you guys will try to involve a tax expert? Or am I considered to find a tax expert myself?

engcom-Lima commented 1 year ago

Hi @crmccann ,

Need yours intervention here.

Thanks

hostep commented 1 year ago

Hey @crmccann: is there already an update around this? We keep running into clients of ours that run against this issue...

engcom-Lima commented 1 year ago

Hi @hostep,

Thanks for your patience!

The internal team has recommended to leverage dedicated tax module e.g. Avalara, Vertex etc. to cover tax calculations. Hope this helps.

Thanks

hostep commented 1 year ago

@engcom-Lima: I completely disagree. Magento has tax calculation support build in, so why not extend it to support more cases? There is a PR with a suggestion for a solution, maybe if you disagree that this is a good idea to enable for everybody, we could only enable it with a new configuration flag?

What do you think?

We've been using this PR as a patch on a couple of the shops we maintain for a few months in production and our clients are happy with the results.