Ir al contenido
Menú
Se marcó esta pregunta
2 Respuestas
575 Vistas

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                                                                                                                                                                                                                                     

Avatar
Descartar

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

Autor Mejor respuesta

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])]
  })

                

Avatar
Descartar
Mejor respuesta

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.

Avatar
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
1
dic 23
5932
1
may 25
1886
1
mar 25
1926
1
feb 25
7256
2
feb 25
3988