如何在自定义模块中添加两个one2many字段的关注者?

时间:2016-06-06 10:32:07

标签: python-2.7 openerp odoo-8

我有两个不同类的One2many字段,想知道如何将用户/合作伙伴添加为文档的关注者(在保存或点击按钮时添加关注者)。

我一直在尝试以下方法:

mail_follower_ids = []
        if sobj.matp:  # matp is a one2many field
            for ma in sobj.matp:
                partner_ids = partner_pool.search(cr, uid, [('name','=',ma.empname.name), ('email','=',ma.wk_mail)])
                if partner_ids:
                    for partner in partner_ids:
                        mail_follower_ids.append(partner)

        if sobj.newa:
            for new in sobj.newa:  # newa is a one2many field
                partner_ids = partner_pool.search(cr, uid, [('name','=',new.empname.name), ('email','=',new.wk_mail)])
                if partner_ids:
                    for partner in partner_ids:
                        mail_follower_ids.append(partner)

但无法继续下去,任何有任何建议的人都会非常感激。谢谢!!

1 个答案:

答案 0 :(得分:1)

如果您的模型继承了email.thread,或者您继承了已继承email.thread的模型,则可以在模型上使用message_subscribe添加合作伙伴。

定义:

def message_subscribe(self, cr, uid, ids, partner_ids, subtype_ids=None, context=None):
    """ Add partners to the records followers. """

只需查看mail.mail_thread以找到一些有用的方法: - )