コンテンツへスキップ
メニュー
この質問にフラグが付けられました
1 返信
21342 ビュー

Hello all,

I'm trying to override the unlink method in the class account_invoice. To be able to erase invoice when I make tests. 

I want the shortest possible code. What I do wrong?

from openerp import models, fields, api

class account_invoice(models.Model):
    _inherit = ['account.invoice']

 

    @api.multi
    def unlink(self):
        _inherit = ['unlink']
        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.'))
        return super(account_invoice, self).unlink()

 

thanks all

アバター
破棄
最善の回答

Try this:

from openerp import models, fields, api
from openerp.exceptions import except_orm, Warning, RedirectWarning

class account_invoice(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.'))
        return models.Model.unlink(self)

PS. last line is not super()!!! because super() calls the method from account.invoice, which you want to replace.

アバター
破棄
著作者

Perfect! THANKS big big!

関連投稿 返信 ビュー 活動
5
2月 22
10790
1
2月 16
5412
1
10月 15
4946
0
5月 16
3407
2
12月 15
3482