Skip to Content
Menu
This question has been flagged
2 Replies
582 Rodiniai

Hello,

This question is similar to one posted some years ago: 
("Grant portal access automatically when contact is created", I can't post the link)
... but I'm using Odoo Studio.

I would like people to sign up for free to my website and then give them some functionality.  I've heard that the way to go is to create a portal user from the contact that is created when someone signs up.  

I'm looking at actions but it feels like the Studio interface doesn't allow me to dig down deep enough to select the filds I was to copy.  Is this possible using Studio?  I have the entreprise subscription.


Thanks, much obliged.                                                                                               

Stephen                                                                                                                                                                                                                                     

Portretas
Atmesti

This is the original question, and the answer there seems like the simplest way to do it. Studio isn't going to provide any useful extra functionality for this requirement.

https://www.odoo.com/forum/help-1/grant-portal-access-automatically-when-contact-is-created-168660

Autorius Best Answer

This worked for me:
For someone who signs up, providing an email address and a password:

First, see if there's a partner with that email address:

partner = request.env['res.partner'].sudo().search([('email', '=', login)], limit=1)

If there isn't then create a partner:

partner = request.env['res.partner'].sudo().create({'name': login, 'email': login})


then create the user linked to the partner record:

             # Create the new portal user linked to the partner

   newUser = request.env['res.users'].sudo().create({
​ 'name': login,
    'login': login,
    'partner_id': partner.id,
    'password': password,
    'groups_id': [(6, 0, [portal_group.id])]
  })

                

Portretas
Atmesti
Best Answer

Hi,

Steps:

Go to Settings → Technical → Automated Actions.

    Create a new automated action:

    Model: res.partner (Contacts)

    Trigger: On Creation

    Action: Create a Record

    You can configure Studio to create a new res.users record.

    Set the partner_id to the created contact.

    Set groups_id to include the Portal group.


If action execute code

Code:

if not record.user_ids:

    user = env['res.users'].create({

        'name': record.name,

        'login': record.email,

        'partner_id': record.id,

        'groups_id': [(4, env.ref('base.group_portal').id)],

    })


Hope it helps.

Portretas
Atmesti
Related Posts Replies Rodiniai Veikla
1
gruod. 23
5937
1
geg. 25
1887
1
kov. 25
1928
1
vas. 25
7266
2
vas. 25
3998