From c51bf7bf559aa219d61868d646440b76e2b7667f Mon Sep 17 00:00:00 2001 From: "ced@b2ck.com" Date: Tue, 25 Dec 2007 18:05:11 +0100 Subject: [PATCH] Add constraint on menu creation - id xml is mandatory - all parent menus must exist before add one --- trytond/ir/__terp__.py | 2 ++ trytond/ir/actions.xml | 1 + trytond/ir/sequence.xml | 1 + trytond/module.py | 12 ------------ trytond/res/__terp__.py | 1 + trytond/tools/convert.py | 18 ++++++------------ trytond/workflow/workflow.xml | 1 + 7 files changed, 12 insertions(+), 24 deletions(-) diff --git a/trytond/ir/__terp__.py b/trytond/ir/__terp__.py index a20da05465..758cce8faa 100644 --- a/trytond/ir/__terp__.py +++ b/trytond/ir/__terp__.py @@ -2,7 +2,9 @@ 'name': 'IR', 'active': True, 'xml': [ + 'ir.xml', 'sequence.xml', + 'ui/ui.xml', 'ui/menu.xml', 'ui/view.xml', 'actions.xml', diff --git a/trytond/ir/actions.xml b/trytond/ir/actions.xml index e5933bb6e3..bccc03ae7f 100644 --- a/trytond/ir/actions.xml +++ b/trytond/ir/actions.xml @@ -1,6 +1,7 @@ + ir.actions.actions.form ir.actions.actions diff --git a/trytond/ir/sequence.xml b/trytond/ir/sequence.xml index ac6705e2a5..9df66ae783 100644 --- a/trytond/ir/sequence.xml +++ b/trytond/ir/sequence.xml @@ -1,6 +1,7 @@ + ir.sequence.form ir.sequence diff --git a/trytond/module.py b/trytond/module.py index b9b7655aa1..b799544c42 100644 --- a/trytond/module.py +++ b/trytond/module.py @@ -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() diff --git a/trytond/res/__terp__.py b/trytond/res/__terp__.py index ef1b26705f..7e3b3e8bf7 100644 --- a/trytond/res/__terp__.py +++ b/trytond/res/__terp__.py @@ -3,6 +3,7 @@ 'active': True, 'depends': ['ir'], 'xml': [ + 'res.xml', 'users.xml', 'lang.xml', 'request.xml', diff --git a/trytond/tools/convert.py b/trytond/tools/convert.py index b93b6e20b4..17059dce40 100644 --- a/trytond/tools/convert.py +++ b/trytond/tools/convert.py @@ -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): diff --git a/trytond/workflow/workflow.xml b/trytond/workflow/workflow.xml index 6ac0e065de..63298939a5 100644 --- a/trytond/workflow/workflow.xml +++ b/trytond/workflow/workflow.xml @@ -1,6 +1,7 @@ + workflow.form workflow