magento2: Exception during creation of Credit Memo when tax and discount applies to shipping price
Preconditions (*)
- Magento 2 2.2.6
Steps to reproduce (*)
- Make an Order with shipping cost and VAT on the shipping. (in my exemple 7.9€ with a 20% VAT rate)
- Use a discount fixed on cart with an amount that can apply to shipping also (in my exemple 5€)

- Invoice and then create a credit memo from the invoice.
Expected result (*)
- The credit memo page appear
Actual result (*)
- 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();
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 16 (8 by maintainers)
I don’t have any objection on my side.