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.

1

How can I add automatically name of the current user to the record

By
Dr Obx
on 5/1/15, 10:02 AM 418 views

How can I add automatically name of the current user to the record if user create a record (warehouse/products).
I can add:
'user_id': fields.many2one("res.users", "Created by", required=True,),
field but user needs to pick his name from list. I would like to be done automatically.

Without any user action.


0

Jérémy Kersten (jke)

--Jérémy Kersten (jke)--
2983
| 3 2 5
Jodoigne, Belgium
--Jérémy Kersten (jke)--

Jérémy is a member of the core R&D team since september 2013. He developed several projects for OpenERP version 8 including the eCommerce, the Google Calendar synchronization and the new product variants/configurator. Now, he manages Odoo website and themes for saas.

Jérémy Kersten (jke)
On 5/1/15, 11:34 AM

Hi,


By default, orm save in create_uid, create_date the creator of the record with date

and in the write_uid, write date, the last user which edit the record...


Else you can add a default value default_user_id = uid in the action or directly in the model python with a lambda


 _defaults = {
'user_id': lambda self, cr, uid, ctx: uid,
}


0
Dr Obx
On 5/1/15, 12:03 PM

Yes and that's what i've done. Added only <field="write_uid" readonly="1"/> and it work fine but this option with _defaults = {} looks more professional :)

Thank you :)

Note sure that more professional, create_uid is exactly what you are looking for, so I don't see the interest to duplicate the information. But for the next time, you know of to set the default value with current user... Have fun with Odoo

Jérémy Kersten (jke)
on 5/1/15, 12:05 PM

Thanx

Dr Obx
on 5/2/15, 9:28 AM

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

2 follower(s)

Stats

Asked: 5/1/15, 10:02 AM
Seen: 418 times
Last updated: 5/1/15, 2:00 PM