跳至内容
菜单
此问题已终结
6 回复
112414 查看

How can I get the id of the current logged user in a new field in res.users?


userid = fields.Char(??)


Thank you

形象
丢弃

Get current logged in user id: https://goo.gl/KzXLak

最佳答案

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

相关帖文 回复 查看 活动
4
3月 20
23668
1
11月 24
1425
3
4月 23
17973
1
12月 22
14129
1
11月 20
4287