This question has been flagged
2 Replies
7702 Views

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!

Avatar
Discard
Best Answer

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 res.id=emp.resource_id

Hope this will help you,

Thanks

Avatar
Discard
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 e.resource_id=res.id
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

Avatar
Discard