pythonodooodoo-12

Automated Action to Add Users as Followers Odoo 12


i need to make a Automated Action on Odoo 12 to auto add the 3 chosen users as followers on create of contact.

Image

Contact Manager = Field name: user_id

L2 Manager = Field name: x_studio_l2_manager

L3 Manager = Field name: x_studio_l3_manager

Any suggestion?

Thanks


Solution

  • Install Automated Action Rules module for model automation, you will find the menu in Settings >> Debug Turn on >> Technical >> Automation >> Automated Actions, create a new automation action, Model: Contact, Trigger condition: On creation, Action to do: Add followers, Select followers,

    Add automatic followers

    This will assign static followers to the newly created contacts. But for dynamic followers, you have to execute python code:

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

    Remember this is assuming x_studio_l3_manager, x_studio_l2_manager are res.partner type field and user_id is res.users type field. If not, update your question with which types of related fields are those. Remember, if the fields are res.users, you have to use record.x_studio_l2_manager.partner_id.id, record.x_studio_l3_manager.partner_id.id because res.users table id will not be always same as res.partner table id for a particular user.

    You can unfollow existing followers using following code:

    record.message_unsubscribe(partner_ids=record.message_partner_ids.ids)
    

    To perform this, you have add server action that will execute python code, add the code to the server action and run that server action selecting the records.