Add constraint on menu creation

- id xml is mandatory
- all parent menus must exist before add one
This commit is contained in:
ced@b2ck.com
2007-12-25 18:05:11 +01:00
parent 3484de7c5d
commit c51bf7bf55
7 changed files with 12 additions and 24 deletions
+2
View File
@@ -2,7 +2,9 @@
'name': 'IR',
'active': True,
'xml': [
'ir.xml',
'sequence.xml',
'ui/ui.xml',
'ui/menu.xml',
'ui/view.xml',
'actions.xml',
+1
View File
@@ -1,6 +1,7 @@
<?xml version="1.0"?>
<terp>
<data>
<menuitem name="Administration/IR/Actions" id="menu_actions"/>
<record model="ir.ui.view" id="actions_actions_view_form">
<field name="name">ir.actions.actions.form</field>
<field name="model">ir.actions.actions</field>
+1
View File
@@ -1,6 +1,7 @@
<?xml version="1.0"?>
<terp>
<data>
<menuitem name="Administration/IR/Sequences" id="menu_sequence"/>
<record model="ir.ui.view" id="sequence_view_form">
<field name="name">ir.sequence.form</field>
<field name="model">ir.sequence</field>
-12
View File
@@ -285,18 +285,6 @@ def load_modules(database, force_demo=False, update_module=False):
uid = 1
pool.get(rmod).unlink(cursor, uid, [rid])
cursor.commit()
# TODO: remove menu without actions of childs
cursor.execute('DELETE FROM ir_ui_menu ' \
'WHERE (id NOT IN (' \
'SELECT parent_id FROM ir_ui_menu ' \
'WHERE parent_id IS NOT NULL)) ' \
'AND (id NOT IN (' \
'SELECT res_id FROM ir_values ' \
'WHERE model = \'ir.ui.menu\')) ' \
'AND (id NOT IN (' \
'SELECT res_id FROM ir_model_data ' \
'WHERE model = \'ir.ui.menu\'))')
cursor.execute("UPDATE ir_module_module SET state = %s " \
"WHERE state IN ('to remove')", ('uninstalled',))
cursor.commit()
+1
View File
@@ -3,6 +3,7 @@
'active': True,
'depends': ['ir'],
'xml': [
'res.xml',
'users.xml',
'lang.xml',
'request.xml',
+6 -12
View File
@@ -407,6 +407,8 @@ class XMLImport(object):
def _tag_menuitem(self, cursor, rec, data_node=None):
rec_id = rec.getAttribute("id").encode('ascii')
assert rec_id, "No id on menutiem %s" % \
rec.getAttribute("name").encode('utf8')
self._test_xml_id(rec_id)
m_l = [escape(x) for x in ESCAPE_RE.split(
rec.getAttribute("name").encode('utf8'))]
@@ -491,19 +493,11 @@ class XMLImport(object):
pid = self.pool.get('ir.model.data')._update(cursor, self.user,
'ir.ui.menu', self.module, values, xml_id,
mode=self.mode, res_id=(res and res[0] or False))
elif res:
# the menuitem already exists
pid = res[0]
xml_id = (idx==len(m_l) - 1) \
and rec.getAttribute('id').encode('utf8')
self.pool.get('ir.model.data')._update_dummy(cursor,
self.user, 'ir.ui.menu', self.module, xml_id)
else:
# the menuitem does't exist but we are in branch (not a leaf)
pid = self.pool.get('ir.ui.menu').create(cursor, self.user,
{'parent_id': pid, 'name': menu_elem})
if rec_id and pid:
self.idref[rec_id] = int(pid)
assert res, "The parent menuitem %s does not exist!" % \
(menu_elem,)
pid = res[0]
self.idref[rec_id] = int(pid)
return ('ir.ui.menu', pid)
def _assert_equals(self, i, j, prec=4):
+1
View File
@@ -1,6 +1,7 @@
<?xml version="1.0"?>
<terp>
<data>
<menuitem name="Administration/Workflow" id="menu_workflow"/>
<record model="ir.ui.view" id="workflow_view_form">
<field name="name">workflow.form</field>
<field name="model">workflow</field>