Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
1 Balas
4422 Tampilan

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
Buang
Jawaban Terbai


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
Buang
Post Terkait Replies Tampilan Aktivitas
3
Mar 15
4632
3
Nov 24
3252
3
Des 22
6107
0
Okt 22
2382
1
Agu 19
2827