Odoo Help

0

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

By
Qinn Zoou
on 8/20/16, 5:34 AM 481 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.

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

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
0
Giezel Esteves
On 8/22/16, 11:10 PM
    @api.one
    def do_shop(self):
        user_id = self.env.user.id        
        print 'user_id', user_id         
        return True
0
Ajeet Yadav
On 8/20/16, 6:59 AM

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

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

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.

Register

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)

Stats

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