Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
3 Risposte
11331 Visualizzazioni

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

Avatar
Abbandona
Risposta migliore

Try the following:

self.env.user.name

Avatar
Abbandona
Risposta migliore

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
Abbandona
Autore

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

Risposta migliore

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
Abbandona
Post correlati Risposte Visualizzazioni Attività
2
ago 24
1690
2
giu 22
3745
2
feb 24
14481
1
set 19
6165
1
apr 17
5548