[IMP] simplify ir.ui.view.get_root_ancestor by using browse records

Also only case which should result in the id not existing is the
initial record, if a view_id is explicitly provided. So the loop can
avoid it's, it's traversing through an m2o so if the m2o value is not
null the next record in the chain should always exist.

bzr revid: xmo@openerp.com-20130423135739-jve1fe2it8q4gkwh
This commit is contained in:
Xavier Morel 2013-04-23 15:57:39 +02:00
parent 0676c84be5
commit 8914886040
1 changed files with 11 additions and 15 deletions

View File

@ -283,23 +283,19 @@ class view(osv.osv):
if not ids: return False
[view_id] = ids
view = self.browse(cr, uid, view_id, context=context)
if not view.exists():
return False
# Search for a root (i.e. without any parent) view.
while True:
views = self.read(cr, uid, [view_id],[
'arch', 'name', 'field_parent',
'id', 'type', 'inherit_id', 'model'
], context=context)
if not views: return False
while view.inherit_id:
view = view.inherit_id
view = views[0] if views else False
if not view['inherit_id']:
return view
view_id = view['inherit_id']
# due to read() inherit_id may be a name_get pair, unpack id
if isinstance(view_id, tuple):
view_id, _name = view_id
views = self.read(cr, uid, [view.id],[
'arch', 'name', 'field_parent',
'id', 'type', 'inherit_id', 'model'
], context=context)
return views[0]
def raise_view_error(self, cr, uid, model, error_msg, view_id, child_view_id, context=None):