In my module I have a many2one field to select workers for a particular task. According to the requirement that field should only display the workers in the current user's department. Simply this is the code,
_columns = {
'employee_id': fields.many2one('hr.employee', 'Employee'),
}
My problem is how to perform such filteration for a field on load? I tried using functional field in a domain in view xml. but It seems functional field gets its value when saving the particular record.
Also I tried adding domain to the field itself, here get_current_user_department is a function returns the department id
_columns = {
'employee_id': fields.many2one('hr.employee', 'Employee',domain=[('department_id.id','=',get_current_user_department)]),
}
This generates following error,
TypeError: is not JSON serializable
Any suggestion to make this work? Thanks