Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
1 ตอบกลับ
21307 มุมมอง

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!

Related Posts ตอบกลับ มุมมอง กิจกรรม
5
ก.พ. 22
10785
1
ก.พ. 16
5398
1
ต.ค. 15
4932
0
พ.ค. 16
3405
override a method inheritance แก้ไขแล้ว
2
ธ.ค. 15
3482