This question has been flagged
2 Replies
2901 Views

Hello everybody!!!

I have a field named type_id which is a many2one to a table hr.contract.type. (where its fields are id, name, ...)

I want to make a field named Date_end invisible when the name of the contract is "CDI".

I tried like this : <field name="date_end" attrs="{'invisible':[('type_id.name,'=',"CDI")]}"/>

But it doesnt work.

Can anyone help please.

Thanks a lot in advance.

Best Regards.

Avatar
Discard
Best Answer

Add the contract name as a related field in the contract object then change the domain in xml

<field name="date_end" attrs="{'invisible':[('my_related_field','=','CDI')]}"/>

NOTE : The code you posted has some errors it should be like this :

<field name="date_end" attrs="{'invisible':[('type_id.name','=','CDI')]}"/>

Let us now how it went for you !

Avatar
Discard
Best Answer

Hello DressFar,


Try this :-

First Solution:-

<field name="date_end" attrs ="{'invisible': {'type_id': [('name', '=', 'CDI')]}}" / >


Second Solution :-

In py:-

type_id = fields.Many2one ("hr.contract.type", 'Type')

type_name = fields.Char(related='type_id.name', 'Type Name')

In Xml:-

<field name="type_id" attrs="{'invisible': [('type_name', '=', 'CDI')]}" />

<field name="type_name" invisible="1"/>


Hope it works for you.

Thanks,

Avatar
Discard