convert: When loading menu, don't match by name

It is safer to create duplicate menus than assume the same name is the same
menu.

Solved strange case with 'Manufacturing', where it would falsely identify
the 'Manufacturing/Manufacturing' as its parent, and thus create a recursive
menu. If we are parsing the 'a/b/c' name syntax, we have to ommit "c" from
parent search.

Conflicts:

	bin/tools/convert.py

bzr revid: p_christ@hol.gr-20100830094806-3d4flzmp6vazdhtb
This commit is contained in:
P. Christeas 2010-08-30 12:48:06 +03:00
parent 48ba7cf974
commit b68138961f
1 changed files with 10 additions and 10 deletions

View File

@ -523,29 +523,29 @@ form: module.record_id""" % (xml_id,)
m_l = map(escape, escape_re.split(rec.get("name",'').encode('utf8')))
values = {'parent_id': False}
if not rec.get('parent'):
if rec.get('parent', False) is False:
pid = False
res = None
values['name'] = m_l[-1]
m_l = m_l[:-1] # last part is our name, not a parent
for idx, menu_elem in enumerate(m_l):
if pid:
cr.execute('select id from ir_ui_menu where parent_id=%s and name=%s', (pid, menu_elem))
else:
cr.execute('select id from ir_ui_menu where parent_id is null and name=%s', (menu_elem,))
res = cr.fetchone()
if idx==len(m_l)-1:
values = {'parent_id': pid,'name':menu_elem}
elif res:
if res:
pid = res[0]
xml_id = idx==len(m_l)-1 and rec.get('id','').encode('utf8')
try:
self.pool.get('ir.model.data')._update_dummy(cr, self.uid, 'ir.ui.menu', self.module, xml_id, idx==len(m_l)-1)
except:
self.logger.notifyChannel('init', netsvc.LOG_ERROR, "module: %s xml_id: %s" % (self.module, xml_id))
else:
# the menuitem does't exist but we are in branch (not a leaf)
self.logger.notifyChannel("init", netsvc.LOG_WARNING, 'Warning no ID for submenu %s of menu %s !' % (menu_elem, str(m_l)))
pid = self.pool.get('ir.ui.menu').create(cr, self.uid, {'parent_id' : pid, 'name' : menu_elem})
values['parent_id'] = pid
else:
menu_parent_id = self.id_get(cr, 'ir.ui.menu', rec.get('parent',''))
if rec.get('parent'):
menu_parent_id = self.id_get(cr, 'ir.ui.menu', rec.get('parent',''))
else: # we get here with <menuitem parent="">, explicit clear of parent
menu_parent_id = False
values = {'parent_id': menu_parent_id}
if rec.get('name'):
values['name'] = rec.get('name')