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

I have a Many2one field that has a domain filter with 2 conditions that it needs to meet. There should only be one value to select in that Many2one field that meets those 2 conditions. Since there is only one value to select from, I would like that Many2one field to automatically select that specific value or default to that value. Is there a way to do this?

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

Hi,

Either you can set the value from an onchange function or from the default get function or by making a computed field.

I think here it is better to set the value using the default get method.

Reference: https://www.youtube.com/watch?v=OBw0PFhOAnM

Thanks

อวตาร
ละทิ้ง

@api.model

def default_get(self, fields):

res = super(ClassName, self).default_get(fields)

#if conditions are met

res['field_name'] = id_of_many2one_field

return res

คำตอบที่ดีที่สุด

@api.model
def default_get(self, default_fields):
res = super(Classname, self).default_get(default_fields)
res['m2o_field'] = (4, ID) # (4, ID of m2o field)
return res



อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
1
ธ.ค. 21
2268
get the value of a field of other model แก้ไขแล้ว
3
มี.ค. 24
7258
3
ส.ค. 25
2074
2
ก.พ. 24
2463
2
พ.ย. 22
4929