Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
2 Răspunsuri
580 Vizualizări

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                                                                                                                                                                                                                                     

Imagine profil
Abandonează

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 Cel mai bun răspuns

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

                

Imagine profil
Abandonează
Cel mai bun răspuns

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.

Imagine profil
Abandonează
Related Posts Răspunsuri Vizualizări Activitate
1
dec. 23
5935
1
mai 25
1887
1
mar. 25
1927
1
feb. 25
7263
2
feb. 25
3995