Skip to Content
Menu
This question has been flagged
6 Replies
3922 Rodiniai

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.

Portretas
Atmesti
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
Portretas
Atmesti
Best Answer

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

Portretas
Atmesti
Best Answer
    @api.one
    def do_shop(self):
        user_id = self.env.user.id        
        print 'user_id', user_id         
        return True
Portretas
Atmesti
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

Portretas
Atmesti
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
Portretas
Atmesti
Autorius

Item 1 is not workable.