From 100529995558bdb4fc3679efa25088dbfee2530c Mon Sep 17 00:00:00 2001 From: Leonardo Rochael Almeida Date: Mon, 8 Jun 2015 03:18:59 +0200 Subject: [PATCH] [FIX] YAML: `!menuitem` tag handling The fetched ID was the one of the parent instead of the ID of the imported menu. --- openerp/addons/test_impex/__openerp__.py | 1 + .../test_impex/tests/test_import_menuitem.yml | 67 +++++++++++++++++++ openerp/tools/yaml_import.py | 4 +- 3 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 openerp/addons/test_impex/tests/test_import_menuitem.yml diff --git a/openerp/addons/test_impex/__openerp__.py b/openerp/addons/test_impex/__openerp__.py index 9bee558c759..00497cd6813 100644 --- a/openerp/addons/test_impex/__openerp__.py +++ b/openerp/addons/test_impex/__openerp__.py @@ -13,6 +13,7 @@ 'auto_install': False, 'test': [ 'tests/test_import_reference.yml', + 'tests/test_import_menuitem.yml', ] } # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/openerp/addons/test_impex/tests/test_import_menuitem.yml b/openerp/addons/test_impex/tests/test_import_menuitem.yml new file mode 100644 index 00000000000..e3607bbfdeb --- /dev/null +++ b/openerp/addons/test_impex/tests/test_import_menuitem.yml @@ -0,0 +1,67 @@ +- | + YAML Import menuitem scenario: + Check that !menuitem import works with YAML. + +- | + Given a standard three level menuitem structure including: + + A top level menu item (no parent no action) +- + !menuitem { + id: test_menu_top, + name: "Test Menu Top", + } +- > + An intermediary menu item (parent, but no action) +- + !menuitem { + id: test_menu_sub, + parent: test_menu_top, + name: "Test Menu Sub", + } + +- > + A leaf menu item (parent and action) +- + !menuitem { + id: test_menu_action, + name: "Test Menu Action", + parent: test_menu_sub, + action: base.open_module_tree, + } + +- > + Another leaf menu item (parent and action) in another menu structure with + dotted parent id +- + !menuitem { + id: test_menu_action_2, + name: "Test Menu Action 2", + parent: base.menu_management, + action: base.open_module_tree, + sequence: 93, + } + +- > + Then these menu items should be present and properly configured. +- + !assert { model: ir.ui.menu, id: test_menu_top, string: menu item "top" is properly configured }: + - name == 'Test Menu Top' + - parent_id.name == False + - action == False +- + !assert { model: ir.ui.menu, id: test_menu_sub, string: menu item "sub" is properly configured }: + - name == 'Test Menu Sub' + - parent_id.name == 'Test Menu Top' + - action == False +- + !assert { model: ir.ui.menu, id: test_menu_action, string: menu item "action" is properly configured }: + - name == 'Test Menu Action' + - parent_id.name == 'Test Menu Sub' + - action.name == 'Local Modules' +- + !assert { model: ir.ui.menu, id: test_menu_action_2, string: menu item "action_2" is properly configured }: + - name == 'Test Menu Action 2' + - sequence == 93 + - parent_id.name == 'Modules' + - action.name == 'Local Modules' diff --git a/openerp/tools/yaml_import.py b/openerp/tools/yaml_import.py index f475ccf2e14..efb6f9b88d8 100644 --- a/openerp/tools/yaml_import.py +++ b/openerp/tools/yaml_import.py @@ -749,14 +749,14 @@ class YamlInterpreter(object): noupdate=self.isnoupdate(node), res_id=res and res[0] or False) if node.id and parent_id: - self.id_map[node.id] = int(parent_id) + self.id_map[node.id] = int(pid) if node.action and pid: action_type = node.type or 'act_window' action_id = self.get_id(node.action) action = "ir.actions.%s,%d" % (action_type, action_id) self.pool['ir.model.data'].ir_set(self.cr, SUPERUSER_ID, 'action', \ - 'tree_but_open', 'Menuitem', [('ir.ui.menu', int(parent_id))], action, True, True, xml_id=node.id) + 'tree_but_open', 'Menuitem', [('ir.ui.menu', int(pid))], action, True, True, xml_id=node.id) def process_act_window(self, node): assert getattr(node, 'id'), "Attribute %s of act_window is empty !" % ('id',)