Odoo Help

0

How to create field with dynamic label name????

By
Jack
on 7/3/13, 11:03 AM 1,103 views

Hiiii,

I select "March" we get 31 days in sequence like 1,2,3,4..........31 with their respective 'days' like Mon,Tue.....Sun . Now 31 field should be created with Label name Mon 1 June,Tue 2 June etc.......

This should happen with all 12 month.

Thanks Jack

0
marwa
On 7/13/17, 10:08 AM

from lxml import etree

@api.model

    def fields_view_get(self,view_id=None, view_type=None,context=None, toolbar=False, submenu=False):

        """

        overwriting to set dynamic label on the field my_field.


        """

 

        res=super(my_model_class, self).fields_view_get(view_id=view_id, view_type=view_type, toolbar=toolbar, submenu=submenu)

        if view_type == 'form':

            doc = etree.XML(res['arch'])


            nodes = doc.xpath("//field[@name='my_field']")

            nodes[0].set('string', 'My Dynamic Label')


            res['arch'] = etree.tostring(doc)

        return res

0
Roel Zantinge
On 11/10/15, 6:25 AM

this is rather tricky to do via the XML files.

More effective is to overwrite fields_view_get method (tested for OE 7.0), like so:

def fields_view_get(self, cr, uid, view_id=None, view_type=None,
context=None, toolbar=False, submenu=False):
"""
overwriting to set dynamic label on the field reading_normal.

"""
    res = super(meter_reading_electricity, self).fields_view_get(
                       cr, uid, view_id=view_id, view_type=view_type,
    context=context, toolbar=toolbar, submenu=submenu)
    if view_type == 'form':
        doc = etree.XML(res['arch'])

        nodes = doc.xpath("//field[@name='reading_normal']")
        nodes[0].set('string', 'My dynamic label')

        res['arch'] = etree.tostring(doc)
    return res

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.

Register

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

0 follower(s)

Stats

Asked: 7/3/13, 11:03 AM
Seen: 1103 times
Last updated: 7/13/17, 10:08 AM