コンテンツへスキップ
メニュー
この質問にフラグが付けられました
3 返信
11335 ビュー

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,
    }

アバター
破棄
関連投稿 返信 ビュー 活動
2
8月 24
1692
2
6月 22
3746
2
2月 24
14481
1
9月 19
6166
1
4月 17
5553