This question has been flagged
6 Replies
2929 Views

Hi,

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')
    @api.one
    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?

Thanks.

Avatar
Discard
Best Answer

Hello,

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
Avatar
Discard
Best Answer

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

Avatar
Discard
Best Answer
    @api.one
    def do_shop(self):
        user_id = self.env.user.id        
        print 'user_id', user_id         
        return True
Avatar
Discard
Best Answer

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
self.env.uid

Avatar
Discard
Best Answer

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

Item 1 is not workable.