跳至内容
菜单
此问题已终结
2 回复
577 查看

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                                                                                                                                                                                                                                     

形象
丢弃

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

编写者 最佳答案

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

                

形象
丢弃
最佳答案

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.

形象
丢弃
相关帖文 回复 查看 活动
1
12月 23
5932
1
5月 25
1886
1
3月 25
1926
1
2月 25
7256
2
2月 25
3990