Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
3 ตอบกลับ
11343 มุมมอง

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

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
2
ส.ค. 24
1703
filling a field with the current user แก้ไขแล้ว
2
มิ.ย. 22
3749
how to get the logged user แก้ไขแล้ว
2
ก.พ. 24
14485
1
ก.ย. 19
6176
1
เม.ย. 17
5566