Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Magento loading the wrong Tax info on admin Invoice and Creditmemo page #31197

Closed
5 tasks
srenon opened this issue Dec 8, 2020 · 10 comments · Fixed by #31198
Closed
5 tasks

Magento loading the wrong Tax info on admin Invoice and Creditmemo page #31197

srenon opened this issue Dec 8, 2020 · 10 comments · Fixed by #31198
Assignees
Labels
Component: Tax Fixed in 2.4.x The issue has been fixed in 2.4-develop branch Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Priority: P2 A defect with this priority could have functionality issues which are not to expectations. Progress: done Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch Severity: S3 Affects non-critical data or functionality and does not force users to employ a workaround.

Comments

@srenon
Copy link
Member

srenon commented Dec 8, 2020

After upgrading from Magento 2.3.3 to 2.4.1, we are having random broken invoice pages. After further debugging, this seems to be core issue.

Preconditions (*)

  1. Magento 2.4-develop

Steps to reproduce (*)

  1. Install clear Magento!
  2. Set-up tax rule for CA region.
  3. Go to Store->Configuration->Sales->Tax->Orders, Invoices, Credit Memos Display Settings and set
    Include Tax In Order Total -> Yes;
    Display Full Tax Summary -> Yes;
  4. Create a simple product.
  5. Place order with this product chose State/Province -> California.
  6. Place one more order and choose any State/Province except for California (to avoid taxes).
  7. Open the second order on the admin panel and create an invoice for it.
  8. Open the second order again, go to the Invoices tab, and open the invoice.

Expected result (*)

  1. Invoice page loaded successfully

Actual result (*)

  1. Invoice page broken
    image

Additional information

file

https://github.com/magento/magento2/blob/2.4-develop/app/code/Magento/Sales/Block/Adminhtml/Order/Totals/Tax.php#L98

app/code/Magento/Tax/Model/ResourceModel/Sales/Order/Tax/Collection.php

image

In the image above order->getId() is actually an instance of Magento\Sales\Model\Order\Creditmemo or Magento\Sales\Model\Order\Invoice therefore getId() will return the invoice or credit memo id instead of the order id which will send the wrong information to the SQL below.

SELECT 
  `main_table`.* 
FROM 
  `sales_order_tax` AS `main_table` 
WHERE 
  (main_table.order_id = 1) 
ORDER BY 
  `process` ASC

Please provide Severity assessment for the Issue as Reporter. This information will help during Confirmation and Issue triage processes.

  • Severity: S0 - Affects critical data or functionality and leaves users without workaround.
  • Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.
  • Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.
  • Severity: S3 - Affects non-critical data or functionality and does not force users to employ a workaround.
  • Severity: S4 - Affects aesthetics, professional look and feel, “quality” or “usability”.
@m2-assistant
Copy link

m2-assistant bot commented Dec 8, 2020

Hi @srenon. 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 give me 2.4-develop instance - upcoming 2.4.x release

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

Please, add a comment to assign the issue: @magento I am working on this


⚠️ According to the Magento Contribution requirements, all issues must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting.

🕙 You can find the schedule on the Magento Community Calendar page.

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

🎥 You can find the recording of the previous Community Contributions Triage on the Magento Youtube Channel

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

@m2-community-project m2-community-project bot added Priority: P2 A defect with this priority could have functionality issues which are not to expectations. Severity: S3 Affects non-critical data or functionality and does not force users to employ a workaround. labels Dec 8, 2020
@chequille
Copy link

Hi Guys, do have the same problem. The Page showing the invoice as described above breaks.
It happens if correct tax is 0.00 f.e. if a coupon code was entered and nothing has to be paid.
It happens as well if a product without tax is the only product in the order.
So as this worked everything in 2.3.5 I hope you will fix this as fast as possible.
Everybody is recommending updating to 2.4.1 but new bugs prevents us all from doing it.
Looking forward to hearing from you.
Best regards,
Chequille

@srenon
Copy link
Member Author

srenon commented Dec 11, 2020

@chequille You could use a composer patch to temporarily fix this issue until a new version is released. See https://devdocs.magento.com/guides/v2.4/comp-mgr/patching/composer.html

filename: {root}/composer.json

"magento/module-sales": {
      "GITHUB:Magento2 - 31197 - Loading wrong order tax info":"patches/composer/magento-github-issue-31197.diff"
}

filename: {root}/patches/composer/magento-github-issue-31197.diff

Index: vendor/magento/module-sales/Block/Adminhtml/Order/Totals/Tax.php
===================================================================
diff --git a/vendor/magento/module-sales/Block/Adminhtml/Order/Totals/Tax.php b/vendor/magento/module-sales/Block/Adminhtml/Order/Totals/Tax.php
--- a/vendor/magento/module-sales/Block/Adminhtml/Order/Totals/Tax.php	(date 1607408606000)
+++ b/vendor/magento/module-sales/Block/Adminhtml/Order/Totals/Tax.php	(date 1607408606000)
@@ -95,7 +95,7 @@

         $taxClassAmount = $this->_taxHelper->getCalculatedTaxes($source);
         if (empty($taxClassAmount)) {
-            $rates = $this->_taxOrderFactory->create()->getCollection()->loadByOrder($source)->toArray();
+            $rates = $this->_taxOrderFactory->create()->getCollection()->loadByOrder($this->getOrder())->toArray();
         $taxClassAmount = $this->_taxCalculation->reproduceProcess($rates['items']);
         }

@chequille
Copy link

chequille commented Dec 12, 2020

@srenon
Thanks for this. I made the changes manually. It is only one line to change :)
After chaning the page break when showing an invoice with zero tax did not happen again. So far so good.
But unfortunately, I found another bug regarding tax. It seems in 2.4.1 there are a lot of changes which did not solve problems but made new problems. I will show you what I found:

  1. Tax calculation is set in my system to "afterdiscount"
  2. I have a coupon for a special product at 49,-€ which reduces this amount 100% and no delivery costs are applied. Therefore, customer does not have to pay something. The invoice total and tax must be ZERO
  3. This working perfectly in my 2.3.5 store which is online

No, I show ou with some screenshots what happens in 2.4.1
I placed an order with a coupon code and the product I mentioned above.
Bank transfer payment, so invocie is not generated.
In the backend the order shows the following totals and tx amount which are correct, all zero !!!!
grafik

So far so good, but now I generate the invoice for this order and after doing so, we suddenly have a non zero total. Tax still says zero, but total is increased with 16% of 49,-€, definetely wrong!!!!!!! (16% is our current tax rate)
grafik

This is a very strange bug and I hope this will be solved very soon, as well with some patches, because waiting for the next release is probably to long.

Looking forward to hearing from you.

Best regards,
Chequille

@srenon
Copy link
Member Author

srenon commented Dec 14, 2020

@chequille .... did you open a new ticket for the issue mention above (I have not fully reviewed but it seems to be a different issue)?

@chequille
Copy link

@srenon
No, I did not, because I thought this is also related to the wrong tax calculation as it is as well in this ticket.
On the other hand, as it happens when generating the invoice it is another issue.

Could you transfer it to a new one?

@srenon
Copy link
Member Author

srenon commented Dec 21, 2020

@chequille ... I only have limited access to this repo... so please go ahead a create a new ticket.

@chequille
Copy link

@srenon
Ok, did it, see #31366

@engcom-Charlie engcom-Charlie added Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch and removed Progress: PR in progress labels Dec 22, 2020
@engcom-Charlie engcom-Charlie added Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed and removed Issue: ready for confirmation labels Dec 22, 2020
@magento-engcom-team
Copy link
Contributor

✅ Confirmed by @engcom-Charlie
Thank you for verifying the issue. Based on the provided information internal tickets MC-40113 were created

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

@magento-engcom-team magento-engcom-team added the Fixed in 2.4.x The issue has been fixed in 2.4-develop branch label Jan 6, 2021
@magento-engcom-team
Copy link
Contributor

Hi @srenon. Thank you for your report.
The issue has been fixed in #31198 by @srenon in 2.4-develop branch
Related commit(s):

The fix will be available with the upcoming 2.4.3 release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Tax Fixed in 2.4.x The issue has been fixed in 2.4-develop branch Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Priority: P2 A defect with this priority could have functionality issues which are not to expectations. Progress: done Reproduced on 2.4.x The issue has been reproduced on latest 2.4-develop branch Severity: S3 Affects non-critical data or functionality and does not force users to employ a workaround.
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

5 participants