Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
3 Răspunsuri
26971 Vizualizări

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

Imagine profil
Abandonează
Cel mai bun răspuns

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.


Imagine profil
Abandonează
Cel mai bun răspuns

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.

Imagine profil
Abandonează

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

Cel mai bun răspuns

Update answer for above answers:

If you looking for solution to inherit view to change the label, try this:


\<\?xml\ version=\"1\.0\"\?\>
\<odoo\>
 \<!\-\-\ show\ custom\ field\ in\ form\ view\ \-\-\>
 \<!\-\-\ inherit\ view\ \"view_partner_form\"\ \-\-\>
 \<record id=\"view_partner_form_inherit\" model=\"ir\.ui\.view\"\ style="color:\#e8bf6a;">\>
 \<!\-\-\ name\ is\ whatever\ you\ like\ \-\-\>
 \<field name=\"name\"\>view.partner.inherit style="color:#e8bf6a;"></field>
 <!-- this model field is the original model -->
 <field name="model">res.partner</field>
 <!-- this inherit_id value is get by "external id" from debug mode view form -->
 <field name="inherit_id" ref="base.view_partner_form"/>
 <field name="arch" type="xml">
 <xpath expr="//page[@name='sales_purchases']//field[@name='user_id']" position="attributes">
 <!-- remove default label -->
 <attribute name="nolabel">1</attribute>
 </xpath>
 <xpath expr="//page[@name='sales_purchases']//field[@name='user_id']" position="before">
 <div>
 <!-- add new label based on condition -->
 <label string="Label 1" attrs="{'invisible':[('partner_id', '=', False)]}" for="user_id"/>
 <label string="Label 2" attrs="{'invisible':[('partner_id', '!=', False)]}" for="user_id"/>
 </div>
 </xpath>
 </field>
 </record>
</odoo>




Hope it helped.

Imagine profil
Abandonează

Sorry for bad format of the code, in this forum, some how i can't edit or delete the comment. Please ignore this answer if you read this.

Related Posts Răspunsuri Vizualizări Activitate
2
iun. 22
5697
2
sept. 21
4618
1
nov. 20
7927
2
mar. 19
6093
1
apr. 18
4271