如何从Odoo中的此类继承Mail.Thread AbstractModel并重写函数? [英] How to inherit Mail.Thread AbstractModel and override function from this class in Odoo?
问题描述
我想更改mail.thread抽象类中的某些内容.因此,我继承了mail.thread并编写了重写message_tracked函数.但是它没有调用覆盖函数……只是调用了基本函数.是由mail.thread引起的,还是Abstract Model?
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?
我尝试过使用osv.osv和osv.AbstractModel并将此py文件导入 init .py并将邮件"模块放入 openerp .py的依赖dic中
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'
他们没有在此类中调用任何函数 def write 或 def message_track
they did not call any function in this class def write or def message_track
如果您不介意,请向我解释如何为message_track编写覆盖功能.
If you do not mind, please explain me how to write override function for message_track.
推荐答案
这可能与此处描述的问题有关: https://github.com/odoo/odoo/issues/9084
This is probably related to the issue described here: https://github.com/odoo/odoo/issues/9084
作为解决方法,您可以尝试解决此问题,如下所述: 在odoo中覆盖python函数
As a workaround you may try to solve this as described here: Override python function in odoo
我是这样做的:
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
这篇关于如何从Odoo中的此类继承Mail.Thread AbstractModel并重写函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!