Odoo Help

0

How to assign the logged in user as a default value? [Closed]

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

The Question has been closed

by
Sudhir Arya (ERP Harbor Consulting Services)
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 (ERP Harbor Consulting Services)

--Sudhir Arya (ERP Harbor Consulting Services)--
11456
| 6 8 8
Ahmedabad, India
--Sudhir Arya (ERP Harbor Consulting Services)--

• Co-Founder & Co-Owner at ERP Harbor Consulting Services

• ERP Consultant / ERP Customization / TechnoFunctional Expert

• Sound knowledge in Python, Odoo (Open ERP), XML, PostgreSQL

• Domain knowledge of Sale Management, Purchase Management, Warehouse Management, Manufacturing, Multi Company Configuration & Management, HR Management, Medical Management, Construction Management, Education Management, Point of Sale, Third Party Integrations

• Positive attitude and quick Learner

• Good analytical skill, quick bug and issue tracing and find the solution

• Good knowledge and experience in payment gateway integration with Odoo

• Ready to accept new challenges

• Active Memeber On Stackoverflow 

LinkedIn

Blog

Stackoverflow

Sudhir Arya
ERP Harbor Consulting Services
skype: 
sudhir@erpharbor.com 
Sudhir Arya (ERP Harbor Consulting Services)
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 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

0 follower(s)

Stats

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