Skip to Content
Menu
This question has been flagged
1 Reply
3194 Views

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
Discard
Author

<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>

Author

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
Discard
Related Posts Replies Views Activity
0
Nov 23
1163
0
Nov 21
2271
4
Oct 21
79910
0
Apr 21
5372
1
Dec 19
3653