Odoo Help

Welcome!

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

0

Delete (previously canceled) invoices

By
E.M.
on 12/5/15, 2:40 PM 794 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

--Axel Mendoza--
10228
| 7 7 8
Camaguey, Cuba
--Axel Mendoza--

DevOps - Full stack - Software Architect - Developer - Technology Integrator

I could help you to develop anything and solve complex problems based on technologies, integrations and tricky stuffs mostly in Python with OpenERP/Odoo, Zato, Django and many others frameworks programming languages and technologies.

I offers consulting services to anyone with an unanswered questions or needs for customizations. Think about it, maybe it's better to have an expert to solve your issues and projects than having a full time employee trying to understand what to do an how

Reach me at aekroft@gmail.com

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

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

2 follower(s)

Stats

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