Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
5 Odpovědi
4380 Zobrazení
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

Avatar
Zrušit
Autor

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)

Autor Nejlepší odpověď

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


Avatar
Zrušit
Nejlepší odpověď

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

Avatar
Zrušit
Nejlepší odpověď

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

Avatar
Zrušit
Nejlepší odpověď

Hi Ahmed:

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

self.env.user.department_id.id
Avatar
Zrušit
Related Posts Odpovědi Zobrazení Aktivita
2
srp 25
7494
2
čvc 24
15736
2
zář 23
8578
2
led 23
2520
1
srp 22
5465