Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
3 Risposte
26026 Visualizzazioni

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

Avatar
Abbandona
Risposta migliore

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
Abbandona
Risposta migliore

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
Abbandona

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

Risposta migliore

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.

Avatar
Abbandona

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.

Post correlati Risposte Visualizzazioni Attività
2
giu 22
5267
2
set 21
4129
1
nov 20
7374
2
mar 19
5546
1
apr 18
3903