Odoo Help


how to create dynamic field labels?

on 6/8/13, 5:47 PM 6,531 views

How can I create dynamic field labels in the form view?

For example for the name, I want to have a label "Company" if it's a company, and the label "Lastname" if it's a contact.

Ideally it should be something like this:

<field name="name" string="{[('Company',[('is_company','=', True)]), ('Lastname',[('is_company','=', False)]) }"/>

How to manage this?


Hiral Patel (hip)

--Hiral Patel (hip)--
| 2 1 5
--Hiral Patel (hip)--

Hiral Patel (hip)
On 6/14/13, 8:46 AM


You can do like :

<label for="name" string="Company" attrs="{'invisible': [('is_company','=',False)]}"/>

<label for="name" string="First Name" attrs="{'invisible': [('is_company','=',True)]}"/>


Hi, Do you test that? I tryed that solution, but when is_company equals True, Form is can not be saved.

on 6/14/13, 9:14 AM

I have tested this and it's working at my end. I have tested on runbot with latest revision and it's allow me to save record even when is_company equals True.

Hiral Patel (hip)
on 6/14/13, 9:25 AM

Thanks, I will give it a try. Most things I tried before messed up the format (how it's display on the view).

on 6/14/13, 9:32 AM

In res_partner_view.xml you will get record for partner form (having id ="view_partner_form"). In place of <label for="name"/> apply the code and then update your server. Otherwise enable debug mode and change it for your test purpose that it's working or not. I hope it will solve your problem.

Hiral Patel (hip)
on 6/14/13, 9:39 AM

Dear Friends, I would like to change field label(string) while onchange many2one field. I have configured few items in that object. I could not use fields_view_get. While i onchange i am able to update field string but is not reflected in the view. def onchange_ini_temp_id(self, cr, uid, ids, initiative_category_id, context=None): val = {} view_id=None view_type='form' toolbar=False submenu=False res = super(project_project, self).fields_view_get(cr, uid, view_id=view_id, view_type=view_type, context=context, toolbar=toolbar, submenu=submenu) fields = res.get('fields', {}) doc = etree.XML(res['arch']) for node in doc.xpath("//field[@name='release']"): node.set('invisible', "0") node.set('string', 'Test Data') setup_modifiers(node, res['fields']['release']) res['arch'] = etree.tostring(doc) self.fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False) return res Thank you

on 9/2/15, 12:14 AM

The easiest option is as Hiral suggested, just show or hide label depending on some field value. Looking for better solution as well :) However it doesn't work as good as it should ;)

Dr Obx
on 11/3/15, 5:28 AM
On 6/8/13, 7:59 PM

In your case, better way to define two fields and hide one of them when you change is_company.

For example:

<field name="name" attrs="{'invisible': [('is_company','=',True)]}"/>
<field name="company_name" attrs="{'invisible': [('is_company','=',False)]}"/>

The field "name" is the default field from res.partner, used for companies AND contacts in V7. I want to keep OpenERP's database as stock as possible, hence my question about dynamic label fields.

on 6/8/13, 8:44 PM

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 6/8/13, 5:47 PM
Seen: 6531 times
Last updated: 12/10/15, 9:49 PM