From ab7dd577711e2394e6ce6df4497140351dbd0792 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Tue, 27 May 2014 12:23:02 +0200 Subject: [PATCH] [IMP] make mode handling more regular Before this commit, @mode=primary would be sorta-ignored[0] if the current view and its parent had the same model: the current view would *still* get applied (as an extension) when asking OpenERP for its parent. This commit makes mode=primary views behave regularly, they are *never* applied when asking for their parent, only when asking for them or their children. This allows "forking" views, and using extended views in some contexts without breaking or duplicating the original view [0] there was actually a problem when asking for the current view directly, first its parent would be resolved by applying it, then it would be applied to resolve itself, the view would thus get applied twice (oops) --- openerp/addons/base/ir/ir_ui_view.py | 6 +++++- openerp/addons/base/tests/test_views.py | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/openerp/addons/base/ir/ir_ui_view.py b/openerp/addons/base/ir/ir_ui_view.py index 2e74f116223..fc0edc24676 100644 --- a/openerp/addons/base/ir/ir_ui_view.py +++ b/openerp/addons/base/ir/ir_ui_view.py @@ -311,7 +311,11 @@ class view(osv.osv): user = self.pool['res.users'].browse(cr, 1, uid, context=context) user_groups = frozenset(user.groups_id or ()) - conditions = [['inherit_id', '=', view_id], ['model', '=', model]] + conditions = [ + ['inherit_id', '=', view_id], + ['model', '=', model], + ['mode', '=', 'extension'], + ] if self.pool._init: # Module init currently in progress, only consider views from # modules whose code is already loaded diff --git a/openerp/addons/base/tests/test_views.py b/openerp/addons/base/tests/test_views.py index 180bb6bff8a..07cd4715b83 100644 --- a/openerp/addons/base/tests/test_views.py +++ b/openerp/addons/base/tests/test_views.py @@ -965,6 +965,14 @@ class TestViewCombined(ViewCase): 'inherit_id': self.a1, 'arch': '' }) + # mode=primary should be an inheritance boundary in both direction, + # even within a model it should not extend the parent + self.a4 = self.create({ + 'model': 'a', + 'inherit_id': self.a1, + 'mode': 'primary', + 'arch': '', + }) self.b1 = self.create({ 'model': 'b', @@ -1031,6 +1039,17 @@ class TestViewCombined(ViewCase): E.a2(), ), arch) + def test_read_from_child_primary(self): + arch = self.read_combined(self.a4)['arch'] + self.assertEqual( + ET.fromstring(arch), + E.qweb( + E.a1(), + E.a4(), + E.a3(), + E.a2(), + ), arch) + def test_cross_model_simple(self): arch = self.read_combined(self.c2)['arch'] self.assertEqual(