how to get current user id in a field in Odoo online version?
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- ลูกค้าสัมพันธ์
- e-Commerce
- ระบบบัญชี
- สินค้าคงคลัง
- PoS
- Project
- MRP
คำถามนี้ถูกตั้งค่าสถานะ
I tried to solve it by myself. Thanks for all your replies.
Hello Techy Mills,
For an online version, you can use the Automated Actions for this.
Activate Developer mode and Go to Settings -> Technical -> Automation -> Automated Actions
When creating an Automated action, you have the option to select the
1. Related Document Model.
2. When to Run
Here you have Option In the When to Run field to select when the operation should be executed.
Like: On Creation, On Update, Based on form Modification, etc.
If you want the field the value as default, then go for Based on form Modification
1. Value as Default
--------------------------------------------
Based on form Modification. It is same as the onchange method. Here we have to apply a trick to get the value as default.
What is the trick? I will explain, Create a new dummy field and trigger the onchange method based on that Field. and hide that field from the view. then this onchange method will call only at the time of creation. (we can't change the value of that field because it is hidden from view. so it will call the onchange method only one time)
Next, there is Actions Tab in the Automated Actions. under that Tab, you have Server actions to run field.
Create a server action. Select Action To Do field as Execute Python Code. The Base Model field is the same model.
In the python code, put like this
record['x_your_user_field'] = env.user.id
This is the way to achieve "Value as default".
--------------------
On Creation and On Update is more easy.
Here select When to Run as On Creation & On Update respectively. No need for Dummy field. Next steps are the same as the first way(Onchange)
Thanks & Regards
Hi,
You can get the current user by this code,
user_id = fields.Many2one('res.users', 'Me', default=lambda self: self.env.user)
Thanks
I cannot access the model file in odoo online. Any other idea?
สนุกกับการพูดคุยนี้ใช่ไหม? เข้าร่วมเลย!
สร้างบัญชีวันนี้เพื่อเพลิดเพลินไปกับฟีเจอร์พิเศษและมีส่วนร่วมกับคอมมูนิตี้ที่ยอดเยี่ยมของเรา!
ลงชื่อ
Get current logged in user id: https://goo.gl/KzXLak