Odoo Help


How can i get logged user name automatically into field ?

Dr Obx
on 9/29/15, 8:12 AM 1,156 views


How can I get user name (like create_uid which automatically sets up user logged in as a default value) in custom field ?

Juan Muñoz
On 9/29/15, 10:23 AM

Hi Dr Obx,

If you see, when creates an invoice, the sales person field is completed automatically by the user logged. 

Then, you should go to your attribute in the python file and put this: 

you_field_name= fields.Many2one('res.users', string='your_string_field', track_visibility='onchange',

readonly=True, states={'draft': [('readonly', False)]}, default=lambda self: self.env.user)

-If you want to see more you can check it in /addons/account/account_invoice.py in line 304 (attribute user_id).

Hope this answer helps you! ^^


Yes, good point. Why I did not checked how it works in other modules instead :) Silly Me :) The question is, why Once I add default=lambda self: self.env.user to the field definition in py and trying upload CSV file immediately it gives me an error ?

Dr Obx
on 9/29/15, 10:48 AM

Unknown error during import: : Wrong value for iprodstep.log.employee_id: res.users(1,) at row 2 Resolve other errors first

Dr Obx
on 9/29/15, 10:50 AM

However none of those fields not exist in CSV so it's not loaded...

Dr Obx
on 9/29/15, 10:51 AM

Can you copy the piece of code that you think may fail here please? I do not know if I can help you more but I'll try. Try putting only: self.env.user

Juan Muñoz
on 9/29/15, 10:59 AM

Hi Juan, I just added "default=lambda self: self.env.user" into the line so it is like that:

	employee_id = fields.Many2one('hr.employee', string='Entered by', required=False, default=lambda self: self.env.user )
	technician_id = fields.Many2one('hr.employee', string='Technician', required=False, default=lambda self: self.env.user)
	packing_id = fields.Many2one('hr.employee', string='Packed by', required=False, default=lambda self: self.env.user)
	warehouse_id = fields.Many2one('hr.employee', string='Picked by', required=False, default=lambda self: self.env.user)
I did not even touch "import" procedure so why it generate error when I'm trying to validate CSV before loading ? I think I know. Maybe the problem can be solved other way. I can create a separate class which will include employee, technician, packing and warehouse then inherit in main/parent class ?
Dr Obx
on 9/30/15, 6:31 AM

As I said, created separate class, inherited by main class but it still won't work. Still getting error whilst I'm loading data from CSV :( so it doesn't help :(

Dr Obx
on 9/30/15, 7:45 AM

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: 9/29/15, 8:12 AM
Seen: 1156 times
Last updated: 9/29/15, 10:23 AM