Trợ giúp


Where is defined the user_id field of the model hr_employee?

Pascal Tremblay

Hello all,

I'm on odoo 10.

1) After an hour searching, I can't find where is declared the many2one field user_id of the model hr_employee... Where is the 'user_id = fields....' in the Python code?

2) Also, still in the model hr_employee, why this sql works :

select distinct("resource_id") FROM "hr_employee" where "resource_id" is not null

But not this one (ERROR:  column "user_id" does not exist) :

select distinct("user_id") FROM "hr_employee" where "user_id" is not null

Both fields resource_id and user_id are many2one fields on the model hr_employee...

Thanks for you help!

Ảnh đại diện
Huỷ bỏ
2 Câu trả lời

Hi Pascal,

The user_id (Related User) field is created in resource module resource.resouce object and hr.employee inherits resource object.

So basically you have to use join query to fetch the user_id field.

SELECT resource.user_id FROM hr_employee emp 
LEFT JOIN resource_resource resource ON

Hope this will help you,


Ảnh đại diện
Huỷ bỏ
Fidel Jimenez Sanzano
Best Answer

The employee is a resource and the resource is the one that has a user_id. Following with the example in sql should be.

Select distinct user_id 
from hr_employee e inner join resource_resource res ON
where user_id is not null

Or use the ORM employee.user_id

Sorry my english is not very good

i hope this are usefull for you

Ảnh đại diện
Huỷ bỏ