Fotic
Fotic

Reputation: 321

Add channel as follower according the two users

Im trying via Automated Action to auto add Channel according the 2 users where they are followers.

Code so far:

record.message_subscribe(partner_ids=[record.user_id.partner_id.id, record.x_studio_subcontractor.user_id.partner_id.id])

The above code make the 2 users followers, what code should apply so I can make their channel also follower to task?

Upvotes: 1

Views: 335

Answers (1)

Charif DZ
Charif DZ

Reputation: 14741

Search for chat channel between this two user both partner should be member of this channel, and the type of the chat channel is 'chat', for private channel the type of channel is 'channel' user can have multiple channels.

partner_ids = [record.user_id.partner_id.id, 
              ecord.x_studio_subcontractor.user_id.partner_id.id]

channel_ids = self.env['mail.channel'].search([('channel_partner_ids', '=', partner_ids[0]),
                                         ('channel_partner_ids', '=', partner_ids[1]),
                                         ('public', '=', 'private'),
                                         ('channel_type', '=', 'chat'),  # only chat channel it should be only one
                                         ]).ids or None

record.message_subscribe(partner_ids=partner_ids, channel_ids=channel_ids)

@Fotic

With the below attributes on search is not adding the channel (probably because there was 2 channels (Announcements and the Private))

('public', '=', 'private'),
('channel_type', '=', 'chat'),  

My final solution:

partner_ids = [record.user_id.partner_id.id,record.x_studio_subcontractor.user_id.partner_id.id]

channel_ids = record.env['mail.channel'].search([('channel_partner_ids', '=', partner_ids[0]),
                                         ('channel_partner_ids', '=', partner_ids[1]),
                                         ('group_ids', '=', False),
                                         ]).ids or None

record.message_subscribe(partner_ids=partner_ids, channel_ids=channel_ids) 

Anyway thank you very much for the help @Charif DZ

Upvotes: 1

Related Questions