How to get the job_id of the user_id linked to the employee_id
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Contabilidad
- Inventario
- PoS
- Project
- MRP
Se marcó esta pregunta
Hi,
If you have a user id with you, then if you wan to find the job _id of the employee whose related user is this user_id, you can do like this,
suppose uid has the id of the user, then
employee_rec = self.env['hr.employee'].search([('user_id', '=', uid)])
job_id = employee_rec.job_id.id
If the user is assigned to more than one employee, then you have to use for loop to iterate over the employee_rec or use limit=1 in search condition.
If you have the employee id with you, then you can get the job id easily , let emp_id is the id of employee
employee_rec = self.env['hr.employee'].search([('id', '=', emp_id)])
job_id = employee_rec.job_id.id
To get the current user name and his job name in the qweb , try the below code.
<span t-esc="user.name"/>
<t t-foreach="request.env['hr.employee'].search([('user_id', '=', user.id)])" t-as="obj">
<t t-esc="obj.job_id.name"/>
</t>
Thanks
I have this NameError: name 'self' is not defined
my_employee = self.env['hr.employee'].search([('user_id', '=', create_uid)])
my_job_id = my_employee.job_id.id
From where you calling this code ? Try to print self and see whats there in it
class PurchaseOrder(models.Model):
_inherit = 'purchase.order'
my_employee = self.env['hr.employee'].search([('user_id', '=', create_uid)])
my_job_id = my_employee.job_id.id
only this much lines ? can you add the full code in this class ? not defined any function ?
yes only this much lines! and no i dont defined any function!!! i'm just trying something fast and want to get the job id but im looking for xml solution too if you can help
i need to give job_id to this <span t-field="o.create_uid.name"/>
Actually you can't do it like this,
can you tell what exactly you are looking for
in a report i want to mention the user who created it and his job
For getting the current user name and his job name, you try this,
<span t-esc="user.name"/>
<t t-foreach="request.env['hr.employee'].search([('user_id', '=', user.id)])" t-as="obj">
<t t-esc="obj.job_id.name"/>
</t>
it works so nice! thank you so much
¿Le interesa esta conversación? ¡Participe en ella!
Cree una cuenta para poder utilizar funciones exclusivas e interactuar con la comunidad.
RegistrarsePublicaciones relacionadas | Respuestas | Vistas | Actividad | |
---|---|---|---|---|
|
0
mar 25
|
36 | ||
|
0
mar 25
|
429 | ||
|
1
feb 25
|
583 | ||
|
0
feb 25
|
357 | ||
|
1
may 25
|
572 |