Search code examples
pythonodooodoo-10

[Odoo][v10] Add subscription types for a follower from Python in Odoo v10


I building my own module, and for each project, I add a calendar event with followers from the project.

So i write a method:

def create_calendar_event(self):
    create_event = self.env['calendar.event'].create({'start': self.start_date, 'stop': self.end_date, 'name': self.title})
    self.calendar_id = create_event

    partner_list = []
    for follower in self.project_id.message_follower_ids:
        partner_list.append(follower.partner_id.id)
    self.testfield = str(partner_list)  #   Debug

    calendar_fallowers = []
    for follower2 in self.calendar_id.message_follower_ids:
        calendar_fallowers.append(follower2.partner_id.id)
    self.testfield_calendar = str(calendar_fallowers)  #   Debug

    #   add followers from project to calendar
    for partner in partner_list:
        if partner not in calendar_fallowers:
            res_id = self.calendar_id.id
            res_model = 'calendar.event'
            partner_id = partner
            self.env['mail.followers'].create({'res_id': res_id, 'res_model': res_model, 'partner_id': partner_id})


    self.env.cr.commit()

So I have calendar event with followers, but I don't have any default subscription types.

and I wanna add default subscription types for all followers: Discussions and Note

How to do this?


Solution

  • To add followers odoo provide a method for :

       self.calendar_id.message_subscribe(partner_list)
    

    And to remove folowers :

       some_record.message_unsubscribe(partner_list)