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 can i create access right for a group with XMLRPC python

By
loic972
on 7/22/14, 11:05 AM 876 views

import xmlrpclib

username = 'admin' #the user
pwd = 'admin'      #the password of the user
dbname = 'openerp' #the database

# Get the uid
sock_common = xmlrpclib.ServerProxy ('http://localhost:8069/xmlrpc/common')
uid = sock_common.login(dbname, username, pwd)

#replace localhost with the address of the server
sock = xmlrpclib.ServerProxy('http://localhost:8069/xmlrpc/object'

diki = {'id':1,'name':"myname",'model_id':1,'group_id': 1,'perm_read':0,'perm_write':1,'perm_create':0,'perm_unlink':1}


group = {
  'category_id': 1, # many2one
  'name': 'newgroup14', #simple field
  'implied_ids': [(6,0,[3, 2, 1])], #one2many
  'users' : [(6,0,[1])],
  'menu_access' : [(6,0,[1])], #many2many
  'view_access' : [(6,0,[1])],
  'comment' : 'chopito',
  'model_access' :diki
 
   } #many2many


#Read partner data

 

 

partner_id = sock.execute(dbname, uid, pwd, 'res.groups', 'create', group)

0

Ben Bernard

--Ben Bernard--
1083
| 4 3 6
Jakarta, Indonesia
--Ben Bernard--
Ben Bernard
On 7/22/14, 10:11 PM

It is easier to see from ir.model.access model perspective. So, after create that group with your script (no need model_access in group hash), you make access control with script like this

ret = sock.execute(dbname, uid, pwd, 'ir.model.access', 'create', {
                'name': diki['name'],
                'model_id': diki['model_id'],
                'group_id': partner_id,
                'perm_create': diki['perm_create'],
                'perm_read': diki['perm_read'],
                'perm_unlink': diki['perm_unlink'],
                'perm_write': diki['perm_write']
                })
            if ret:
                print 'ACL {} created'.format(diki['name'])

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/22/14, 11:05 AM
Seen: 876 times
Last updated: 3/16/15, 8:10 AM