This question has been flagged
3 Replies
22501 Views

How to change field's string label based on condition?

Avatar
Discard
Best Answer

Hi Giezel,

One more trick.

Steps 1:

Set nolabel to true in your field.

E.g.

<field name="your_field" nolabel="1"/>

Step 2:

Set the two labels above to your field and apply condition inside the labels.


<label string="Label 1" attrs="{'invisible':[]}"/>  <!-- Provide your condition inside [], if condition will be true the label will be invisible -->
<label string="Label 2" attrs="{'invisible':[]}"/> <!-- Provide reverse condition than above label. -->
<field name="your_field"/>


By following this you can hide your make visible your label based on condition.

Hope this will help.

Happy Odooing...


Regards,

Anil.


Avatar
Discard
Best Answer

Its tricky ;)

<field name="my_field" string="LABEL1" attrs="{'invisible': [('partner_id', '!=', False)]}"/>
<field name="my_field" string="LABEL2" attrs="{'invisible': [('partner_id', '=', False)]}"/>


So, here when you have partner, odoo will display LABEL1 as string.

Other wise LABEL2 for "my_field" field.


You can get some help from here.

Avatar
Discard

it works, but this is an unrecommended solution, better to avoid this, imho