跳至內容
選單
此問題已被標幟
1 回覆
4574 瀏覽次數

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 

頭像
捨棄
最佳答案


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)

頭像
捨棄
相關帖文 回覆 瀏覽次數 活動
3
3月 15
4900
3
11月 24
3535
3
12月 22
6222
0
10月 22
2465
1
8月 19
2941