Odoo Help


How to get the current login user in business logic in ver9.0?

Qinn Zoou
on 8/20/16, 5:34 AM 588 views


I have create a model with the code below:

from openerp import models, fields, api
class shop(models.Model):
    _name = 'training02.shop'
    name = fields.Char(string='Shop Name', required=True)
    address = fields.Text(string='Address')
    def do_shop(self):
        # The code that get login user
        # ......
        return True

I want to get login user in the function "do_shop".

Are there anyone can give me some advises?


--Ahmed M.Elmubarak--

Ahmed M.Elmubarak
On 8/20/16, 8:35 AM


For cr [database curser] , uid [current user id] ,  and context you can use:

self._cr or self.env.cr
self._uid or self.env.uid
self._context or self.env.context
Giezel Esteves
On 8/22/16, 11:10 PM
    def do_shop(self):
        user_id = self.env.user.id        
        print 'user_id', user_id         
        return True
Ajeet Yadav
On 8/20/16, 6:59 AM

You can get loged in user uid by self._uid.

Niraj Pajwani
On 8/22/16, 11:42 AM

Hello Qinn Zoou,
You can get the current loged in user record by:
1) self.user.id
2) self.env.uid
3) self._uid

Item 1 is not workable.

Qinn Zoou
on 8/22/16, 11:00 PM
Mostafa Abd El Fattah
On 8/20/16, 11:22 AM

try to debug the self and you will know everything about the logged user with it's company
you can obtain it whether in python or XML

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.


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)


Asked: 8/20/16, 5:34 AM
Seen: 588 times
Last updated: 8/22/16, 11:10 PM