Odoo Help

Welcome!

This community 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.

0

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

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

--Ahmed M.Elmubarak--
2988
| 5 3 5
Sudan
--Ahmed M.Elmubarak--


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

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

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