Ir al contenido
Menú
Se marcó esta pregunta
1 Responder
4419 Vistas

Hi 

I created a module for rental system, however while creating it i made a lot of sample invoices which I made for testing, and now i want to delete all those invoices for my keeping my final module freshly..

Note : I have cancelled those modules but its still not deleting 

ODOO Version : 11

Hope someone helps 

Avatar
Descartar
Mejor respuesta


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)

Avatar
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
3
mar 15
4629
3
nov 24
3247
3
dic 22
6106
0
oct 22
2381
1
ago 19
2826