Skip to Content
Menu
This question has been flagged
4 Replies
6101 Views

Hi guys,

How to Create openerp user through Python code ?

I have created a custom menu, there i need to create openerp user.

How can we override create method for this.

i refered below link:

\https://www.odoo.com/forum/help-1/question/how-to-create-openerp-user-through-python-code-34090

def create(self, cr, uid, vals, context=None):
user_obj = self.pool.get('res.users')
vals_user = {
'name': vals.get('name'),
'login': default_login,
#other required field
}
user_obj.create(cr, uid, vals_user, context)
result = super(hr_employee, self).create(cr, uid, vals, context=context)
return result

I didnt understood "'login': default_login",

How to do this? Is there any other method's?


Thanks,

Avatar
Discard
Best Answer
Add these variable to create user in res.users

'login': fields.char('Login', size=64, required=True,
help="Used to log into the system"),
'password': fields.char('Password', size=64, invisible=True, copy=False,
Avatar
Discard
Author

Thank you, its working

Best Answer

Hi,

The suggestion in the link should work fine. You just need to specify the required fields:

vals_user = {

     'name': 'value_of_name',

     'login': 'login_password_value_eg_123', 

     ... and so on

You can check the required fields of the user here ...


Avatar
Discard
Author

Thanks, i need only login and password to be defined in my menu. how can we write that?

Author Best Answer

Hi all,

Thank you, it worked. I was getting 'Integrity error'. and it is solved.

def create(self, cr, uid, vals, context=None):
user_obj = self.pool.get('res.users')
vals_user = {
'name': vals.get('name'),
'login': vals.get('login'),
'password': vals.get('password'),
}
user_obj.create(cr, uid, vals_user, context)
result = super(users_profile, self).create(cr, uid, vals, context=context)
return result
Avatar
Discard