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 assign the logged in user as a default value? [Closed]

By
Eric
on 2/28/14, 1:53 PM 1,816 views

The Question has been closed

by
Sudhir Arya (SA)
on 03/01/2014 02:32:33

Hello, I am trying to find a way to make the logged in user as a default value for a new record.
Is there a way to do that using the _defaults variable in the class file?

I am using the _defaults variable to set default values for other fields, but I dont know how to dynamically set my 'status_by' field to the logged in user id. Thank you for your help

1

Sudhir Arya (SA)

--Sudhir Arya (SA)--
10150
| 6 8 8
Ahmedabad, India
--Sudhir Arya (SA)--

Working as an OpenERP/Odoo developer and a Team Leader 

Top 5 Odoo contributor On Stackoverflow

LinkedIn

Blog

Stackoverflow

Sudhir Arya (SA)
On 2/28/14, 3:49 PM

Hi Eric,

You can assign current logged in user by following way also.

_defaults = {
    'status_by': lambda obj, cr, uid, context: uid,
}

Awesome! I didn't even think of that, but makes total sense. thank you

Eric
on 2/28/14, 6:45 PM
0
Eric
On 2/28/14, 2:25 PM

Okay so I found an answer at this url:

http://stackoverflow.com/questions/19293630/what-is-the-reason-of-using-defaults-and-lambda-in-python-for-openerp-developme

So basically I used this example, but modified a couple things so it worked with my app:

_defaults = {
    'status_by': lambda self,cr,uid, context: self.pool.get('res.users').browse(cr, uid, uid, context).id,
}

The lambda is an inline function that returns the id from the res_users table

About This Community

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

Question tools

0 follower(s)

Stats

Asked: 2/28/14, 1:53 PM
Seen: 1816 times
Last updated: 3/16/15, 8:10 AM