Skip to Content
Menu
This question has been flagged
1 Reply
11035 Views

Hi All,


I would like to create 2 sets of user, whenever a form is signup. Hence I cannot use the "auth_signup" module.


I tried to test create a user from the console using the below code:

env['res.users'].sudo().create({
'name': 'testa',
'login': 'testa',
})


But I was not able to create a new user. Instead I got this error.

2016-01-25 00:57:51,435 13091 INFO elm openerp.sql_db: bad query:  SELECT "res_users"."id" as "id","res_users"."company_id" as "company_id" FROM "res_users" LEFT JOIN "res_partner" as "res_users__partner_id" ON ("res_users"."partner_id" = "res_users__partner_id"."id")
WHERE "res_users".id IN (1) ORDER BY "res_users__partner_id"."name" ,"res_users"."login"
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/home/gavinyap/Documents/git/fusionbrm9/openerp/api.py", line 248, in wrapper
return new_api(self, *args, **kwargs)
File "/home/gavinyap/Documents/git/fusionbrm9/openerp/api.py", line 490, in new_api
result = method(self._model, cr, uid, *args, **old_kwargs)
File "/home/gavinyap/Documents/git/fusionbrm9/openerp/addons/base/res/res_users.py", line 845, in create
return super(users_view, self).create(cr, uid, values, context)
File "/home/gavinyap/Documents/git/fusionbrm9/openerp/api.py", line 250, in wrapper
return old_api(self, *args, **kwargs)
File "/home/gavinyap/Documents/git/fusionbrm9/openerp/addons/base/res/res_users.py", line 643, in create
user_id = super(users_implied, self).create(cr, uid, values, context)
File "/home/gavinyap/Documents/git/fusionbrm9/openerp/api.py", line 250, in wrapper
return old_api(self, *args, **kwargs)
File "/home/gavinyap/Documents/git/fusionbrm9/openerp/addons/base/res/res_users.py", line 336, in create
user_id = super(res_users, self).create(cr, uid, vals, context=context)
File "/home/gavinyap/Documents/git/fusionbrm9/openerp/api.py", line 250, in wrapper
return old_api(self, *args, **kwargs)
File "/home/gavinyap/Documents/git/fusionbrm9/openerp/api.py", line 354, in old_api
result = method(recs, *args, **kwargs)
File "/home/gavinyap/Documents/git/fusionbrm9/openerp/models.py", line 4112, in create
vals = self._add_missing_default_values(vals)
File "/home/gavinyap/Documents/git/fusionbrm9/openerp/api.py", line 248, in wrapper
return new_api(self, *args, **kwargs)
File "/home/gavinyap/Documents/git/fusionbrm9/openerp/api.py", line 490, in new_api
result = method(self._model, cr, uid, *args, **old_kwargs)
File "/home/gavinyap/Documents/git/fusionbrm9/openerp/models.py", line 1775, in _add_missing_default_values
defaults = self.default_get(cr, uid, list(missing_defaults), context)
File "/home/gavinyap/Documents/git/fusionbrm9/openerp/api.py", line 250, in wrapper
return old_api(self, *args, **kwargs)
File "/home/gavinyap/Documents/git/fusionbrm9/openerp/addons/base/res/res_users.py", line 875, in default_get
values = super(users_view, self).default_get(cr, uid, fields1, context)
File "/home/gavinyap/Documents/git/fusionbrm9/openerp/api.py", line 250, in wrapper
return old_api(self, *args, **kwargs)
File "/home/gavinyap/Documents/git/fusionbrm9/openerp/api.py", line 354, in old_api
result = method(recs, *args, **kwargs)
File "/home/gavinyap/Documents/git/fusionbrm9/openerp/models.py", line 1326, in default_get
defaults[name] = field.default(self)
File "/home/gavinyap/Documents/git/fusionbrm9/openerp/fields.py", line 75, in <lambda>
value(model._model, model._cr, model._uid, model._context),
File "/home/gavinyap/Documents/git/fusionbrm9/openerp/addons/base/res/res_users.py", line 254, in _get_company
context=context, load='_classic_write')
File "/home/gavinyap/Documents/git/fusionbrm9/openerp/api.py", line 250, in wrapper
return old_api(self, *args, **kwargs)
File "/home/gavinyap/Documents/git/fusionbrm9/openerp/addons/base/res/res_users.py", line 908, in read
res = super(users_view, self).read(cr, uid, ids, other_fields, context=context, load=load)
File "/home/gavinyap/Documents/git/fusionbrm9/openerp/api.py", line 250, in wrapper
return old_api(self, *args, **kwargs)
File "/home/gavinyap/Documents/git/fusionbrm9/openerp/addons/base/res/res_users.py", line 307, in read
result = super(res_users, self).read(cr, uid, ids, fields=fields, context=context, load=load)
File "/home/gavinyap/Documents/git/fusionbrm9/openerp/api.py", line 250, in wrapper
return old_api(self, *args, **kwargs)
File "/home/gavinyap/Documents/git/fusionbrm9/openerp/models.py", line 3175, in read
result = BaseModel.read(records, fields, load=load)
File "/home/gavinyap/Documents/git/fusionbrm9/openerp/api.py", line 248, in wrapper
return new_api(self, *args, **kwargs)
File "/home/gavinyap/Documents/git/fusionbrm9/openerp/models.py", line 3210, in read
self._read_from_database(stored, inherited)
File "/home/gavinyap/Documents/git/fusionbrm9/openerp/api.py", line 248, in wrapper
return new_api(self, *args, **kwargs)
File "/home/gavinyap/Documents/git/fusionbrm9/openerp/models.py", line 3348, in _read_from_database
cr.execute(query_str, params)
File "/home/gavinyap/Documents/git/fusionbrm9/openerp/sql_db.py", line 139, in wrapper
return f(self, *args, **kwargs)
File "/home/gavinyap/Documents/git/fusionbrm9/openerp/sql_db.py", line 218, in execute
res = self._obj.execute(query, params)
InternalError: current transaction is aborted, commands ignored until end of transaction block


The error does not make sense as I can cut, paste and run the SQL in postgres and it yield results.


What is wrong here and what can I do to create a new User? 

Note: I'm using Odoo8 or 9


Avatar
Discard
Best Answer

Can you run that code (with a little modification as bellow)  in a web controller?:

class ApiController(http.Controller):

@http.route(route='/create_user', auth='public')
 def create_user(self, **kwargs): 

http.request.env['res.users'].sudo().create({
'name': 'testa',
'login': 'testa',
})


My code is pretty the same as yours and it works well in a controller.

Avatar
Discard
Author

Thanks. Odoo framework is relatively weird. In the console. if I use self.env it works but not env alone.

Related Posts Replies Views Activity
2
Nov 21
2304
1
May 21
8889
0
Oct 16
3945
1
Sep 16
6218
2
Apr 23
85059