openerp的視圖結構是以XML的格式存放於ir.ui.view表中,屬於靜態格式,設計之後就固定,
但可以通過在model中重寫fields_view_get函數,在視圖加載時修改arch屬性,動態修改視圖的結構
[python] view plaincopy
- def fields_view_get(self, cr, uid, view_id=None,view_type='form',context=None,toolbar=False,submenu=False):
- ip_obj = self.pool.get('hr.rule.input')
- res = super(hr_inputs_editor,self).fields_view_get(cr,uid,view_id,view_type,context,toolbar,submenu)
- if view_type=='form':
- treev = res['fields']['line_ids']['views']['tree']
- doc = etree.XML(treev['arch'])
- for node in doc.xpath("/tree/field"):
- name = node.get('name',False)
- if name.startswith('value'):
- name = name.replace('value','input') + '_code'
- cd = context.has_key(name) and context[name] or False
- if cd:
- ip_ids = ip_obj.search(cr,uid,[('code','=',cd)],limit=1,context=context)
-