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.5k stars 9.31k forks source link

Exception during creation of Credit Memo when tax and discount applies to shipping price #19429

Closed datasolution75 closed 4 years ago

datasolution75 commented 5 years ago

Preconditions (*)

  1. Magento 2 2.2.6

Steps to reproduce (*)

  1. Make an Order with shipping cost and VAT on the shipping. (in my exemple 7.9€ with a 20% VAT rate)
  2. Use a discount fixed on cart with an amount that can apply to shipping also (in my exemple 5€)

image

  1. Invoice and then create a credit memo from the invoice.

Expected result (*)

  1. The credit memo page appear

Actual result (*)

  1. Exception Maximum shipping amount allowed to refund is: 7.89

{"0":"Maximum shipping amount allowed to refund is: 7.89","1":"

0 HOME/vendor/magento/module-sales/Model/Order/Creditmemo.php(347): Magento\Sales\Model\Order\Creditmemo\Total\Shipping->collect(Object(Magento\Sales\Model\Order\Creditmemo\Interceptor))

1 HOME/vendor/magento/module-sales/Model/Order/CreditmemoFactory.php(132): Magento\Sales\Model\Order\Creditmemo->collectTotals()

2 HOME/vendor/magento/module-sales/Controller/Adminhtml/Order/CreditmemoLoader.php(209): Magento\Sales\Model\Order\CreditmemoFactory->createByInvoice(Object(Magento\Sales\Model\Order\Invoice), Array)

3 HOME/vendor/magento/module-sales/Controller/Adminhtml/Order/Creditmemo/NewAction.php(63): Magento\Sales\Controller\Adminhtml\Order\CreditmemoLoader->load()

4 HOME/vendor/magento/framework/App/Action/Action.php(107): Magento\Sales\Controller\Adminhtml\Order\Creditmemo\ewAction->execute()

5 HOME/vendor/magento/module-backend/App/AbstractAction.php(235): Magento\Framework\App\Action\Action->dispatch(Object(Magento\Framework\App\Request\Http))

6 HOME/vendor/magento/framework/Interception/Interceptor.php(58): Magento\Backend\App\AbstractAction->dispatch(Object(Magento\Framework\App\Request\Http))

7 HOME/vendor/magento/framework/Interception/Interceptor.php(138): Magento\Sales\Controller\Adminhtml\Order\Creditmemo\ewAction\Interceptor->___callParent('dispatch', Array)

8 HOME/vendor/magento/module-backend/App/Action/Plugin/Authentication.php(143): Magento\Sales\Controller\Adminhtml\Order\Creditmemo\ewAction\Interceptor->Magento\Framework\Interception{closure}(Object(Magento\Framework\App\Request\Http))

9 HOME/vendor/magento/framework/Interception/Interceptor.php(135): Magento\Backend\App\Action\Plugin\Authentication->aroundDispatch(Object(Magento\Sales\Controller\Adminhtml\Order\Creditmemo\ewAction\Interceptor), Object(Closure), Object(Magento\Framework\App\Request\Http))

10 HOME/vendor/magento/framework/Interception/Interceptor.php(153): Magento\Sales\Controller\Adminhtml\Order\Creditmemo\ewAction\Interceptor->Magento\Framework\Interception{closure}(Object(Magento\Framework\App\Request\Http))

11 HOME/generated/code/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/NewAction/Interceptor.php(26): Magento\Sales\Controller\Adminhtml\Order\Creditmemo\ewAction\Interceptor->___callPlugins('dispatch', Array, NULL)

12 HOME/vendor/magento/framework/App/FrontController.php(55): Magento\Sales\Controller\Adminhtml\Order\Creditmemo\ewAction\Interceptor->dispatch(Object(Magento\Framework\App\Request\Http))

13 HOME/vendor/magento/framework/Interception/Interceptor.php(58): Magento\Framework\App\FrontController->dispatch(Object(Magento\Framework\App\Request\Http))

14 HOME/vendor/magento/framework/Interception/Interceptor.php(138): Magento\Framework\App\FrontController\Interceptor->___callParent('dispatch', Array)

15 HOME/vendor/magento/framework/Interception/Interceptor.php(153): Magento\Framework\App\FrontController\Interceptor->Magento\Framework\Interception{closure}(Object(Magento\Framework\App\Request\Http))

16 HOME/generated/code/Magento/Framework/App/FrontController/Interceptor.php(26): Magento\Framework\App\FrontController\Interceptor->___callPlugins('dispatch', Array, Array)

17 HOME/vendor/magento/framework/App/Http.php(135): Magento\Framework\App\FrontController\Interceptor->dispatch(Object(Magento\Framework\App\Request\Http))

18 HOME/vendor/magento/framework/App/Bootstrap.php(257): Magento\Framework\App\Http->launch()

19 HOME/index.php(39): Magento\Framework\App\Bootstrap->run(Object(Magento\Framework\App\Http\Interceptor))

20 {main}","url":"/admin/sales/order_creditmemo/new/key/89b8c3c6e96cdcc5aa7981498fafe687026e77e2c9f20204bc5a2c723c4da936/order_id/112/invoice_id/106/","script_name":"/index.php"}

The "collect" function of Magento\Sales\Model\Order\Creditmemo\Total\Shipping should add the ShippingDiscountTaxCompensationAmount in the allowedTaxAmount variable.

Code is now :

$allowedTaxAmount = $order->getShippingTaxAmount() - $order->getShippingTaxRefunded();
$baseAllowedTaxAmount = $order->getBaseShippingTaxAmount() - $order->getBaseShippingTaxRefunded();

It should be :

$allowedTaxAmount = $order->getShippingTaxAmount() + $order->getShippingDiscountTaxCompensationAmount() - $order->getShippingTaxRefunded();
$baseAllowedTaxAmount = $order->getBaseShippingTaxAmount() + $order->getBaseShippingDiscountTaxCompensationAmnt() - $order->getBaseShippingTaxRefunded();
magento-engcom-team commented 5 years ago

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

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 $VERSION instance

where $VERSION is version tags (starting from 2.2.0+) or develop branches (for example: 2.3-develop). For more details, please, review the Magento Contributor Assistant documentation.

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

magento-engcom-team commented 5 years ago

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

orlangur commented 5 years ago

@datasolution75 for suggesting code changes it is better to create a PR 😉

datasolution75 commented 5 years ago

Sorry i'm new to this, what is a PR ? And where can i create one ?

ghost commented 5 years ago

Hi @datasolution75. Thanks for the report. I was not able to reproduce this issue by following the steps you provided. My Grand Total (Excl tax.) is 41,94. I got this result: item

datasolution75 commented 5 years ago

Hi, i see that you don't have exacty the same prices, and i think the shippings you set are not taxed.

All the products and the shipping method have a 20% tax rate. The prices are all including tax in the BO. Here is the Tax config :

image

image

Firt product price including tax is : 19.95 Second is 26.90 Shipping is 7.90.

All have taxes.

Here is the invoice i have in the database :

image

image

orlangur commented 5 years ago

@datasolution75 please check https://github.com/magento/magento2/blob/2.3-develop/.github/CONTRIBUTING.md on how to propose some changes.

magento-engcom-team commented 5 years ago

@engcom-backlog-andrii Thank you for verifying the issue. Based on the provided information internal tickets MAGETWO-96738 were created

milindsingh commented 5 years ago

@datasolution75 @orlangur can I create a PR with suggested changes ?

datasolution75 commented 5 years ago

I don't have any objection on my side.

vikalps4 commented 5 years ago

I am working on this at #dmcdindia1

mekedron commented 4 years ago

@magento-engcom-team I'm pretty sure the field base_shipping_discount_tax_compensation_amnt will never have a value instead of null inside the quote_address table.

At first, take a look at this WONDERFUL phpdoc: \Magento\Quote\Model\Quote\Address at line 84-85. setBaseShippingDiscountTaxCompensationAmnt

Please, follow up this trace: \Magento\Quote\Model\Quote\TotalsCollector::collect - line 148 \Magento\Quote\Model\Quote\TotalsCollector::collectAddressTotals - line 274 \Magento\Tax\Model\Sales\Total\Quote\Tax::collect - line 126 \Magento\Tax\Model\Sales\Total\Quote\Shipping::collect - line 56 \Magento\Tax\Model\Sales\Total\Quote\CommonTaxCollector::processShippingTaxInfo - line 743 \Magento\Quote\Model\Quote\Address\Total::setBaseTotalAmount - pay your attention to '_amont' literal. \Magento\Quote\Model\Quote\TotalsCollector::collectAddressTotals - line 286

How should this field convert from base_shipping_discount_tax_compensation_amount into base_shipping_discount_tax_compensation_amnt?

m2-assistant[bot] commented 4 years ago

Hi @engcom-Charlie. Thank you for working on this issue. Looks like this issue is already verified and confirmed. But if you want to validate it one more time, please, go though the following instruction:


engcom-Charlie commented 4 years ago

Hello @datasolution75

I am not able to reproduce this issue on a fresh Magento 2.4-develop.

Testing scenario:

  1. Make an Order with shipping cost and VAT on the shipping. (in my exemple 5$ with a 20% VAT rate)
  2. Use a discount fixed on cart with an amount that can apply to shipping also (in my example 5$)

Result: Credit memo has been created image

So i have to close this issue as not reproducible.

Please feel free to comment, reopen or create new ticket according to the Issue reporting guidelines if you are still facing this issue on the latest Magento 2.4-develop branch.

Thank you for collaboration.

mekedron commented 4 years ago

@engcom-Charlie please check the comment I've left above Is it related to this issue or I need to create another one?

engcom-Charlie commented 4 years ago

Hello @durexlovesex, please create a new issue for it. Thanks for contributing!