Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
2 ตอบกลับ
10422 มุมมอง

How to get the job_id of the user_id linked to the employee_id

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

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

Related Posts ตอบกลับ มุมมอง กิจกรรม
2
ต.ค. 25
60
1
ก.ย. 25
307
3
ก.ย. 25
480
1
ส.ค. 25
616
1
ก.ค. 25
1009