Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
1 Balas
21338 Tampilan

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

Avatar
Buang
Jawaban Terbai

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.

Avatar
Buang
Penulis

Perfect! THANKS big big!

Post Terkait Replies Tampilan Aktivitas
5
Feb 22
10790
1
Feb 16
5411
1
Okt 15
4946
0
Mei 16
3406
2
Des 15
3482