By default, Odoo will not allow you to cancel an invoice once it has been validated. Since accounting entries have been recorded, we are not able to delete or update them. In such cases, you can create a refund invoice and reconcile them so that accounts are reflected properly. However, in some case canceling an invoice is necessary.
For canceling invoice we should install the account cancel module from apps. After installing the app it will allow you to configure your journal with the possibility to cancel entries, a new checkbox will be visible in the journal configuration. If the field not visible, then activate developer mode/Technical Feature.
If you try to cancel a posted invoice system generates a warning message called you can’t cancel an invoice, which is before canceling the invoice you should check whether the related journal entry is unposted. If it is posted then you should cancel the journal. Then, you will be able to cancel the invoice. Now the state/status is changed to cancel.
And as soon as the invoice is canceled you can set it back to draft. You won't be able to delete it permanently because the invoice number stays reserved for that invoice.
If there are existing Payments applied to a certain Invoice, you will have to Un-reconciled them, before being able to cancel it.
Go for the journal entry and click on the start button on the top of the form.
Then you will get a new window with journal items.
Just select them and click on more button on the top of the form. Then click on the Unreconcile Entries, then you will get a wizard.
Once you reconcile the payment, you can cancel the entries (journal and invoice).