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

I want to assign a employee to a task:


request.env['project.task'].sudo().with_context(check_move_validity=False).create({

 'name': task['name'], 

'description': task['desc'], 

'project_id': project_id, 

'user_id': get_or_create_employee('John Doe')  

})


def get_or_create_employee(employee_name):

    e_exists = request.env['hr.employee'].search([('name', '=', employee_name)]) 

    if e_exists: 

        employee_id = e_exists.id 

    else: 

        new_employee =     request.env['hr.employee'].sudo().with_context(check_move_validity=False).create({

 'name': employee_name

}) 

        employee_id = new_employee.id 

    return employee_id


The new employee is created but not assigned to the task.

Instead the Administrator is assigned to the task.

I get no errors.


Thank you







Avatar
Discard
Best Answer

Hi,

Assigned to field in the task model is a many2one field of res.users not hr.employee. So instead of creating/searching employee, you have to search inside users model and set that value to the user_id field in the task model.

Thanks

Avatar
Discard
Author

Alright, thank you

Related Posts Replies Views Activity
1
Nov 24
1479
1
Nov 24
1183
2
Sep 24
1046
1
Aug 24
2448
3
Aug 24
2681