Open riversy opened 2 years ago
Hi @riversy. 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.
Join Magento Community Engineering Slack and ask your questions in #github channel.
:warning: According to the Magento Contribution requirements, all issues must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting.
: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
@magento give me 2.4-develop instance
Hi @riversy. Thank you for your request. I'm working on Magento instance for you.
Hi @riversy, here is your Magento Instance: https://9202dc350ac6ddc7308a4c44cefb2813.instances.magento-community.engineering Admin access: https://9202dc350ac6ddc7308a4c44cefb2813.instances.magento-community.engineering/admin_bc93 Login: aca737d3 Password: 8835845b11f1
Hi @engcom-November. 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:
[ ] 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).Details
If 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.
[ ] 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.
[ ] 3. Add Component: XXXXX
label(s) to the ticket, indicating the components it may be related to.
[ ] 4. Verify that the issue is reproducible on 2.4-develop
branchDetails
- Add the comment @magento give me 2.4-develop instance
to deploy test instance on Magento infrastructure.
- If the issue is reproducible on 2.4-develop
branch, please, add the label Reproduced on 2.4.x
.
- If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!
[ ] 5. Add label Issue: Confirmed
once verification is complete.
[ ] 6. Make sure that automatic system confirms that report has been added to the backlog.
Trying to replicate the issue on the https://9202dc350ac6ddc7308a4c44cefb2813.instances.magento-community.engineering/ instance.
(1) Applied the following settings to the instance:
(2) Applied tax rule
(3) Created necessary Cart Price Rule
(4) Created a test product
Cart Subtotal Incl. Tax to be $119.00 because Cart Subtotal Excl. Tax ($100.00) + Tax ($19.00) = $119.00
Cart Subtotal Incl. Tax is $120.00 It can be treated as an incorrect value.
Hi @riversy , Thank you for reporting and collaboration. Verified this on Magento 2.4-develop instance however this behavior is there due to incorrect Tax Configuration. As per Magento docs for tax configuration - Catalog Price: Excluding tax, Display settings: "Including and Excluding tax" & Tax calculation method based on "Total" , can result in rounding errors because the tax calculation is rounded, the amount that appears in the cart might differ from the amount that a customer expects to pay and warning message is displayed to the user in Admin. Please refer the document for valid combinations when configuring tax calculation settings. Thank you.
Hi @engcom-November, Thank you for your clarification of this problem and the provided documentation reference.
According to the document (Magento Docs), the following combination of the settings shouldn't lead to any warnings and confusion, as I understand:
Trying to retest the issue on the https://9202dc350ac6ddc7308a4c44cefb2813.instances.magento-community.engineering/ instance using a combination of settings above:
Cart Subtotal Incl. Tax to be $119.00 because Cart Subtotal Excl. Tax ($100.00) + Tax ($19.00) = $119.00
Cart Subtotal Incl. Tax is $120.00 It can be treated as an incorrect value.
The problem here is not only related to the displayed subtotal on the Checkout page, which is also confusing.
The incorrect values row_total_incl_tax
, base_row_total_incl_tax
, price_incl_tax
, base_price_incl_tax
are stored in the table quote_item
as a result of mentioned code. Some payment modules later can use this information to initiate a payment on the gateway, leading to issues with whose payment methods.
There's one only example: vendor/klarna/module-core/Model/Checkout/Orderline/Items.php:161
As for rounding errors, there's a special values discount_tax_compensation_amount
and base_discount_tax_compensation_amount
are presented in the table quote_item
. It isn't used in the \Magento\Tax\Model\Calculation\AbstractAggregateCalculator::calculateWithTaxNotInPrice method, but as I understand the logic it can be.
So my main question here is an incorrect value of Cart Subtotal Incl. Tax is a part of a plan and shouldn't be fixed, or is this an issue worth fixing to make a whole solution more stable?
If Magento is going to fix it, I will be happy to help with a resolution. Thank you!
@magento give me 2.4-develop instance
Hi @engcom-November. Thank you for your request. I'm working on Magento instance for you.
Hi @engcom-November, here is your Magento Instance: https://9202dc350ac6ddc7308a4c44cefb2813.instances.magento-community.engineering Admin access: https://9202dc350ac6ddc7308a4c44cefb2813.instances.magento-community.engineering/admin_7b6a Login: 42f35b80 Password: e50027f32f0b
Verified the issue again on Magento 2.4-develop branch with above mentioned configuration and the issue is reproducible. Cart Subtotal Incl. Tax to be $119.00 but displayed $120 Also as per Magento docs, for tax combination: Catalog prices: excluding tax, Tax calculation method: "Row Total" & Display settings set to - "Including and Excluding Tax", there should not be any warning message on admin but Warning message is getting displayed on admin UI
:white_check_mark: Jira issue https://jira.corp.magento.com/browse/AC-2735 is successfully created for this GitHub issue.
:white_check_mark: Confirmed by @engcom-November. Thank you for verifying the issue.
Issue Available: @engcom-November, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.
@riversy I faced similar issue, noticed that the column row_total_incl_tax
has different value.
Correct value would be row_total - discount_amount + tax_amount
Did you manage to find a workaround?
@riversy I faced similar issue, noticed that the column
row_total_incl_tax
has different value. Correct value would berow_total - discount_amount + tax_amount
Did you manage to find a workaround?
Hi, @ilnytskyi
The following patch fixed the problem on my project:
--- a/vendor/magento/module-tax/Model/Calculation/AbstractAggregateCalculator.php
+++ b/vendor/magento/module-tax/Model/Calculation/AbstractAggregateCalculator.php (date 1648194054598)
@@ -154,7 +154,7 @@
}
$rowTax = array_sum($rowTaxes);
$rowTaxBeforeDiscount = array_sum($rowTaxesBeforeDiscount);
- $rowTotalInclTax = $rowTotal + $rowTaxBeforeDiscount;
+ $rowTotalInclTax = $rowTotal + $rowTax;
$priceInclTax = $rowTotalInclTax / $quantity;
if ($round) {
I hope it will help you as well.
@engcom-November since the issue is reproducible and confirmed. Could you check falling tests in https://github.com/magento/magento2/pull/36141 this run https://public-results-storage-prod.magento-testing-service.engineering/reports/magento/magento2/pull/36141/5ec82fdcae5038efdcf4f5a02e903286/Integration/console-error-logs.html
We have config like this:
The fix suggested by @riversy resolves the problem in our case as well.
But now I have doubts if values for row_total_incl_tax
in core tests are correct.
cc @maghamed @sidolov
Maybe you could help up to figure out what is the reason that the column row_total_incl_tax
is always calculated as if tax applied before discount? So for order with discount and tax appliance after the discount row_total_incl_tax != (row_total + tax_amount - discount_amount)
can be clearly seen with this SQL
select name,
qty,
price,
discount_percent,
tax_percent,
round(((price * qty) * (discount_percent / 100)), 4) as calculated_discount_amount,
discount_amount,
round((row_total - discount_amount) * (tax_percent / 100), 2) as calculated_tax_amount_after_discount,
round((row_total) * (tax_percent / 100), 2) as calculated_tax_amount_before_discount,
tax_amount,
row_total,
round((price * qty), 2) as calculated_row_total,
price_incl_tax,
round((row_total + tax_amount), 2) as calculated_row_total_incl_tax_after_discount,
round((row_total + round((row_total) * (tax_percent / 100), 2)), 2) as calculated_row_total_incl_tax_before_discount,
row_total_incl_tax,
(row_total + tax_amount) as row_with_tax,
(row_total_incl_tax - discount_amount) as row_without_discount, #current
(row_total - discount_amount) as final_no_tax,
(row_total + tax_amount - discount_amount) as final_with_tax #correct
from quote_item
where quote_id = {your quote id};
Preconditions (*)
Steps to reproduce (*)
Expected result (*)
Totals Cart Subtotal Excl. Tax: $100.00 Cart Subtotal Incl. Tax: $119.00 Discount (fix5): -$5.00 Shipping Flat Rate - Fixed: $5.00 Tax: $19.00 Order Total: $119.00
Quote Item Data
Actual result (*)
Totals Cart Subtotal Excl. Tax: $100.00 Cart Subtotal Incl. Tax: $120.00 Discount (fix5): -$5.00 Shipping Flat Rate - Fixed: $5.00 Tax: $19.00 Order Total: $119.00
Quote Item Data
Cart Subtotal Incl. Tax is not correlating to the subtotal and final tax.
Reference
According to the following documentation, the actual tax amount is expected to be added to the subtotal instead of the original: https://docs.magento.com/user-guide/configuration/sales/tax.html
The place to fix the issue in the source code: https://github.com/magento/magento2/blob/0763e060d1e491385280c82ac9f951b1a8b1fcfe/app/code/Magento/Tax/Model/Calculation/AbstractAggregateCalculator.php#L157
The following code:
Should be:
Please provide Severity assessment for the Issue as Reporter. This information will help during Confirmation and Issue triage processes.