跳至內容
選單
此問題已被標幟
3 回覆
11344 瀏覽次數

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
1706
2
6月 22
3750
2
2月 24
14486
1
9月 19
6176
1
4月 17
5566