Magento2: Wrong shipping tax calculation after discount

Created on 26 Feb 2019  路  31Comments  路  Source: magento/magento2

Preconditions (*)

  1. Project Magento 2.2.6 EE, also clean Magento 2.2.6 EE, no sample data (Magento Cloud)
  2. Tax class for products and shipping method with 22% rate
  3. Product price is configured to be with excluded tax, displayed with included tax in catalog
  4. Shipping price is configured to be with included tax, displayed with included tax in catalog
  5. Cart price rule discount -50% which applies also for shipping method
  6. Tax is configured to be calculated after discount
  7. Discount is configured to be applied on excluding tax prices
  8. In order prices are configured to be displayed with excluded tax

Steps to reproduce (*)

  1. Add product to cart, product price is $100 excluding tax, $122 including tax
  2. Select shipping method, shipping method price is $5 including tax, $4.1 excluding tax
  3. Place order
  4. Check order values in admin panel / table directly...

Expected result (*)

  1. I expected that following values should be in order:
    1.1. Product $100 exl. tax, $122 incl. tax
    1.2. Shipping and handling $4.1 incl. tax
    1.3. Discount -$52,05
    1.4. Tax $11.45 ($11 + $0.45)
    1.5. Grant total $63.5

Actual result (*)

  1. Unfortunately shipping tax is calculated from 100% shipping price instead of 50% of shipping price:
    1.1. Product $100 exl. tax, $122 incl. tax
    1.2. Shipping and handling $4.1 incl. tax
    1.3. Discount -$52,05
    1.4. Tax $11.53 - WTF?
    1.5. Grant total $63.95 ($50 + $11 + $2.05 + $0.9 - which seems to be "correct" in compare to above tax value, except fact that shipping tax is calculated from 100% instead of 50%)

It works fine when cart price discount does not apply on shipping price, or when applies but shipping price excludes tax.

Tax Clear Description Confirmed Format is valid Ready for Work P1 ready for dev Reproduced on 2.2.x Reproduced on 2.3.x S1

Most helpful comment

Generally things goes wrong in:
vendor/magento/module-tax/Model/Calculation/AbstractAggregateCalculator.php:49

For test purpose I have replaced:

//TODO: handle originalDiscountAmount
$taxableAmount = \max($rowTotalInclTax - $discountAmount, 0);
$rowTaxAfterDiscount = $this->calculationTool->calcTaxAmount(
    $taxableAmount,
    $rate,
    true,
    false
);
$rowTaxAfterDiscount = $this->roundAmount(
    $rowTaxAfterDiscount,
    $rate,
    true,
    self::KEY_REGULAR_DELTA_ROUNDING,
    $round,
    $item
);
// Set discount tax compensation
$discountTaxCompensationAmount = $rowTax - $rowTaxAfterDiscount;
$rowTax = $rowTaxAfterDiscount;

With following:

$taxableAmount = \max($rowTotal - $discountAmount, 0);
$discountTaxCompensationAmount = 0;
$rowTax = $taxableAmount * ($rate / 100);

Then result is as expected.

All 31 comments

Hi @pierzakp. Thank you for your report.
To help us process this issue please make sure that you provided the following information:

  • [ ] Summary of the issue
  • [ ] Information on your environment
  • [ ] Steps to reproduce
  • [ ] Expected and actual results

Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:

@magento-engcom-team give me 2.3-develop instance - upcoming 2.3.x release

For more details, please, review the Magento Contributor Assistant documentation.

@pierzakp do you confirm that you was able to reproduce the issue on vanilla Magento instance following steps to reproduce?

  • [ ] yes
  • [ ] no

Hi @engcom-backlog-nazar. 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:

  • [x] 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).
    DetailsIf the issue has a valid description, the label Issue: Format is valid will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid appears.
  • [x] 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description label to the issue by yourself.

  • [x] 3. Add Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • [x] 4. Verify that the issue is reproducible on 2.3-develop branch

    Details- Add the comment @magento-engcom-team give me 2.3-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.3-develop branch, please, add the label Reproduced on 2.3.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and _stop verification process here_!

  • [x] 5. Verify that the issue is reproducible on 2.2-develop branch.

    Details- Add the comment @magento-engcom-team give me 2.2-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.2-develop branch, please add the label Reproduced on 2.2.x

  • _Next steps are available in case you are a member of Community Maintainers._

  • [x] 6. Add label Issue: Confirmed once verification is complete.

  • [x] 7. Make sure that automatic system confirms that report has been added to the backlog.

Hi, I have created vanilla Magento 2.2.6 EE instance on Magento Cloud and after configuring all preconditions I am able to reproduce this issue.

Hi @pierzakp can you reproduce this on CE version ?

Please share 2.2.6 CE instance.

@magento-engcom-team give me 2.2.6 instance

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

Hi @engcom-backlog-nazar, here is your Magento instance.
Admin access: https://i-21456-2-2-6.instances.magento-community.engineering/admin
Login: admin Password: 123123q
Instance will be terminated in up to 3 hours.

@magento-engcom-team give me 2.3-develop instance

Hi @dipti2jcommerce. Thank you for your request. I'm working on Magento 2.3-develop instance for you

Hi @dipti2jcommerce, here is your Magento instance.
Admin access: https://i-21456-2-3-develop.instances.magento-community.engineering/admin
Login: admin Password: 123123q
Instance will be terminated in up to 3 hours.

Thank you for sharing the instance. Issue has been reproduced with the same wrong values as output in order.

:white_check_mark: Confirmed by @engcom-backlog-nazar
Thank you for verifying the issue! :+1: Your confirmation will help us to acknowledge and process this report.

:white_check_mark: Confirmed by @engcom-backlog-nazar
Thank you for verifying the issue! :+1: Your confirmation will help us to acknowledge and process this report.

:white_check_mark: Confirmed by @engcom-backlog-nazar
Thank you for verifying the issue. Based on the provided information internal tickets MAGETWO-98435, MAGETWO-98436 were created

Issue Available: @engcom-backlog-nazar, _You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself._

Generally things goes wrong in:
vendor/magento/module-tax/Model/Calculation/AbstractAggregateCalculator.php:49

For test purpose I have replaced:

//TODO: handle originalDiscountAmount
$taxableAmount = \max($rowTotalInclTax - $discountAmount, 0);
$rowTaxAfterDiscount = $this->calculationTool->calcTaxAmount(
    $taxableAmount,
    $rate,
    true,
    false
);
$rowTaxAfterDiscount = $this->roundAmount(
    $rowTaxAfterDiscount,
    $rate,
    true,
    self::KEY_REGULAR_DELTA_ROUNDING,
    $round,
    $item
);
// Set discount tax compensation
$discountTaxCompensationAmount = $rowTax - $rowTaxAfterDiscount;
$rowTax = $rowTaxAfterDiscount;

With following:

$taxableAmount = \max($rowTotal - $discountAmount, 0);
$discountTaxCompensationAmount = 0;
$rowTax = $taxableAmount * ($rate / 100);

Then result is as expected.

@magento-engcom-team give me 2.1.16 instance

Hi @ryandiamond23. Thank you for your request.
Unfortunately, I can only deploy instances for 2.2 and 2.3 release lines

  • @magento-engcom-team give me 2.2-develop instance

Hi @amol2jcommerce. Thank you for your request. I'm working on Magento 2.2-develop instance for you

Hi @amol2jcommerce, here is your Magento instance.
Admin access: https://i-21456-2-2-develop.instances.magento-community.engineering/admin
Login: admin Password: 123123q
Instance will be terminated in up to 3 hours.

  • @magento-engcom-team give me 2.2.7 instance

Hi @maheshWebkul721. Thank you for your request. I'm working on Magento 2.2.7 instance for you

Hi @maheshWebkul721, here is your Magento instance.
Admin access: https://i-21456-2-2-7.instances.magento-community.engineering/admin
Login: admin Password: 123123q
Instance will be terminated in up to 3 hours.

What is status of the issue?

To make follow up to everyone I received following responses from Magento EE support:

This behavior was implemented intentionally according to our design. When taxes are included for shipping and there is a shipping discount then Magento calculates discounted tax compensation in order to charge taxes for whole shipping amount. I understand this was done in order to comply with tax regulations.

As my colleague said, our core development team has reported that this behavior is as designed.
My understanding is there are plans to revisit this implementation in future releases, however it would require a great deal of architecture work. We do not have an ETA.

Our Core developers have said this is as designed and are not going to fix this for M2.2x or 2.3 at this time. The design will be revisited for future releases.
The github post will be updated with those results, but it hasn't been done yet.

Seems that we need to find workaround on our own.

Thanks for the update @pierzakp :).

When an administrator chooses "apply to shipping", the discount should be fully applied to the shipping. Discounted shipping does not mean, 'discounted, except for tax'. If perhaps it does for some countries, this behaviour should at be configurable. This is a disappointing response from Magento!

@pierzakp we are in communication with Magento EE for the issue but We don't get the information from them, still waiting for a solution. Could you share more detail about what you talked to them exactly?

To elaborate on the issue I'm having, which is similar to @tnsezer's in #22480

I have a cart price rule that is has an action of 100% discount and applies to shipping. All tax calculation rules are set to be 'including tax' and tax is set to be calculated after discount. Everything gets discounted, however I'm left with the tax on the shipping (which is 拢5, so 83p).

Turns out the issue I was having may be unrelated. We have a weird setup whereby simple products are in categories that their configurable is not. This messed up cart price rules based on categories.

We are experiencing the same issue. Shipping tax is not discounted when using a discount code. Have anyone solved this one yet?

Was this page helpful?
0 / 5 - 0 ratings