Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
21312 Lượt xem

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

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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.

Ảnh đại diện
Huỷ bỏ
Tác giả

Perfect! THANKS big big!

Bài viết liên quan Trả lời Lượt xem Hoạt động
5
thg 2 22
10786
1
thg 2 16
5401
1
thg 10 15
4934
0
thg 5 16
3406
2
thg 12 15
3482