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

Hello 

would like to give  group "A" for the created user, if the creator have group "B", for that i have created the following class :


class User(models.Model):

_inherit = 'res.users'

#this is the solution
@api.model
def create(self, vals):



res = super(User, self).create(vals)

if self.env.user.has_group('module.group_A'):
self.env['res.users'].create({
'groups_id': 'module.group_B',
})


return res

But i got this erreur:
You cannot create a new user from here.
To create new user please go to configuration panel.

Avatar
Discard
Best Answer

Hi,
You are trying to create a new user by only giving the group_id, that is why you are getting such a message. On creating the new user, if the value from the login is not given, you will get such a message, so please modify the code by adding login on creating the new user.


This is the original  code from where you getting such a message.

@api.model
def create(self, values):
if not values.get('login', False):
action = self.env.ref('base.action_res_users')
msg = _("You cannot create a new user from here.\n To create new user please go to configuration panel.")
raise exceptions.RedirectWarning(msg, action.id, _('Go to the configuration panel'))

user = super(Users, self).create(values)

Thanks

Avatar
Discard
Author

Thank you bro