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

Hello,

I would like to make the created user as employee , i have used the following instruction :

#this is the solution
@api.model
def create(self, vals): ......
vals['employee'] = True

But nothing happened, any help please?

Avatar
Discard
Best Answer

Hi,

You can create employee from user like this,

class ResUsersInherit(models.Model):
_inherit = 'res.users'

employee_id = fields.Many2one('hr.employee',
string='Employee', ondelete='restrict', auto_join=True)

@api.model
def create(self, vals):
res = super(ResUsersInherit, self).create(vals)
res['employee_id'] = self.env['hr.employee'].create({'name': result['name'],
'user_id': result['id'],
'address_home_id': result['partner_id'].id})
return res

Also you can check with this community module,https://www.odoo.com/apps/modules/9.0/employee_creation_from_user/

Thanks

Avatar
Discard
Author

Thank you Niyas, and what i do to give an user the employee rule (This user is existed before) ?

Check this code, whether it can help you or not,

new_parent_user = user_rec.sudo().create({

'name': parent_user_name,

'login': parent_login,

'password': self.phone

})

for group_parent in new_parent_user.groups_id:

group_parent.write({'users': [(3, new_parent_user.id)]})

user_group1 = self.env.ref('module_name.group_name')

if user_group1:

user_group1.users = user_group1.users + new_parent_user

Author

Thank you, i will check it

Author

The problem is when i use this insctruction, the previous goups deleted :

vals['groups_id'] = (4,user_group_client.id)

What i should do to save the previous group ?

what you are looking to add a new group ?