Odoo Help

0

How to assign a group for user programatically in openerp 7?

By
Maniganda
on 7/10/14, 1:01 AM 2,448 views

I need to assign the groups to user through programatically rather than directly selecting the groups from Access Rights screen.

I have created a field called "user_roles" which will give the list of roles such as [Sales, Purchase,so on..].

based on these roles i need to assign groups to user, and to clear other standard groups assigned to user.

0
Richmond Ang
On 7/10/14, 1:46 PM

You can do something like this

user_model = self.pool.get('res.users')
external_id_model = self.pool.get('ir.model.data')
portal_group_id = external_id_model.get_object_reference(cr,uid,'portal','group_portal')[1]
res_id = False

username = "login id of user"

res_id = user_model.search(cr, uid, [('login','=', username)]))[0].id

user_model.write(cr,uid,[res_id],{'groups_id': [(6, 0, [portal_group_id])]})

this code removes all previous groups then adds the portal group.

if you need more reference on adding to many2many fields:

http://stackoverflow.com/questions/9377402/insert-into-many-to-many-openerp/9387447#9387447

About This Community

This platform 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.

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)

Stats

Asked: 7/10/14, 1:01 AM
Seen: 2448 times
Last updated: 3/16/15, 8:10 AM