How can I get the id of the current logged user in a new field in res.users?
userid = fields.Char(??)
Thank you
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
How can I get the id of the current logged user in a new field in res.users?
userid = fields.Char(??)
Thank you
Hi,
You can define a field like this,
current_user = fields.Many2one('res.users','Current User', default=lambda self: self.env.user)
Also you can get the current user id in python by self._uid and in xml you will get current uid by user.id.
Even you can create a compute field and write the user id into that field. Or you can use the defaults.
_defaults={
'current_uid':lambda self, cr, uid, ctx=None: uid
}
Thanks
Mubaris , after the Ankit 's code , you have to do :
user.login
That's it :)
Try this
userid = fields.Char("User ID",default=lambda self: self.env.user.name)
Hello all,
i want to know is there any way to get master password of odoo using programatically??
Thanks in advance
hi,
u can use self._uid u will get current login person user id or u can use
default=lambda self: self.env.user inside field.
Hello,
You can use below code.
context = self._context
current_uid = context.get('uid')
user = self.env['res.users'].browse(current_uid)
Hope this help you.
Best Thanks,
Ankit H Gandhi.
hi Ankit ,i tried your code .it helps but it doesn't give the current user name,when i print(user) it shows "res.user() " as the output .thank you
Tạo tài khoản ngay hôm nay để tận hưởng các tính năng độc đáo và tham gia cộng đồng tuyệt vời của chúng tôi!
Đăng kýBài viết liên quan | Trả lời | Lượt xem | Hoạt động | |
---|---|---|---|---|
|
4
thg 3 20
|
23782 | ||
|
1
thg 11 24
|
1501 | ||
|
3
thg 4 23
|
18074 | ||
How to add an user to a group
Đã xử lý
|
|
1
thg 12 22
|
14210 | |
|
1
thg 11 20
|
4345 |
Get current logged in user id: https://goo.gl/KzXLak