From 043f50ba121cf6670d4517b6d15d1a0d7dc9036a Mon Sep 17 00:00:00 2001 From: sebastien beau Date: Mon, 19 Sep 2011 01:59:47 +0200 Subject: [PATCH] [REF] refactor code in order to add the possibility to overwrite the way to inherit the view bzr revid: sebastien.beau@akretion.com.br-20110918235947-5k6bxg2fbshhtrsd --- openerp/addons/base/ir/ir_ui_view.py | 13 +++++++++++++ openerp/osv/orm.py | 11 +++++------ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/openerp/addons/base/ir/ir_ui_view.py b/openerp/addons/base/ir/ir_ui_view.py index 90990834c9b..2cc5b6376c7 100644 --- a/openerp/addons/base/ir/ir_ui_view.py +++ b/openerp/addons/base/ir/ir_ui_view.py @@ -96,6 +96,19 @@ class view(osv.osv): if not cr.fetchone(): cr.execute('CREATE INDEX ir_ui_view_model_type_inherit_id ON ir_ui_view (model, type, inherit_id)') + def get_inherit_views(self, cr, uid, id, model, context=None): + """ + Get all views which inherit from (ie modify) this view + + :param cr: database cursor + :param user: current user id + :param id: id of the view + :return: list of tuple which contain of the view arch and the id + """ + + cr.execute('select arch,id from ir_ui_view where inherit_id=%s and model=%s order by priority', (id, model)) + return cr.fetchall() + def write(self, cr, uid, ids, vals, context={}): if not isinstance(ids, (list, tuple)): ids = [ids] diff --git a/openerp/osv/orm.py b/openerp/osv/orm.py index 86afb7c218d..9f64e587baa 100644 --- a/openerp/osv/orm.py +++ b/openerp/osv/orm.py @@ -1900,7 +1900,7 @@ class orm_template(object): raise_view_error("Element '%s' not found in parent view '%%(parent_xml_id)s'" % tag, inherit_id) return source - def apply_view_inheritance(source, inherit_id): + def apply_view_inheritance(cr, user, source, inherit_id): """ Apply all the (directly and indirectly) inheriting views. :param source: a parent architecture to modify (with parent @@ -1910,12 +1910,11 @@ class orm_template(object): are applied """ - # get all views which inherit from (ie modify) this view - cr.execute('select arch,id from ir_ui_view where inherit_id=%s and model=%s order by priority', (inherit_id, self._name)) - sql_inherit = cr.fetchall() + + sql_inherit = self.pool.get('ir.ui.view').get_inherit_views(cr, user, inherit_id, self._name) for (inherit, id) in sql_inherit: source = apply_inheritance_specs(source, inherit, id) - source = apply_view_inheritance(source, id) + source = apply_view_inheritance(cr, user, source, id) return source result = {'type': view_type, 'model': self._name} @@ -1958,7 +1957,7 @@ class orm_template(object): result['view_id'] = sql_res['id'] source = etree.fromstring(encode(sql_res['arch'])) - result['arch'] = apply_view_inheritance(source, result['view_id']) + result['arch'] = apply_view_inheritance(cr, user, source, result['view_id']) result['name'] = sql_res['name'] result['field_parent'] = sql_res['field_parent'] or False