Skip to Content
Menu
This question has been flagged
2 Replies
15340 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

Avatar
Discard
Author Best Answer

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.



Avatar
Discard
Best Answer

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.

Avatar
Discard
Related Posts Replies Views Activity
0
Sep 24
3
0
Sep 24
351
1
Jun 24
667
0
Apr 24
401
1
Mar 24
930