Skip to Content
Menú
This question has been flagged
1 Respondre
5142 Vistes

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
Descartar
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
Descartar
Related Posts Respostes Vistes Activitat
1
de maig 19
4413
2
d’ag. 24
1123
0
d’abr. 21
2277
0
de febr. 21
214
2
d’oct. 23
8555