Skip to Content
Menu
This question has been flagged
2 Replies
5977 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

Avatar
Discard
Best Answer

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

Avatar
Discard
Best Answer

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

Avatar
Discard