Skip to Content
Menu
This question has been flagged
3 Replies
26945 Rodiniai

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

Portretas
Atmesti
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.


Portretas
Atmesti
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.

Portretas
Atmesti

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

Related Posts Replies Rodiniai Veikla
2
birž. 22
5666
2
rugs. 21
4594
1
lapkr. 20
7921
2
kov. 19
6046
1
bal. 18
4245