Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
5 ตอบกลับ
4456 มุมมอง
dep = fields.Many2one('hr.department', string='Administrative unit',)

ex. if user is ahmed who created a record in sales department so the field dep in this record returns sales

thanks in advance

อวตาร
ละทิ้ง
ผู้เขียน

this code is worked but users other than admin :) so solved thanks all

dep = fields.Many2one('hr.department', string='Administrative unit', default=lambda self: self.env.user.employee_ids.department_id.id, readonly=True)

ผู้เขียน คำตอบที่ดีที่สุด

Hi Paresh
trying

default=lambda self: self.env.user.department_id <-- or with .id -->

says department_id doesnot exist in res.users cause it does not

i tried

default=lambda self: self.env.user.employee_ids.department_id

no errors but no reseult :)

i will try what muhammad send but i will appreciate if you have solution :)

thanks


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

https://www.odoo.com/fr_FR/forum/aide-1/question/how-to-get-current-user-name-into-field-problem-solved-129261

https://www.odoo.com/fr_FR/forum/aide-1/question/get-current-user-s-company-id-94026

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

https://www.odoo.com/fr_FR/forum/aide-1/question/how-to-get-current-user-name-into-field-problem-solved-129261

https://www.odoo.com/fr_FR/forum/aide-1/question/get-current-user-s-company-id-94026

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

Hi Ahmed:

The following should return the department id of the current user.

self.env.user.department_id.id
อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
2
ส.ค. 25
7644
2
ก.ค. 24
15971
2
ก.ย. 23
8809
2
ม.ค. 23
2632
1
ส.ค. 22
5693