Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
2 Odpovědi
19383 Zobrazení

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?

Avatar
Zrušit
Nejlepší odpověď

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.

Avatar
Zrušit

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

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.

Autor

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

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.

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

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 ;)

Nejlepší odpověď

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)]}"/>
Avatar
Zrušit
Autor

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.

Related Posts Odpovědi Zobrazení Aktivita
2
lis 18
4652
0
bře 15
5686
0
bře 15
3574
1
bře 15
4512
1
bře 15
6591