[FIX] base: correct custom views validation.

As custom views validation is done while `self.pool._init` is set,
filter on currently loaded modules was still applied.
As a side effect, only one custom view per base view was validated.
In case this view is depending on another custom inherited view, the
validation failed.
Now force loading all views when validating custom views.
This commit is contained in:
Christophe Simonis 2015-03-04 12:49:06 +01:00
parent 325de62f51
commit d6998061f1
2 changed files with 20 additions and 3 deletions

View File

@ -324,6 +324,8 @@ class view(osv.osv):
:rtype: list of tuples
:return: [(view_arch,view_id), ...]
"""
if not context:
context = {}
user = self.pool['res.users'].browse(cr, 1, uid, context=context)
user_groups = frozenset(user.groups_id or ())
@ -334,13 +336,13 @@ class view(osv.osv):
['mode', '=', 'extension'],
['active', '=', True],
]
if self.pool._init:
if self.pool._init and not context.get('load_all_views'):
# Module init currently in progress, only consider views from
# modules whose code is already loaded
conditions.extend([
'|',
['model_ids.module', 'in', tuple(self.pool._init_modules)],
['id', 'in', context and context.get('check_view_ids') or (0,)],
['id', 'in', context.get('check_view_ids') or (0,)],
])
view_ids = self.search(cr, uid, conditions, context=context)
@ -1110,7 +1112,8 @@ class view(osv.osv):
""", (model,))
ids = map(itemgetter(0), cr.fetchall())
return self._check_xml(cr, uid, ids)
context = dict(load_all_views=True)
return self._check_xml(cr, uid, ids, context=context)
def _validate_module_views(self, cr, uid, module):
"""Validate architecture of all the views of a given module"""

View File

@ -685,6 +685,20 @@ class test_views(ViewCase):
)
self.assertTrue(validate()) # inherited view
# validation of a second inherited view (depending on 1st)
self._insert_view(
name='inherited view 2',
model=model,
priority=5,
inherit_id=vid,
arch_db="""<?xml version="1.0"?>
<xpath expr="//field[@name='name']" position="after">
<field name="target"/>
</xpath>
""",
)
self.assertTrue(validate()) # inherited view
def test_view_inheritance(self):
Views = self.registry('ir.ui.view')