This question has been flagged
1 Reply
3808 Views

Hi

I would add a many2many field to my form to get able to add some more users as follower to my module

This is my python code now

def default_recipient(self):
rec_type = self.env.context.get('rec', False)
if rec_type == 'recipient':
return self.env.user.company_id.partner_id

recipient_partner_id = fields.Many2many(
'res.partner',
string='Recipient',
track_visibility='onchange',
default=default_recipient)

and this is .xml file

<group>
<field name="recipient_partner_id" readonly="1"/>
<field name="name" attrs="{'readonly': [('state', 'not in', ['draft'])]}"/>
</group>

so how can i add this partner as follower

do any one know how to do?

Thanks guys

Avatar
Discard
Best Answer

Hello,

You can try this.

@api.model

def create(self, vals):

res = super(<Your class Name>, self).create(vals)

if res.recipient_partner_id:

for partner in res.recipient_partner_id:

    vals['message_follower_ids'] += self.env['mail.followers']._add_follower_command(self._name, [], {partner.id}, {})[0]

return res

Avatar
Discard