Odoo Help

Welcome!

This community 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.

3

how to create dynamic field labels?

By
wjn
on 6/8/13, 5:47 PM 4,419 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?

4

Hiral Patel (hip)

--Hiral Patel (hip)--
Tiny ERP Pvt Ltd
http://www.odoo.com
913
| 2 1 5
India
--Hiral Patel (hip)--


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

Hello,

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)]}"/>

Thanks.

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

Alexander
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).

wjn
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

George
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
1
Alexander
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.

wjn
on 6/8/13, 8:44 PM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

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