我有一个问题我不确定如何自动添加关注者。我试图使用此功能,但它不起作用
def add_follower_id(self, res_id, model, partner_id):
follower_id = False
reg = {
'res_id': res_id,
'res_model': 'my.model',
'partner_id': self.field_id
}
try:
follower_id = self.env['mail.followers'].create(reg)
except:
return False
return follower_id
答案 0 :(得分:0)
继承mail.thread
模型并覆盖当前模型的create
函数以添加关注者。请尝试以下代码。
class yourClassName(model.Model):
_name = 'your.model'
_inherit = ['mail.thread']
@api.model
def create(self,vals):
result = super(yourClassName,self).create(vals)
follower_ids = [add user_ids here]
for f_id in follower_ids:
result.self.message_subscribe_users(user_ids=your ids)
希望它会对你有所帮助。