diff --git a/openerp/addons/base/ir/ir_ui_view.py b/openerp/addons/base/ir/ir_ui_view.py
index b8ae58d4767..ca19048848e 100644
--- a/openerp/addons/base/ir/ir_ui_view.py
+++ b/openerp/addons/base/ir/ir_ui_view.py
@@ -264,7 +264,7 @@ class view(osv.osv):
# default view selection
def default_view(self, cr, uid, model, view_type, context=None):
""" Fetches the default view for the provided (model, view_type) pair:
- view with no parent (inherit_id=Fase) with the lowest priority.
+ primary view with the lowest priority.
:param str model:
:param int view_type:
@@ -274,7 +274,7 @@ class view(osv.osv):
domain = [
['model', '=', model],
['type', '=', view_type],
- ['inherit_id', '=', False],
+ ['mode', '=', 'primary'],
]
ids = self.search(cr, uid, domain, limit=1, context=context)
if not ids:
diff --git a/openerp/addons/base/tests/test_views.py b/openerp/addons/base/tests/test_views.py
index 29e6fe18248..2ccf608e0b4 100644
--- a/openerp/addons/base/tests/test_views.py
+++ b/openerp/addons/base/tests/test_views.py
@@ -14,6 +14,12 @@ class ViewCase(common.TransactionCase):
def setUp(self):
super(ViewCase, self).setUp()
self.addTypeEqualityFunc(ET._Element, self.assertTreesEqual)
+ self.Views = self.registry('ir.ui.view')
+
+ def browse(self, id, context=None):
+ return self.Views.browse(self.cr, self.uid, id, context=context)
+ def create(self, value, context=None):
+ return self.Views.create(self.cr, self.uid, value, context=context)
def assertTreesEqual(self, n1, n2, msg=None):
self.assertEqual(n1.tag, n2.tag)
@@ -374,13 +380,6 @@ class TestApplyInheritedArchs(ViewCase):
""" Applies a sequence of modificator archs to a base view
"""
-class TestViewCombined(ViewCase):
- """
- Test fallback operations of View.read_combined:
- * defaults mapping
- * ?
- """
-
class TestNoModel(ViewCase):
def test_create_view_nomodel(self):
View = self.registry('ir.ui.view')
@@ -812,15 +811,6 @@ class ViewModeField(ViewCase):
classes, integrating the test (or not) of the mode field to regular cases
"""
- def setUp(self):
- super(ViewModeField, self).setUp()
- self.Views = self.registry('ir.ui.view')
-
- def browse(self, id, context=None):
- return self.Views.browse(self.cr, self.uid, id, context=context)
- def create(self, value, context=None):
- return self.Views.create(self.cr, self.uid, value, context=context)
-
def testModeImplicitValue(self):
""" mode is auto-generated from inherit_id:
* inherit_id -> mode=extendion
@@ -893,6 +883,62 @@ class ViewModeField(ViewCase):
view.write({'mode': 'primary'})
+class TestDefaultView(ViewCase):
+ def testDefaultViewBase(self):
+ self.create({
+ 'inherit_id': False,
+ 'priority': 10,
+ 'mode': 'primary',
+ 'arch': '',
+ })
+ v2 = self.create({
+ 'inherit_id': False,
+ 'priority': 1,
+ 'mode': 'primary',
+ 'arch': '',
+ })
+
+ default = self.Views.default_view(self.cr, self.uid, False, 'qweb')
+ self.assertEqual(
+ default, v2,
+ "default_view should get the view with the lowest priority for "
+ "a (model, view_type) pair"
+ )
+
+ def testDefaultViewPrimary(self):
+ v1 = self.create({
+ 'inherit_id': False,
+ 'priority': 10,
+ 'mode': 'primary',
+ 'arch': '',
+ })
+ self.create({
+ 'inherit_id': False,
+ 'priority': 5,
+ 'mode': 'primary',
+ 'arch': '',
+ })
+ v3 = self.create({
+ 'inherit_id': v1,
+ 'priority': 1,
+ 'mode': 'primary',
+ 'arch': '',
+ })
+
+ default = self.Views.default_view(self.cr, self.uid, False, 'qweb')
+ self.assertEqual(
+ default, v3,
+ "default_view should get the view with the lowest priority for "
+ "a (model, view_type) pair in all the primary tables"
+ )
+
+class TestViewCombined(ViewCase):
+ """
+ Test fallback operations of View.read_combined:
+ * defaults mapping
+ * ?
+ """
+
class TestXPathExtentions(common.BaseCase):
def test_hasclass(self):
tree = E.node(