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

Hi, I am using Odoo 14 and in 'res.users' I have added one new One2many field.

One2many field details:

name: test_ids

model: test.users

fields: name, user_id, employee_id


In form view I have added context on One2many field to set default user but it is not working.field name="test_ids" context="{'default_user_id': active_id}"

I need domain on employee_id that [('user_id', '=',  user_id )].

First user_id means employee's user_id and second user_id means One2many's user_id


I can't see any employee in One2many's employee_id because when creating One2many record by clicking on Add an item, the the user_id of One2many is blank. Because the the following context is not working in Odoo 14.

context="{'default_user_id': active_id}"


Please help me if any other solution for that.


Thanks.


Regards,

Hemangi.

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

you can provide default value from field definitions like

user_id
= fields.Many2one('res.users', default=lambda self: self.env.user.id)

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

Hi,

You can get the current user_id from the environment. 

for example :

user_id = self.env.uid

which the user_id will be the id of the current logged user.

Regards

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
1
ก.พ. 22
2163
1
เม.ย. 24
1456
1
ก.ค. 22
1707
1
พ.ย. 19
7968
1
มี.ค. 24
2768