Search code examples
odooopenerp-7odoo-8openerp-8

How can i change the field name based on condition in xml file?


How can I change the field name based on condition in XML file?

My code is:

<field name="parent_id" position="attributes">    
    <attribute name="string">{'HOD':[('is_student','=',True)]}</attribute>    
</field>

If field is_student is True, then Show HOD otherwise keep as Manager only.

How to achieve it?


Solution

  • As I am not able to do in XML file, because if I try the @Odedra solution, my design getting disturbed.

    I'm achieve it with this code:

    def fields_get(self, cr, uid, fields=None, context=None):
        if context is None:
            context={}
        res = super(hr_employee, self).fields_get(cr, uid, fields, context)
        if 'parent_id' in res and 'is_student' in context and context['is_student']:
            if 'string' in res['parent_id']:
                res['parent_id']['string'] = 'HOD'
        return res