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

Hello, 

What I want to do is show filtered One2many fields using tree view.


I have One2many fields like below

subscription_line_ids = fields.One2many('subscription.subscription.line', 'subscription_id')

And subscription.subscription.line model has stage field 

stage = fields.Selection(
[('draft', 'Draft'),
('in progress', 'In Progress'),
('closed', 'Closed')],
default='draft')

so I tried using domain on xml like below

<field name="subscription_line_ids"
domain="[('subscription_line_ids.stage', '=', 'in progress')]"
>
<tree editable="bottom">
<field name="stage" />
<field name="close_reason_id"/>
</tree>
</field>


But the domain not working


How can I solve this problem?


I know I can do on *.py but I don't want to make fields for every stage.


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

In python I think you can do fields.One2many('subscription.subscription.line', 'subscription_id', domain=[('stage', '=', 'in progress')]), so try to use it xml.
<field name="subscription_line_ids" domain="[('stage', '=', 'in progress')]" >

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

yes it work in python. but same thing not work on xml.

in odoo 12 I use it in xml to filter M2M fields so it should work for O2M. But maybe it was on Odoo 10. So hope you figure it out and post how you did it.

ผู้เขียน

I decided to use domain on *.py. I spent a couple of days on this. I can't spend any more time on this.

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


https://www.odoo.com/forum/help-1/question/how-to-write-this-domain-for-a-one2many-field-on-a-view-114226
อวตาร
ละทิ้ง
ผู้เขียน

I don't know it is my case.

the answer of the link not show me how to use domain.

Related Posts ตอบกลับ มุมมอง กิจกรรม
2
ต.ค. 21
9104
1
มิ.ย. 15
4120
2
มิ.ย. 15
3690
1
ก.ย. 18
300
0
ก.ย. 24
1263