diff --git a/bin/osv/orm.py b/bin/osv/orm.py index c8e11da544b..67716225bc8 100644 --- a/bin/osv/orm.py +++ b/bin/osv/orm.py @@ -951,12 +951,26 @@ class orm_template(object): model = True sql_res = False while ok: + sql_res_usr = None if view_id: + #check for user specific view and get the view according to that where = (model and (" and model='%s'" % (self._name,))) or '' - cr.execute('SELECT arch,name,field_parent,id,type,inherit_id FROM ir_ui_view WHERE id=%d'+where, (view_id,)) + cr.execute('select arch,name,field_parent,ref_id,type,inherit_id from ir_ui_view_user where ref_id=%d and user_id=%d'+where, (view_id, user)) + sql_res_usr = cr.fetchone() + + if not sql_res_usr: + where = (model and (" and model='%s'" % (self._name,))) or '' + cr.execute('select arch,name,field_parent,id,type,inherit_id from ir_ui_view where id=%d'+where, (view_id,)) else: - cr.execute('SELECT arch,name,field_parent,id,type,inherit_id FROM ir_ui_view WHERE model=%s AND type=%s ORDER BY priority', (self._name,view_type)) - sql_res = cr.fetchone() + cr.execute('select arch,name,field_parent,ref_id,type,inherit_id from ir_ui_view_user where model=%s and type=%s and user_id=%d order by priority', (self._name, view_type, user)) + sql_res_usr = cr.fetchone() + if not sql_res_usr: + cr.execute('select arch,name,field_parent,id,type,inherit_id from ir_ui_view where model=%s and type=%s order by priority', (self._name,view_type)) + + if sql_res_usr is None: + sql_res = cr.fetchone() + else: + sql_res = sql_res_usr if not sql_res: break ok = sql_res[5] @@ -971,8 +985,14 @@ class orm_template(object): def _inherit_apply_rec(result, inherit_id): # get all views which inherit from (ie modify) this view - cr.execute('select arch,id from ir_ui_view where inherit_id=%d and model=%s order by priority', (inherit_id, self._name)) + + cr.execute('select arch,id from ir_ui_view where inherit_id=%s and model=%s and id not in (select ref_id from ir_ui_view_user where inherit_id=%s and model=%s and user_id=%s)' , (inherit_id, self._name, inherit_id, self._name, user)) + sql_inherit_part1 = cr.fetchall() + + cr.execute('select arch,ref_id from ir_ui_view_user where inherit_id=%d and model=%s and user_id=%d order by priority', (inherit_id, self._name, user)) sql_inherit = cr.fetchall() + + sql_inherit = sql_inherit_part1 + sql_inherit for (inherit,id) in sql_inherit: result = _inherit_apply(result, inherit) result = _inherit_apply_rec(result, id)