콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
3 답글
11352 화면

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
1709
2
6월 22
3760
2
2월 24
14491
1
9월 19
6180
1
4월 17
5569