[IMP] define a name_get() that includes the complete hierarchy of menus

also improve code style (var names)

bzr revid: abo@openerp.com-20121029104636-6psw5ucyjy3zoyro
This commit is contained in:
Antonin Bourguignon 2012-10-29 11:46:36 +01:00
parent 9582a8bc82
commit c0cbbc3b03
1 changed files with 18 additions and 9 deletions

View File

@ -132,20 +132,29 @@ class ir_ui_menu(osv.osv):
return len(result)
return result
def _get_full_name(self, cr, uid, ids, name, args, context):
res = {}
for m in self.browse(cr, uid, ids, context=context):
res[m.id] = self._get_one_full_name(m)
def name_get(self, cr, uid, ids, context=None):
res = []
for id in ids:
elmt = self.browse(cr, uid, id, context=context)
res.append((id, self._get_one_full_name(elmt)))
return res
def _get_one_full_name(self, menu, level=6):
def _get_full_name(self, cr, uid, ids, name=None, args=None, context=None):
if context == None:
context = {}
res = {}
for elmt in self.browse(cr, uid, ids, context=context):
res[elmt.id] = self._get_one_full_name(elmt)
return res
def _get_one_full_name(self, elmt, level=6):
if level<=0:
return '...'
if menu.parent_id:
parent_path = self._get_one_full_name(menu.parent_id, level-1) + "/"
if elmt.parent_id:
parent_path = self._get_one_full_name(elmt.parent_id, level-1) + "/"
else:
parent_path = ''
return parent_path + menu.name
return parent_path + elmt.name
def create(self, *args, **kwargs):
self.clear_cache()