Skip to Content
Menú
This question has been flagged
1 Respondre
3244 Vistes

name="out_doc" attrs="{'invisible': ['|',('out_doc', '=', False),('for_country','=','us')]}">
editable="bottom">
name="lab_test"/>
name="name" optional="hide"/>
name="stop_check" optional="hide"/>
name="product_id"/>
name="att_file" widget="binary" attrs="{'invisible': [('att_file', '!=', False)]}"
options="{'accepted_file_extensions': '.jpeg,.pdf,.jpg,.png'}" filename="name"
string="Attachment"/>
name="att_file" widget="binary" attrs="{'invisible': [('att_file', '=', False)]}"
options="{'accepted_file_extensions': '.jpeg,.pdf,.jpg,.png'}" filename="name"
string="Attachment"/>






this is my code in this code the attribute invisible is working on for_country but didn't do invisible the field when i don't record in it.

Avatar
Descartar
Autor

<field name="out_doc" attrs="{'invisible': ['|',('out_doc', '=', False),('for_country','=','us')]}">
<tree editable="bottom">
<field name="lab_test"/>
<field name="name" optional="hide"/>
<field name="stop_check" optional="hide"/>
<field name="product_id"/>
<field name="att_file" widget="binary" attrs="{'invisible': [('att_file', '!=', False)]}"
options="{'accepted_file_extensions': '.jpeg,.pdf,.jpg,.png'}" filename="name"
string="Attachment"/>
<field name="att_file" widget="binary" attrs="{'invisible': [('att_file', '=', False)]}"
options="{'accepted_file_extensions': '.jpeg,.pdf,.jpg,.png'}" filename="name"
string="Attachment"/>
<button name="open_file_preview" attrs="{'invisible': [('att_file', '=', False)]}" string="Preview File" type="object" class="oe_inline"/>
</tree>
</field>

Autor

this is complete code

Best Answer

Hi Mohsan Raza,


To address the situation where you want to make a One2many field invisible if it contains no data, you can follow these steps:


1. Add a Boolean (True/False) field to the model. This field will serve as an indicator of whether the One2many field has data or not.


2. Write a compute method for the Boolean field. In this method, you can check if the One2many field contains any records. If it does, set the Boolean field to True; otherwise, set it to False.


3. In the XML view definition, apply the `attrs` attribute to the One2many field. Use this attribute to conditionally make the One2many field invisible based on the value of the Boolean field.


This approach allows you to dynamically control the visibility of the One2many field based on the presence of data.

Hope it will be helpful to you.

Thanks & Regards,
Email:    odoo@aktivsoftware.com  

Skype: kalpeshmaheshwari

Avatar
Descartar
Related Posts Respostes Vistes Activitat
0
de nov. 23
1231
0
de nov. 21
2331
4
d’oct. 21
79975
0
d’abr. 21
5417
1
de des. 19
3686