Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
2 ตอบกลับ
6487 มุมมอง

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.


อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

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,
}


อวตาร
ละทิ้ง
ผู้เขียน คำตอบที่ดีที่สุด

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

ผู้เขียน

Thanx

Related Posts ตอบกลับ มุมมอง กิจกรรม
1
พ.ย. 23
1451
How to Restore a Deleted User Account แก้ไขแล้ว
2
ม.ค. 23
5913
1
พ.ย. 19
7519
1
เม.ย. 16
4030
0
มี.ค. 15
3621