Odoo Help

0

Delete (previously canceled) invoices

By
E.M.
on 12/5/15, 2:40 PM 1,240 views

Hi,

I am trying to write a module to delete invoices.

I have seen this post https://www.odoo.com/forum/help-1/question/how-to-delete-an-invoice-after-validation-20831 which explains what to do.

I have therefore created a new module delete_invoices with the following code:

/usr/lib/python2.7/dist-packages/openerp/addons/custom/delete_invoices# cat delete_invoices.py
# -*- coding: utf-8 -*-
from openerp import models, fields, api

# DESCRIPTION:
# Class DeleteInvoices allows invoice deletion
# NOTES:
# account_cancel / diary allow cancel entries required

class DeleteInvoices ( models.Model ):
_inherit = 'account.invoice'

@api.multi
def unlink(self):
for invoice in self:
if invoice.state not in ('draft', 'cancel'):
raise Warning(_('You cannot delete an invoice which is not draft or cancelled. You should refund it instead.'))
# elif invoice.internal_number:
# raise 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, then re-confirm it.'))
return super(account_invoice, self).unlink()


Unfortunately when I try to delete a cancelled invoice I get the following message:

  File "/usr/lib/python2.7/dist-packages/openerp/addons/custom/delete_invoices/delete_invoices.py", line 20, in unlink
return super(account_invoice, self).unlink()
NameError: global name 'account_invoice' is not defined

Any tips or ideas? Thanks a lot.


For completition I also include __openerp__ and __init__ files:

# cat __init__.py
from . import delete_invoices
# cat __openerp__.py
{
'name': 'Allow delete invoice',
'description': 'This module allows to delete invoices once they have been cancelled',
'author': 'E.M.',
'depends': ['account_cancel'],
'data': [],
}

Thanks

In the __openerp__.py you have to add account depends too. Account_cancel it's not enough

Metalluffico di Ottaviano Basso, Mirco Strizzi
on 12/5/15, 2:50 PM

Thanks Mirco. 'account_cancel' depends on 'account' so at the end you will need to have installed both modules so 'account' might be redundant here. In any case issue is located on how I am replacing the method and not in dependencies.

E.M.
on 12/5/15, 6:43 PM
0
Axel Mendoza
On 12/5/15, 7:00 PM

The account_invoice error refers to the class name used on the super call. Just change to DeleteInvoices and you will be ok

Still same error: File "/usr/lib/python2.7/dist-packages/openerp/addons/custom/delete_invoices/delete_invoices.py", line 20, in unlink return super(DeleteInvoices, self).unlink() NameError: global name 'account_invoice' is not defined

E.M.
on 12/6/15, 8:31 AM

That was an error you havd. You should have more. Post all the code because in that line I only saw one account_invoice variable usage on super call. It must be something that you are not posting

Axel Mendoza
on 12/6/15, 9:43 AM

About This Community

This platform 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.

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

2 follower(s)

Stats

Asked: 12/5/15, 2:40 PM
Seen: 1240 times
Last updated: 12/6/15, 8:29 AM