Odoo Help


This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


How to delete an invoice after validation?

on 6/11/13, 7:49 PM 22,529 views

How to delete an invoice after validation?

On 9/20/13, 11:19 AM

Hi, In order to Delete an invoice(which is validated), you have to edit the unlink method of account_invoice.

1) At first you have to install a account_cancel module.

2) Allow Cancelling Entries of corresponding journals.

3) After that you have cancel posted journal entries of that invoice.

4) then you are able to cancel the invoice. now you are ready to delete this invoice.

Go to Addons>>account module, open account_invoice.py file. find the unlink method which is same as:

def unlink(self, cr, uid, ids, context=None):
    if context is None:
        context = {}
    invoices = self.read(cr, uid, ids, ['state','internal_number'], context=context)
    unlink_ids = []
    for t in invoices:
        if t['state'] in ('draft', 'cancel') and t['internal_number']== False:
            raise osv.except_osv(_('Invalid Action!'), _('You can not delete an invoice which is not cancelled. You should refund it instead.'))
    osv.osv.unlink(self, cr, uid, unlink_ids, context=context)
    return True

Just remove "and t['internal_number']== False" from if statement or change it to "and t['internal_number']== True", and save it. after doing it you have to restart the openerp server. Now go to admin and delete the canceled invoice, it will work perfectly.

There is also an another trick, which will work every time.

In account_invoice.py in the 'action_cancel' method

self.write(cr, uid, ids, {'state':'cancel', 'move_id':False})

just replace this code with below one:

self.write(cr, uid, ids, {'state':'cancel', 'internal_number':False ,'move_id':False})


Ray Carnes

--Ray Carnes--
| 9 7 9
Greater Los Angeles, United States
--Ray Carnes--

Senior Odoo Analyst

OpenERP 6.1, 7.0 and Odoo 8.0, 9.0 (Since 2012)

Completed Functional and Technical Training.

Major Skills:

  • Needs Discovery and Requirements Analysis;

  • Function and Technical Specifications;

  • Project Planning;

  • Prototyping and Proof of concepts;

  • Data migration;

  • Configuration & Customization (UI and modules);

  • Integration - data, business logic and service levels;

  • Training and Knowledge transfer;

  • Go Live support;

  • Help desk;

  • Version Migration.

I have over 20 years of experience empowering and enabling users with enterprise information systems that make a real and measurable difference in their ability to proactively manage their businesses and organizations. 

Ray Carnes
On 6/11/13, 9:07 PM

If the Invoice has not been paid, you can CANCEL it.

Only do this if you are sure the Invoice has not been sent to your Customer/Supplier.

thank you very much for your answer, but how can I remove it

on 6/11/13, 10:45 PM

Also - if you unreconcile the payments to reopen it, you can cancel an invoice previously recorded as paid.

Bista Solutions US, Ray Carnes
on 9/20/13, 4:42 PM

@Bista Solutions, I have unreconciled the payments and tried to re-open the invoice but. it's still in PAID state. This is in V7.

Gopakumar N G
on 8/11/16, 3:07 AM


| 6 5 8
Delhi, India
Python OpenERP Developer http://in.linkedin.com/pub/sandeep-rana/3b/a16/786/
On 6/12/13, 3:09 AM

Hi After validation you can't delete any invoice , for that case you can do one thing ,just refund the invoice and then cancelit

you can consider it as deleted one as it will not be counted for invoice register



Cyril Gaspard (GEM)

--Cyril Gaspard (GEM)--
| 5 6 8
Paris, France
--Cyril Gaspard (GEM)--

Forum contributor since 2008

Cyril Gaspard (GEM)
On 6/11/13, 8:21 PM


use a refund for that.


Greater Global - HK
On 11/17/13, 2:29 AM

2) Allow Cancelling Entries of corresponding journals.

Hi, I am stuck on step 2. I have installed account_cancel module.

Yet, in settings-->>accounting-->>configuration -- I do not have any check options relating to journals. I have unistalled and re-installed account_cancel module, updated it, looked at the technical features tab etc and nothing.

It simply isn't showing up under settings. I can't select "cancel entries of corresponding journals" because I cannot find it!

any advice/ thoughts please? Very much appreciated.

What you are looking for is a checkbox on the Journal form view. Accounting --> Configuration --> Journals -> Journals. Open the Journal for which you want to allow cancelling, and make sure "Allow Cancelling Entries" is checked.

Bista Solutions US, Ray Carnes
on 11/17/13, 10:38 PM

Hi Ray, thank you for taking the time to answer.

That option isn't showing. I cannot access journals under configuration. I have since discovered that the online edition doesn't allow for modules to be added / updated, thus explaining why this configuration option isn't showing up. Many thanks anyways!

Greater Global - HK
on 11/17/13, 10:46 PM

The online edition allows for modules written by OpenERP to be installed. The module "Cancel Journal Entries" is one of these modules. You need to be logged in as the administrator of your database to install the module, and a member of the Technical Features group to see all of the hidden menus.

Bista Solutions US, Ray Carnes
on 11/19/13, 1:09 AM

Is there any option same as that used to delete the invoice so that all the other documents like sales orders,delivery orders,internal moves etc can be deleted in various statuses without much difficulty?

sneha antony
on 6/11/14, 6:04 AM
Piotr Kaczmarski
On 10/10/13, 8:35 PM


I stuck at step 4 ... In my installation (openerp 7, python 2.6, centos) following fragment of account_invoice.py code is little different, eg:

def unlink(self, cr, uid, ids, context=None):
         if context is None:
             context = {}
         invoices = self.read(cr, uid, ids, ['state','internal_number'], context=context)
         unlink_ids = []

         for t in invoices:
             if t['state'] not in ('draft', 'cancel'):
                 raise openerp.exceptions.Warning(_('You cannot delete an invoice which is not draft or cancelled. You should refund it instead.'))
             elif t['internal_number']:
                 raise openerp.exceptions.Warning(_('You cannot delete an invoice after it has been validated (and received a number).  You can set it back to "Draft" state and modify its content, the        n re-confirm it.'))

         osv.osv.unlink(self, cr, uid, unlink_ids, context=context)
         return True

     def onchange_partner_id(self, cr, uid, ids, type, partner_id,\
             date_invoice=False, payment_term=False, partner_bank_id=False, company_id=False):
         partner_payment_term = False
         acc_id = False
         bank_id = False
         fiscal_position = False

There is no such thing like: t['internal_number']== False. I tried delete this line, modify content sth, but installation just hangs.

Also, I can modify account_invoice.py content using second method, openerp working, but with no effect (invoice still cant be deleted). In log i have following output:

Traceback (most recent call last): File "/usr/lib/python2.6/site-packages/openerp-7.0_20130908_231053-py2.6.egg/openerp/osv/osv.py", line 131, in wrapper return f(self, dbname, args, *kwargs) File "/usr/lib/python2.6/site-packages/openerp-7.0_20130908_231053-py2.6.egg/openerp/osv/osv.py", line 197, in execute res = self.execute_cr(cr, uid, obj, method, args, *kw) File "/usr/lib/python2.6/site-packages/openerp-7.0_20130908_231053-py2.6.egg/openerp/osv/osv.py", line 185, in execute_cr return getattr(object, method)(cr, uid, args, *kw) File "/usr/lib/python2.6/site-packages/openerp-7.0_20130908_231053-py2.6.egg/openerp/addons/sale/sale.py", line 1012, in unlink return super(account_invoice, self).unlink(cr, uid, ids, context=context) File "/usr/lib/python2.6/site-packages/openerp-7.0_20130908_231053-py2.6.egg/openerp/addons/account/account_invoice.py", line 474, in unlink

Any ideas will be welcomed :)

now for this situation you just comment the elif part. after that don't forget to restart the openerp server......

on 11/18/13, 2:18 AM
On 6/12/13, 2:51 AM

You can set the sales journal to allow canceling entries. by going to Configuration > Journals. Then you can cancel the invoice to remove any journal entries and the invoice will appear grayed out in your list. OR you can refund it if thats more applicable to the particular situation.

However, you shouldn't be able to delete the record completely from OpenERP, once it has been validated. Full deletion would not be fantastic accounting practice as there wouldn't be any traceability :)

Hope that helps.

Hi! What if all you entries that you made until the moment you want to delete them are for test purpose only. How can you delete those entries (invoice, payments...) ?

Claudiu Dominic Bolonyi
on 6/14/13, 11:38 AM

If you are just testing, maybe its worth creating a separate database for testing purposes and keeping all your production entries in a real one. If its too late and you HAVE to remove entries you can do this manually by deleting them from postgres, but this is not advisable if there is an alternative.

on 6/18/13, 12:09 AM

I have faced the same problem, and I have deleted all records from account_invoice* tables in openerp database. That data were not for testing, is just a bad operation For example, I have created a proforma invoice, then I needed to change the price but proforma does not allow to change it. I tried to refund, but new records were created. After some trials to cancel an invoice, I got 6 new invoices in my accounting system. So the only solution was to delete data from database.

on 8/3/13, 7:59 PM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

4 follower(s)


Asked: 6/11/13, 7:49 PM
Seen: 22529 times
Last updated: 3/16/15, 8:10 AM