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 assign a group for user programatically in openerp 7?

By
Maniganda
on 7/10/14, 1:01 AM 1,701 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

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: 7/10/14, 1:01 AM
Seen: 1701 times
Last updated: 3/16/15, 8:10 AM