How to hide a field checking if there is a specific record inside?<group attrs="{'invisible':[('210220', 'in', 'events.type_event')]}">type_event = fields.Selection(<field name="events">
[('210200', u'Confirmação da Operação'),
('210210', u'Ciência da Emissão'),
('210220', u'Desconhecimento da Operação'),
('210240', u'Operação não Realizada'),
('110111', u'Cancelamento da Operação')],
string=u'Tipo de Evento',
required=True
)
<tree create="false">
<field name="type_event" readonly="1"/>
<field name="protocol" readonly="1"/>
<field name="write_date" readonly="1"/>
</tree>
</field>
<button name="event_desconhecimento" type="object"
string="Desconhecimento da Operação" class="btn-info btn-block"/>
</group>
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Accounting
- Inventory
- PoS
- Project management
- MRP
This question has been flagged
Hello, Michael.
I think we can't set a domain like that, the first parameter should be a field od the model, the second is the operator and the third one is the value.
So, if you want to hide the field depending on the availability of a value in the records of the one2many field, I recommend to create a new field in the model, maybe "type_event_invisible" of type Boolean.
I would define a method with @api.onchange('type_event') as decorator, this method should change the value of type_event_invisible field of the record. As I've tested, all onchange methods get executed at form loading.
Then, the domain for invisible attribute should be {'invisible':[('type_event_invisible', '=', True)]}
I'm not really good explaining, but I hope it can helps. Greetings.
That way I would create disposable fields in the database, so I did it this way:
ciencia = fields.Boolean(
compute='compute_display_view',
store=False,
default=False
)
confirmacao = fields.Boolean(
compute='compute_display_view',
store=False,
default=False
)
desconhecimento = fields.Boolean(
compute='compute_display_view',
store=False,
default=False
)
nao_realizada = fields.Boolean(
compute='compute_display_view',
store=False,
default=False
)
xml_entrada = fields.Boolean(
compute='compute_display_view',
store=False,
default=False
)
def compute_display_view(self):
for record in self:
for x in record.events:
if x.type_event == '210200':
record.confirmacao = True
record.ciencia = True
if x.type_event == '210220':
record.desconhecimento = True
record.ciencia = True
if x.type_event == '210240':
record.nao_realizada = True
record.ciencia = True
if x.type_event == '210210':
record.ciencia = True
for x in record.nsu:
if x.type_response == '1':
record.xml_entrada = True