i have a many2one field and i want that if certain value is selected a field must get invisible . There are many questions like that on the forum but nothing working for me. Please help
here is the code
py
class MaintNewCust(models.Model):
_inherit = 'maintenance.request'
number = fields.Char(string='Serial Number')
complaint_type = fields.Many2one('my.model',string='Complaint Type')
emr = fields.Selection([
('ws', 'Water Supply'),
('sui', 'Sui Gas'),('electric', 'Electric'),('SA', 'Split AC')], string='E & M', copy=False)
bbr = fields.Selection([
('fw', 'Finishing Work'),
('sf', 'Sanitary Fitting'), ('ss', 'Sewarage System'), ('fp', 'Footpaths'), ('rd', 'Roads'), ('ww', 'Wood Works')], string='B & R', copy=False)
used = fields.Boolean(string='Boolean')
@api.onchange('complaint_type')
def _onchange_type(self):
if self.complaint_type == "Buildings and roads":
self.used = True
else:
self.used = False
xml
<xpath expr="//field[@name='employee_id']" position="after">
<field name="complaint_type"/>
</xpath>
<xpath expr="//field[@name='maintenance_type']" position="after">
<field name="emr" attrs="{'invisible': [('used','==',False)]}"/>
</xpath>
<xpath expr="//field[@name='maintenance_type']" position="after">
<field name="bbr" attrs="{'invisible':[('used', '==', True)]}"/>
</xpath>
How to visible and invisible fields in odoo: https://goo.gl/BCxCpk
Or try this one: http://learnopenerp.blogspot.com/2016/10/how-to-visible-and-invisible-fields-in.html