magento2: Wrong tax calculation after applying discount coupon in Magento Open Source v2.3.4
Preconditions (*)
- Fresh Magento 2.3.4, 2.4-develop (Open Source) with sample data
Steps to reproduce (*)
- Stores->Configuration-> Sales->Tax : Set all values including tax and Apply Customer Tax After Discount (http://prnt.sc/tyizqn)
- Stores->Tax Zones and Rates: Set VAT of 15% (http://prnt.sc/tyizuc)
- Stores->Tax Rules: Set VAT of 15% (http://prnt.sc/tyizwl)
- Marketing-> Cart Price Rule: Set 10% off on “Percent of product price discount” (http://prnt.sc/tyizzo)
Expected result (*)
If any taxable item’s (https://prnt.sc/tyjm6f) selling price 100 and tax 15% (13.04) included, then:
- Base price without tax should be (100 - 13.04) = 86.96
- As 10% Discount from that Base price should be (86.96 * 10%) = 8.70
- After Discount Base price should be (86.96 - 8.70) = 78.26
- 15% Tax on New discounted base price (78.26 * 15%) = 11.74
- So Total price after discount with tax (78.26 + 11.74) = 90
Actual result (*)
But on Magento after discount, it calculates wrong Tax and total
- it shows Base price without tax 86.96 which is ok
- it shows As 10% Discount from that Base price 8.70 which is also ok
- but the Tax it shows 11.91 which is wrong
- and it shows total price after discount with tax 91.30 which is also wrong http://prnt.sc/tyj01h Can anybody explain why it’s working this way and what is the logic behind it?
Temporary solution
If we follow this fix https://github.com/magento/magento2/issues/21456#issuecomment-467475342
Fix on file vendor/magento/module-tax/Model/Calculation/AbstractAggregateCalculator.php:49
Replace:
//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 the following:
$taxableAmount = max($rowTotal - $discountAmount, 0);
$discountTaxCompensationAmount = 0;
$rowTax = $taxableAmount * ($rate / 100);
In our case, it works as expected (http://prnt.sc/tyj04g). Thanks to @pierzakp Is it reliable or safe enough to apply on the production site? Is there any alternative way or settings to fix that tax issue?
Note: After applying this fix it wasn’t working as expected, then find out its need clear cache properly both for Magento + Browser + 3rd party (if any).
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 20 (5 by maintainers)
Do we have any patch for this?