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

I have a list and form views, I can select one element in the list to access the form.

The form has fields A and B (both many2one), when A has one value B must filter by these value. 

When I change the value in A, I can use function on_change to set the domain in B. 

The problem comes when I access this form view from the list and A already has a value, I don't know how to set the domain then, I have tried with default_get and read functions, but I'm not successful.

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

I was making it too complicated, I found the solution on https://www.odoo.com/forum/help-1/question/problem-with-a-domain-many2one-22314

 

It was enough adding the domain to the field, the problem is that I was writing it as: 

domain=[('B1.B2', '=', A)]

And it raised an error because A wasn't recognized. I changed to 

domain="[('B1.B2', '=', A)]"

Now it works very smooth.

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

You can follow this: https://youtu.be/XGqXEL2qQmE 

Hope it helps, Thanks

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

Pau, you need to developed an on_change method on the field which change will trigger the domain change.  This page provides an overview of how on_change can be developed.

อวตาร
ละทิ้ง
ผู้เขียน

Thanks John, I don't have any problem with the on_change. If the user changes a field, then there's no problem. The problem is if the user doesn't change the field. The field has content already, but nobody changed the content.

Related Posts ตอบกลับ มุมมอง กิจกรรม
1
มี.ค. 15
4719
1
พ.ย. 24
1672
1
ก.ย. 21
9450
1
ม.ค. 24
17062
0
มี.ค. 15
3327