odoo 加载一个模型视图会先走load_views方法
在这个方法里面可以获得这个模型的form,list,search视图。先上源码
@api.model
def load_views(self, views, options=None):
""" Returns the fields_views of given views, along with the fields of
the current model, and optionally its filters for the given action.
:param views: list of [view_id, view_type]
:param options['toolbar']: True to include contextual actions when loading fields_views
:param options['load_filters']: True to return the model's filters
:param options['action_id']: id of the action to get the filters
:return: dictionary with fields_views, fields and optionally filters
"""
options = options or {}
result = {}
toolbar = options.get('toolbar')
result['fields_views'] = {
v_type: self.fields_view_get(v_id, v_type if v_type != 'list' else 'tree',
toolbar=toolbar if v_type != 'search' else False)
for [v_id, v_type] in views
}
result['fields'] = self.fields_get()
if options.get('load_filters'):
result['filters'] = self.env['ir.filters'].get_filters(self._name, options.get('action_id'))
return result
拿到全部字段
fields_views里面form视图上的xml代码,模型,字段值,都可以在这里看到。显然在视图上东西也都可以在这里改,之前有个问题就是要修改这个partner_type这个selection4个选项去掉 PI,不可以继承字段直接修改。那就可以在这里动一下手脚。
res['fields_views']['form']['fields']['partner_type']['selection'].remove(('PI', '课题组(PI)'))
根据具体的条件来控制是否去除
在form,tree,search视图上一些奇奇怪怪的修改需求,可以在load_views上操作fields_views进行修改