Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
4381 Widoki

I am attempting to assign a user to a group in OpenERP 7.0 using the API, via the openerp-client-lib Python library. When I try to associate a user with the group with what I believe to be the correct ORM write method, my system throws an NotImplementedError exception.

Here is my script:

import openerplib

conn = openerplib.get_connection(hostname='localhost', database='openerp', login='admin', password='password')
user_model = conn.get_model('res.users')
myuser = user_model.search_read([('login', '=', 'joebloggs')])
group_model = conn.get_model('res.groups')
mygroup = group_model.search_read([('name', '=', 'Multi Companies')])[0]
group_model.write(mygroup['id'], {'users': [(4, myuser['id'])]})

The exception trace output is as follows:

Fault Iteration is not allowed on browse_record(res.groups, 4):
Traceback (most recent call last):
File "/opt/openerp/server/openerp/service/wsgi_server.py", line 82, in xmlrpc_return
result = openerp.netsvc.dispatch_rpc(service, method, params)
File "/opt/openerp/server/openerp/netsvc.py", line 292, in dispatch_rpc
result = ExportService.getService(service_name).dispatch(method, params)
File "/opt/openerp/server/openerp/service/web_services.py", line 626, in dispatch
res = fn(db, uid, *params)
File "/opt/openerp/server/openerp/osv/osv.py", line 188, in execute_kw
return self.execute(db, uid, obj, method, *args, **kw or {})
File "/opt/openerp/server/openerp/osv/osv.py", line 131, in wrapper
return f(self, dbname, *args, **kwargs)
File "/opt/openerp/server/openerp/osv/osv.py", line 197, in execute
res = self.execute_cr(cr, uid, obj, method, *args, **kw)
File "/opt/openerp/server/openerp/osv/osv.py", line 185, in execute_cr
return getattr(object, method)(cr, uid, *args, **kw)
File "/opt/openerp/server/openerp/addons/mail/res_users.py", line 190, in write
write_res = super(res_groups_mail_group, self).write(cr, uid, ids, vals, context=context)
File "/opt/openerp/server/openerp/addons/base/res/res_users.py", line 670, in write
res = super(groups_view, self).write(cr, uid, ids, values, context)
File "/opt/openerp/server/openerp/addons/base/res/res_users.py", line 588, in write
for g in self.browse(cr, uid, ids):
File "/opt/openerp/server/openerp/osv/orm.py", line 494, in __iter__
raise NotImplementedError("Iteration is not allowed on %s" % self)
NotImplementedError: Iteration is not allowed on browse_record(res.groups, 4)

Looking at the source, the users field on the res.groups model appears to be a normal many2many field, which I expect would be written to in the normal manner via the API. I've tried some of the other write methods (like trying to unlink all users), but get the same error. Can anyone point out what I'm doing wrong?

Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
1
wrz 23
2182
3
kwi 19
3141
1
mar 15
5722
5
maj 25
33605
0
gru 24
1299