跳至内容
菜单
此问题已终结
3 回复
26968 查看

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

形象
丢弃
最佳答案

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.


形象
丢弃
最佳答案

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.

形象
丢弃

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

相关帖文 回复 查看 活动
2
6月 22
5671
2
9月 21
4615
1
11月 20
7926
2
3月 19
6070
1
4月 18
4248