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 will have to 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:
unlink_ids.append(t['id'])
else:
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})
..(copied answer but it ll work)