Search code examples
pythonodooodoo-12

Automated Action Grant Portal Access


Im trying to make an Automated Action, when I create a user also grand access to portal.

My code so far is bind on button Apply to All (see image below):

for rec in records:
  for user in rec.user_ids:
    user['in_portal'] = True
rec.action_apply()

Apply to All Button Code: <button name="563" type="action" string="Apply to All"/>

enter image description here

How can i modify the code so it run, when I create a user and also grand access to portal?


Solution

  • There are some options, to implement what you need.

    1. Override create() of model res.users and just add users to your desired group(s) after super call.

    2. Create an automated action (Settings/Technical/Automation/Automated Actions)

      • Model: Users (res.users)
      • Trigger Condition: On Creation
      • Action To Do: Update the Record
      • Data to Write: add one line

        • Field: Groups (res.users)
        • Evaluation Type: Python expression
        • Value: [(4,env.ref('external id of group').id)]

          Substitute external id of group with base.group_portal so in your case it should be [(4,env.ref('base.group_portal').id)]