An Automated Action (this example should work with v11 and v12) can combine the followers (this example adds ONLY followers who are Users) on the Sale Order and followers from the Customer:
Code to copy/paste:
partners_who_are_users = []
users = env['res.users'].search([])
for user in users:
partners_who_are_users.append(user.partner_id.id)
followers = []
for partner in record.partner_id.message_partner_ids.ids:
if partner in partners_who_are_users:
followers.append(partner)
record.message_subscribe(followers)
=========================
add followers automatically
12/18/13, 5:27 AM 10,045 views
Hello in crm.lead the responsible user (user_id) is automatically added as follower to the new task. How can I add this functionality to add some users to my custom object?
To expand on David's answer, I needed to add the Customer as a follower on a LEAD in v10.
I created an Automated Action that looked for crm.lead records created or updated that also had either a Customer or Email populated.
If the record had a Customer, I needed to just add that Customer as a follower (as long as it wasn't already).
If the record had an Email, I needed to check if a Customer already existed, and if not - create them.
This is the code I used for the Server Action:
if record.partner_id:
partner = record.partner_id
else:
partner = env['res.partner'].search([('email','=',record.email_from)])
if not partner:
reg = {
'name': record.contact_name or record.email_from,
'email': record.email_from,
'type': 'contact',
}
partner = env['res.partner'].create(reg)
partner_id = partner.id
reg = {
'res_id': record.id,
'res_model': 'crm.lead',
'partner_id': partner_id,
}
if not env['mail.followers'].search([('res_id','=',record.id),('res_model','=','crm.lead'),('partner_id','=',partner_id)]):
follower_id = env['mail.followers'].create(reg)