Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
5 Trả lời
4406 Lượt xem
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

Ảnh đại diện
Huỷ bỏ
Tác giả

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)

Tác giả Câu trả lời hay nhất

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


Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Hi Ahmed:

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

self.env.user.department_id.id
Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 8 25
7545
2
thg 7 24
15826
2
thg 9 23
8648
2
thg 1 23
2554
1
thg 8 22
5550