Today you will learn how to visible and invisible Odoo fields. Here I am trying to make a field visible and invisible in Odoo wizard when "All" is checked or unchecked.
Models.py
faculty_id = fields.Many2one('model.faculty', string="Faculty Name")
all_fac_resume = fields.Boolean(string="All")
is_show_faculty = fields.Boolean(string="is show faculty")
1 @api.onchange('all_fac_resume')
2 def _all_checked(self):
3 if self.all_fac_resume:
4 self.is_show_faculty = False
5 else:
6 self.is_show_faculty = True
Code Description:
Here we declare three fields the first one is "faculty_id" which shows the name of faculty in a drop down list, the second is "all_fac_resume" this field is Boolean (Check Box) and the last field is "is_show_faculty" on the basis of this last field we make our visible or invisible functionality. Here we will use this field in our xml file to visible or invisible "faculty_id" field.
In line no 1 we used "@api.onchange" decorator on 'all_fac_resume', this means that whenever check box checked or unchecked below functionality (line no 3 to 6) will be called.
.xml
1<field name="is_show_faculty" attrs="{'invisible':1}"/>
2<field name="faculty_id" options="{'no_quick_create': True,'no_create_edit':True}" style="width: 300px" attrs="{'invisible':[('is_show_faculty','=', False)]}"/>
Code Description:
In line no 1 we declare "is_show_faculty" field attribute as invisible because we don't want to show this field in our form view or in wizard. Here we used this field to only visible or invisible "faculty_id" (which is to be declared in line no 2, "attrs="{'invisible':[('is_show_faculty','=', False)]}""). Whenever the value of "is_show_faculty" will be false then "faculty_id" field will be invisible or vice versa.
0 comments
Post a Comment