Перейти к содержимому
Меню
Чтобы взаимодействовать с сообществом, необходимо зарегистрироваться.
Этот вопрос был отмечен
6 Ответы
112538 Представления

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

Related Posts Ответы Просмотры Активность
4
мар. 20
23760
1
нояб. 24
1486
3
апр. 23
18035
1
дек. 22
14182
1
нояб. 20
4326