Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

How to create a new user and give him access via API

By
Fabian
on 1/25/16, 4:37 AM 755 views

Hi,

does anyone know how to add a new user to some groups?

I' am able to creat a user via API but i don't know how to add the user to Groups and give him access like Sales: Manager and Warehouse: Manager and so on.

To creat a User via API I use the following code:

import xmlrpcliburl = "http://localhost:8069"  db = "testDatabase" username = 'admin'password = 'admin'common = xmlrpclib.ServerProxy('{}/xmlrpc/2/common'.format(url))uid = common.authenticate(db, username, password, {})models = xmlrpclib.ServerProxy('{}/xmlrpc/2/object'.format(url))user_id=models.execute_kw(db, uid, password, 'res.users', 'create', [{'name':"userAPI", 'login':'userapi@gmail.com','company_ids':[1], 'company_id':1, 'new_password':'1234567890'}])

Now I want to create the new user and give him  access to the Warehouse with the role Manager.

I guess I need to add 'groups_id' to models.execute_kw, but I do not know which value is expected.

I hop, that anyone can halp me.

As you can see in the Tags, i use Odoo Version 8.0-20160119.

Thx Fa

0
Fabian
On 1/25/16, 11:07 AM

Got It:

If you want to creat a User and add him to a Goup, you have to add the following:

import xmlrpcliburl = "http://localhost:8069"   db = "Odoo8TestMac" username = 'admin'password = 'admin'common = xmlrpclib.ServerProxy('{}/xmlrpc/2/common'.format(url))uid = common.authenticate(db, username, password, {})   models = xmlrpclib.ServerProxy('{}/xmlrpc/2/object'.format(url)) user_id=models.execute_kw(db, uid, password, 'res.users', 'create', [{'name':"userAPI9", 'login':'userapi9@gmail.com','company_ids':[1], 'company_id':1, 'new_password':'123456','sel_groups_39_40':40,    'sel_groups_9_44_10':10, 'sel_groups_29_30':30, 'sel_groups_36_37':37, 'sel_groups_21_22_23':23,'sel_groups_5':5 }])

'sel_groups_9_44_10':10 set the user as Sales Manager

'sel_groups_29_30':30 set the user as Warehouse Manager

'sel_groups_36_37:37 set as Manufacturing Manager

'sel_groups_21_22_23':23 set as Financial Manager

'sel_groups_39_40':40 set as Purchases Manager

and 'sel_groups_5':5 set as Employee.



0

Atul Arvind

--Atul Arvind--
1854
| 3 3 5
India
--Atul Arvind--

Hello, 

I am odoo Enthusiast/Consultant from Baroda, Gujarat, India. Working with odoo from v5 to v9 and other opensource technology since 4+ years. Having Strong Expertise in

Requirement gathering & Gap Analysis

Odoo Development

Odoo Customization

Odoo Training

Odoo Integration

Server Administration

Odoo Migration

Implementation

I am also active on StackOverflow.

or 


Atul Arvind
On 1/25/16, 11:47 AM

Here is the possible code to import the users with groups.


import xmlrpclib
url = "http://localhost:8069"
db = "testDatabase"
username = 'admin'
password = 'admin'
common = xmlrpclib.ServerProxy('{}/xmlrpc/2/common'.format(url))
uid = common.authenticate(db, username, password, {})
models = xmlrpclib.ServerProxy('{}/xmlrpc/2/object'.format(url))
user_id = models.execute_kw(db, uid, password, 'res.users', 'create', [{'name':"userAPI", 'login':'userapi@gmail.com','company_ids':[1], 'company_id':1, 'new_password':'1234567890'}])
sale_module_categ_id = models.execute_kw(db, uid, password, 'ir.module.category', 'search', [('name', '=', 'sales')])
#SEARCHES AND LINKING CUSTOMER TO THE GROUP SALES MANAGER
if sale_module_categ_id:
sale_manager_group_id = models.execute_kw(db, uid, password, 'res.group', 'search', [('name', '=', 'sales '), ('category_id', '=', sale_module_categ_id[0])])
if sale_manager_group_id:
models.execute_kw(db, uid, password, 'res.group', 'write', sale_manager_group_id, {'users': [(4, user_id)]})
#SEARCHES AND LINKING CUSTOMER TO THE GROUP WAREHOUSE MANAGER
warehouse_module_categ_id = models.execute_kw(db, uid, password, 'ir.module.category', 'search', [('name', '=', 'sales')])
if warehouse_module_categ_id:
warehouse_manager_group_id = models.execute_kw(db, uid, password, 'res.group', 'search', [('name', '=', 'sales '), ('category_id', '=', warehouse_module_categ_id[0])])
if warehouse_manager_group_id:
models.execute_kw(db, uid, password, 'res.group', 'write', warehouse_manager_group_id, {'users': [(4, user_id)]})



Hope this helps.

Thanks.

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 1/25/16, 4:37 AM
Seen: 755 times
Last updated: 1/26/16, 3:05 AM