Yardım

2

Where is defined the user_id field of the model hr_employee?

Avatar
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!

Avatar
Vazgeç
2 Yanıtlar
4

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
Vazgeç
1
En iyi cevap

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
Vazgeç