limfit
limfit

Reputation: 37

Function to add followers automatiically in odoo10

i have a problem I'm not sure how i could add automatically a followers. I tried to use this function but it doesn't work

def add_follower_id(self, res_id, model, partner_id):
  follower_id = False
  reg = {
   'res_id': res_id,
   'res_model': 'my.model',
   'partner_id': self.field_id
  }
  try:
    follower_id = self.env['mail.followers'].create(reg)
  except:
     return False
  return follower_id

Upvotes: 0

Views: 199

Answers (1)

KbiR
KbiR

Reputation: 4174

Inherit mail.thread model and override the create function of current model to add followers. Try below code.

class yourClassName(model.Model):
   _name = 'your.model'
   _inherit = ['mail.thread']

   @api.model
   def create(self,vals):
       result = super(yourClassName,self).create(vals)
       follower_ids = [add user_ids here]
       for f_id in follower_ids:
          result.self.message_subscribe_users(user_ids=your ids)

hope it will help you.

Upvotes: 1

Related Questions