Odoo Help


Get Current User ID

on 12/22/14, 2:18 AM 10,640 views

I have a field many2one relation to res.users like this : 'salesman':fields.many2one('res.users', string='Salesman').

I want default value it field is current user ID (current login) like Administrator, Custom User, etc. How to do it?



under the _defaults you can write the following code


'salesman':lambda self, cr, uid, ctx=None: uid


hope this helps !!

In the 8.0 API this would be something like this: salesman = fields.Many2one( string="Salesman", comodel_name='res.users', default= lambda self: self.env.user.id )

Rubén Cabrera
on 11/16/15, 4:42 PM
On 12/22/14, 4:57 AM

Why don't you take a look at sale.order model from odoo/addons/sale/sale.py.  It has user_id defined which - AFAIK - mimics what you need.  It uses _default as well as @Emipro had suggested.

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: 12/22/14, 2:18 AM
Seen: 10640 times
Last updated: 6/7/17, 2:41 AM