How to inherit Mail.Thread AbstractModel and override function from this class in Odoo?

情到浓时终转凉″ 提交于 2019-12-23 16:34:38

问题


I would like to change something from mail.thread abstract class. So I inherited mail.thread and wrote override message_tracked function. But it did not call override function... just only called base function. Is it cause by mail.thread is Abstract Model?

I tried like that osv.osv and osv.AbstractModel and import this py file in init.py and put 'mail' module in depend dic of openerp.py

class mail_thread(osv.osv):
    _inherit = 'mail.thread'  

class mail_thread(osv.AbstractModel):
    _inherit = 'mail.thread' 

they did not call any function in this class def write or def message_track

If you do not mind, please explain me how to write override function for message_track.


回答1:


This is probably related to the issue described here: https://github.com/odoo/odoo/issues/9084

As a workaround you may try to solve this as described here: Override python function in odoo

I did it like this:

from openerp.addons.mail.mail_thread import mail_thread

message_new_orig = mail_thread.message_new

def message_new(self, cr, uid, msg_dict, custom_values=None, context=None):
    # call super function
    msg_id = message_new_orig(self, cr, uid, msg_dict,
                              custom_values=custom_values, context=context)
    # put custom code here
    # ...

    return msg_id

# install overide
mail_thread.message_new = message_new


来源:https://stackoverflow.com/questions/31936122/how-to-inherit-mail-thread-abstractmodel-and-override-function-from-this-class-i

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!