我继承了crm.lead
模型,并在该字段中创建了一个下拉自定义字段,该字段仅显示组分配用户。现在,当我从下拉列表中选择哪些用户时,我想这样做,这些用户会自动添加到关注者中。
如何执行此操作。如果您知道,请告诉我。
请参阅我的代码。
.py文件
estimation_id = fields.Many2many('res.users', default=lambda self:self.env.user, domain=lambda self: [("groups_id", "=", self.env.ref( "estimation.group_user_hide" ).id)], select=True, track_visibility='onchange', string='Estimation Asign To')
答案 0 :(得分:0)
我有自己的从下拉菜单中添加关注者的代码。问题是我不能从FOllowers列表中仅删除单个记录。您能建议我的代码在哪里错误或我缺少什么吗?
@api.multi
def write(self, vals):
res = super(CrmLead, self).write(vals)
for rec in self:
if rec.estimation_id:
partner_ids = []
for est_rec in rec.estimation_id:
if est_rec.partner_id and est_rec.partner_id.email:
partner_ids.append(est_rec.partner_id.id)
rec.message_subscribe(partner_ids, None)
#message_unsubscribe
message_partner_ids = rec.message_partner_ids.ids
est_ids = [est_rec.partner_id.id for est_rec in rec.estimation_id] + [self.env.ref('base.partner_root').id]
unsub_partners = set(message_partner_ids) - set(est_ids)
template_obj = self.env['mail.mail']
template_data = {
'subject': 'New Estimation Asign : ',
'body_html': "message_body",
'email_from': self.env['mail.message']._get_default_from(),
'email_to': est_rec.partner_id.email
}
template_id = template_obj.create(template_data)
template_obj.send(template_id)
if list(unsub_partners):
rec.message_unsubscribe(list(unsub_partners))
return res