Skip to Content
Menu
This question has been flagged
4 Replies
14654 Views

How can I remove/delete the invoice that was posted with the wrong invoice number in odoo13?

Avatar
Discard

Thinking out of the box and making data corrupted is good way that you need to implement in your business ? Nice...

I found a solution that works for me.

i set the account move to draft then i create an action server with the python code below 

records.with_context(force_delete=True).unlink()

Yes, You cannot delete a posted invoice, But you can cancel the invoice which helps to remove the entry from accounts.

Best Answer

You cannot delete a posted invoice, But you can cancel the invoice which helps to remove the entry from accounts.

Avatar
Discard

Why is it whn you override the delete method in odoo the action takes too long

Best Answer

I tried overriding the delete method in odoo but the system takes too long to complete the action...I used the below code 


def delete_from_db(self):
for rec in self:
rec.release_number.with_context(force_delete=True).unlink()
return rec.unlink()
Avatar
Discard
Best Answer

You can install the account_cancel module. It will allow you to configure your journal(s) with the possibility to cancel entries (a new checkbox will be visible on the journal configuration).

Then, you will be able to cancel an invoice (the status will then be "canceled") and as soon as the invoice is canceled you can set it back to draft.

But as soon as an invoice has been confirmed, you won't be able to delete it permanently (the invoice number stays reserved for that invoice)

This is a totally wrong method but if you still want you to have no option then you will go with below option 

1- First install an account_cancel module.


2- Go to file:

https://github.com/odoo/odoo/blob/13.0/addons/account/models/account_move.py#L1596

Note: we recommend create a save to file before.

2- Comment the function unlink like:

def unlink(self):
    for move in self:
        # if move.name != '/' and not self._context.get('force_delete'):
        #    raise UserError(_("You cannot delete an entry which has been posted once."))
        move.line_ids.unlink()
    return super(AccountMove, self).unlink()


3- Go to View and Remove the Invoice.

I hope to help you!

Avatar
Discard

How can you recommend this way to comment out and do it, if odoo is blocking the deletion of posted entries it has its own reason, better go with standard solution of cancelling the invoice and then delete. And in v13, there is no module account_cancel, it is part of the account module itself

Yes @Niyas Raphy Your Are Right we all have to go standard and this is totally wrong let me edit my Ans and Add this is on the ans

Author

People that can only follow standard are not thinking out of the box :-P

Best Answer

Hello, I can't seem to find the Account cancel module. What do I need to do? Thanks

Avatar
Discard

Niyas commented below "And in v13, there is no module account_cancel, it is part of the account module itself. " You need to set the Invoice to draft first.