Skip to Content
Меню
Вам необхідно зареєструватися, щоб взаємодіяти зі спільнотою.
Це запитання позначене
2 Відповіді
7851 Переглядів

I want to override function unlink() of base model.I got a reference but it is works in odoo9.

https://stackoverflow.com/questions/34725611/how-to-override-method-of-basemodel-openerp-models-py-in-odoo-v9

Can anyone suggest how to override standard unlink() method (odoo/models.py) in odoo 11?

I have tried below code but it didn't worked.

from odoo import api, models


class BaseModelExtend(models.BaseModel):
    _auto = False   
    _register = False
    @api.multi   
    def unlink(self):       
        // code       
        return super(BaseModelExtend, self).unlink()
Аватар
Відмінити
Автор Найкраща відповідь

I found my solution.I tried below code and it is working.

from odoo import api, models
   class BaseModelExtend(models.AbstractModel):
    _inherit = 'base'
     @api.multi
    def unlink(self):
        # code
        return super(BaseModelExtend, self).unlink()
Аватар
Відмінити

thanks, clear, simple and usefull

Should you need to get the table name of the actual model, it's accessible with self._table

Найкраща відповідь


I do this: I inherit my model from the module in which I need to rewrite the function with _inherit and then write my function with the same name, maybe it will help you

Аватар
Відмінити
Related Posts Відповіді Переглядів Дія
2
лип. 24
2745
1
черв. 24
5197
1
жовт. 23
10930
1
жовт. 23
98
1
серп. 23
2194