Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
3 Replies
11345 Tampilan

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

Avatar
Buang
Jawaban Terbai

Try the following:

self.env.user.name

Avatar
Buang
Jawaban Terbai

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

Avatar
Buang
Penulis

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..

Jawaban Terbai

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

Avatar
Buang
Post Terkait Replies Tampilan Aktivitas
2
Agu 24
1706
2
Jun 22
3751
2
Feb 24
14486
1
Sep 19
6176
1
Apr 17
5567