Skip to Content
Меню
Вам необхідно зареєструватися, щоб взаємодіяти зі спільнотою.
Це запитання позначене
3 Відповіді
11389 Переглядів

iam logged in some user like johnsmith. so here how to print current logged user name. how it's done in odoo v8?

Аватар
Відмінити
Найкраща відповідь

Try the following:

self.env.user.name

Аватар
Відмінити
Найкраща відповідь

current user is nothing but uid in python code Eg

def buttton_click(cr,uid,ids,context=None):

rec=self.pool.get('res.user').browse(cr,uid,uid)

print rec.login

Аватар
Відмінити
Автор

but browse pass only the list of id's. i dnt know current user id. In this case how i retrieve?

that uid is the id we should pass.. just try it u will get to know..

Найкраща відповідь

This little function will get you the username you're logged in with: 

def _get_user_name(self, cr, uid, *args):
        user_obj = self.pool.get('res.users')
        user_value = user_obj.browse(cr, uid, uid)
        return user_value.login or False

And you can then call it from Python code and do with it whatever you want. For example to print it in a field as default value:

defaults = {
     'username_print': _get_user_name,
    }

Аватар
Відмінити
Related Posts Відповіді Переглядів Дія
2
серп. 24
1727
2
черв. 22
3772
2
лют. 24
14514
1
вер. 19
6196
1
квіт. 17
5587