跳至内容
菜单
此问题已终结
3 回复
11383 查看

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
1719
2
6月 22
3767
2
2月 24
14505
1
9月 19
6192
1
4月 17
5581