-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
Prevent invoice cancelation multiple times #11073
Conversation
The changes look good to me. Would you be interested in adding a test that covers your scenario? |
@fooman In this case, I don't know how cover this scenario with tests. (I'm not an expert with PHPUnit 😔 ), in all cases BTW I saw that InvoiceService.php not have a cancel method like OrderService.php. @vkublytskyi you think it might be interesting add this function for webapi? (maybe in other PR) |
@osrecio Yes, it would be nice to have Web API for full invoice management and additional PR with such changes would be a great contribution. But be aware of specific backward compatibility policy that affects Regarding test coverage. I believe this fix is a good subject to start. Such changes can be covered with unit tests which are located in $this->eventManagerMock->expects($this->never())->method('dispatch')->with('sales_order_invoice_cancel'); As well as we can ensure that for canceled order payment cancellation is not triggered: $this->paymentMock->expects($this->never())->method('cancelInvoice'); For more safety order items collection may be mocked tu ensure that In general this implementation consistent with Order implementation but it cannot be considered as the best approach:
As a conclusion, I would like to ask you, in addition to the implemented solution, discover and fix why invoice cancelation is invoked twice. |
I got it, I will add new commits with test coverage. Thanks! About your question: only can cancel invoice when you're making programmatically things. Actually this PR not is a fix, would be a improvement. About API implementation I will work with Backward compatibility like we are made in PR: #9560 😄 |
Added test, I hope are ok @vkublytskyi :) |
@vkublytskyi here is a backport: #11261 |
Add Guard Clause to check if invoice has been canceled previously
Description
The invoice gets canceled twice, so order amounts are also being adjusted twice.
With same approach of
Magento\Sales\Model\Order::cancel
added guard clause to avoid recancel order.Fixed Issues (if relevant)
Manual testing scenarios
Contribution checklist