コンテンツへスキップ
メニュー
この質問にフラグが付けられました
2 返信
19360 ビュー

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?

アバター
破棄
最善の回答

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.

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.

著作者

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

最善の回答

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.

関連投稿 返信 ビュー 活動
2
11月 18
4646
0
3月 15
5683
0
3月 15
3570
1
3月 15
4497
1
3月 15
6562