[IMP] make mode handling more regular
authorXavier Morel <xmo@openerp.com>
Tue, 27 May 2014 10:23:02 +0000 (12:23 +0200)
committerXavier Morel <xmo@openerp.com>
Tue, 27 May 2014 10:23:02 +0000 (12:23 +0200)
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
openerp/addons/base/tests/test_views.py

index 2e74f11..fc0edc2 100644 (file)
@@ -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
index 180bb6b..07cd471 100644 (file)
@@ -965,6 +965,14 @@ class TestViewCombined(ViewCase):
             'inherit_id': self.a1,
             'arch': '<xpath expr="//a1" position="after"><a3/></xpath>'
         })
+        # 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': '<xpath expr="//a1" position="after"><a4/></xpath>',
+        })
 
         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(