This question has been flagged

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>

Avatar
Discard

How to visible and invisible fields in odoo: https://goo.gl/BCxCpk

Best Answer
<xpath expr="//field[@name='maintenance_type']" position="attributes">
<attribute name="attrs">{'invisible': [('used','=',False)]}</attribute>
</xpath>
Avatar
Discard
Author

i want fields name "emr" and "bbr" to be visible or invisible, not maintenance type. Sir how will this help?

<xpath expr="//field[@name='maintenance_type']" position="after">

<field name="emr" attrs="{'invisible':[('used', '=', False)]}"/>

<field name="bbr" attrs="{'invisible':[('used', '=', True)]}"/>

</xpath>