跳至内容
菜单
此问题已终结
5 回复
4420 查看
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
形象
丢弃
相关帖文 回复 查看 活动
2
8月 25
7572
2
7月 24
15879
2
9月 23
8695
2
1月 23
2589
1
8月 22
5618