Odoo Help

0

how to retrieve current logged user name in odoo v8?

By
Demirel yakito
on 1/19/15, 8:52 AM 3,776 views

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

1

Try the following:

self.env.user.name

1
Anand
On 1/19/15, 8:57 AM

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?

Demirel yakito
on 1/19/15, 8:59 AM

that uid is the id we should pass.. just try it u will get to know..

Anand
on 1/19/15, 9:01 AM
1
Yenthe
On 1/19/15, 9:16 AM

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

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)

Stats

Asked: 1/19/15, 8:52 AM
Seen: 3776 times
Last updated: 3/16/15, 8:10 AM