تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
2 الردود
1759 أدوات العرض

I want to set field invisible, depends on value of many2one field:

field name="kind"/>

field name="render_path" invisible="kind != 'Render'"/>


but this field shows randomly.

 Any solutions?

الصورة الرمزية
إهمال
أفضل إجابة

Hi,


Use the invisible attribute to make your field invisible based on the value of many2one field.

<field name="your_field_to_hide" invisible="many2one_field == 1"/>


In this example you can specify the id of the value of the many2one field.



Hope this helps.


الصورة الرمزية
إهمال
الكاتب

It's working. Thanks a lot.

أفضل إجابة

Hi Piotr:

The direct value of a relation field(M2o,X2m) actually mapping the id of the co-model, not the 'name'.  And i suggest to use attrs + domain to determine the attr 'invisible' , you can try:

    <field name="kind"/>      
​(PS: suppose the field 'kind' is Many2one,  it's better defining it like 'kind_id'.)
 
  <field name="render_path" attrs="{'invisible': [('kind', '!=', <the 'Render' id in co-model>)]}"/> 

  

The domain doesn't support a relational syntax(ie: model.field),  so if you still want use the name like 'Render' as dependency,  you can additionally define a related field in the model:

    kind_name = fields.Char(related='kind.name')

and then in xml file:

    <field name="kind_name" invisible="1"/>  (this field must in the view)
   <field name="render_path" attrs="{'invisible': [('kind_name', '!=', 'Render' )]}"/>  
الصورة الرمزية
إهمال
المنشورات ذات الصلة الردود أدوات العرض النشاط
1
يوليو 25
659
0
نوفمبر 24
1305
0
أكتوبر 24
1608
1
أكتوبر 24
2257
0
أكتوبر 24
1343