تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
6 الردود
112485 أدوات العرض

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
مارس 20
23724
1
نوفمبر 24
1457
3
أبريل 23
18000
1
ديسمبر 22
14157
1
نوفمبر 20
4304