Pular para o conteúdo
Menu
Esta pergunta foi sinalizada
1 Responder
8935 Visualizações

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
Cancelar

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

Melhor resposta
<xpath expr="//field[@name='maintenance_type']" position="attributes">
<attribute name="attrs">{'invisible': [('used','=',False)]}</attribute>
</xpath>
Avatar
Cancelar
Autor

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>

Publicações relacionadas Respostas Visualizações Atividade
1
ago. 23
3839
0
nov. 21
2880
4
out. 21
80905
0
abr. 21
5903
1
dez. 19
4165