콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
3 답글
6383 화면

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

작성자

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.

베스트 답변

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

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

관련 게시물 답글 화면 활동
1
7월 15
6592
1
3월 17
11145
1
6월 16
9113
1
10월 15
7579
3
9월 15
6531