How to change field's string label based on condition?
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Accounting
- Inventory
- PoS
- Project
- MRP
This question has been flagged
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
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.
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.
Enjoying the discussion? Don't just read, join in!
Create an account today to enjoy exclusive features and engage with our awesome community!
Sign upRelated Posts | Replies | Views | Activity | |
---|---|---|---|---|
|
2
Jun 22
|
5254 | ||
|
2
Sep 21
|
4123 | ||
|
1
Nov 20
|
7358 | ||
|
2
Mar 19
|
5540 | ||
What does Nginx do in Odoo?
Solved
|
|
1
Apr 18
|
3897 |