From a2db8022d326c4ee7012cc2d1241706345fc29bd Mon Sep 17 00:00:00 2001 From: Antonin Bourguignon Date: Tue, 21 Aug 2012 18:40:54 +0200 Subject: [PATCH 1/3] [FIX] xml import: when using a menuitem tag, properly determine the type of action that is referenced the attribute for the element should now be useless bzr revid: abo@openerp.com-20120821164054-6zzad2k6nmebqe35 --- openerp/tools/convert.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/openerp/tools/convert.py b/openerp/tools/convert.py index 36f560ba62c..cf3967b1da0 100644 --- a/openerp/tools/convert.py +++ b/openerp/tools/convert.py @@ -591,7 +591,22 @@ form: module.record_id""" % (xml_id,) if rec.get('action'): a_action = rec.get('action','').encode('utf8') - a_type = rec.get('type','').encode('utf8') or 'act_window' + + # determine the type of action + # either the type is explicitly provided in the menuitem + if (rec.get('type','')): + a_type = rec.get('type','').encode('utf8') + # either we have to find it by ourselves + else: + # prevent redundant appearance of the module name for external xml ids + a_action_simplified = a_action.split('.')[1] if '.' in a_action else a_action + + ir_action_ref = self.pool.get('ir.model.data').get_object_reference(cr, self.uid, self.module, a_action_simplified) + ir_action = self.pool.get(ir_action_ref[0]).browse(cr, self.uid, [ir_action_ref[1]])[0] + + # isolate the last part of the type field, which is the only one revelant in this case + a_type = ir_action.type.split('.')[-1] + icons = { "act_window": 'STOCK_NEW', "report.xml": 'STOCK_PASTE', @@ -601,6 +616,7 @@ form: module.record_id""" % (xml_id,) "server": 'STOCK_EXECUTE', } values['icon'] = icons.get(a_type,'STOCK_NEW') + if a_type=='act_window': a_id = self.id_get(cr, a_action) cr.execute('select view_type,view_mode,name,view_id,target from ir_act_window where id=%s', (int(a_id),)) @@ -627,7 +643,7 @@ form: module.record_id""" % (xml_id,) values['icon'] = 'STOCK_EXECUTE' if not values.get('name', False): values['name'] = action_name - + elif a_type in ['wizard', 'url', 'client', 'server'] and not values.get('name'): a_id = self.id_get(cr, a_action) a_table = 'ir_act_%s' % a_type From 8dd80d5dcfa27fad822152f9f03c8ab2f76dd55e Mon Sep 17 00:00:00 2001 From: Antonin Bourguignon Date: Tue, 21 Aug 2012 19:22:24 +0200 Subject: [PATCH 2/3] [FIX] handling of the action's module xml id. also don't use the attribute anymore bzr revid: abo@openerp.com-20120821172224-9unwry0p27tn7d82 --- openerp/tools/convert.py | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/openerp/tools/convert.py b/openerp/tools/convert.py index cf3967b1da0..5fd88889602 100644 --- a/openerp/tools/convert.py +++ b/openerp/tools/convert.py @@ -593,19 +593,18 @@ form: module.record_id""" % (xml_id,) a_action = rec.get('action','').encode('utf8') # determine the type of action - # either the type is explicitly provided in the menuitem - if (rec.get('type','')): - a_type = rec.get('type','').encode('utf8') - # either we have to find it by ourselves + if ('.' in a_action): + # this is an action refering to another module: extract this module's name + a_action_module, a_action_name = a_action.split('.') else: - # prevent redundant appearance of the module name for external xml ids - a_action_simplified = a_action.split('.')[1] if '.' in a_action else a_action + # this is a local action: fetch the current module's name + a_action_module = self.module + a_action_name = a_action - ir_action_ref = self.pool.get('ir.model.data').get_object_reference(cr, self.uid, self.module, a_action_simplified) - ir_action = self.pool.get(ir_action_ref[0]).browse(cr, self.uid, [ir_action_ref[1]])[0] - - # isolate the last part of the type field, which is the only one revelant in this case - a_type = ir_action.type.split('.')[-1] + # fetch the model and the res id + ir_action_ref = self.pool.get('ir.model.data').get_object_reference(cr, self.uid, a_action_module, a_action_name) + # get the part of the model we need + a_type = ir_action_ref[0].split('.')[-1] icons = { "act_window": 'STOCK_NEW', From a337ca201d7d72b485c0e330c433afc50bef458a Mon Sep 17 00:00:00 2001 From: Olivier Dony Date: Wed, 22 Aug 2012 16:49:46 +0200 Subject: [PATCH 3/3] [IMP] rng: forbid redundant @type for menuitem, now inferred from the action type + minor cleanup bzr revid: odo@openerp.com-20120822144946-fdsw9ee1ia3nfe86 --- openerp/import_xml.rng | 1 - openerp/tools/convert.py | 6 +++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/openerp/import_xml.rng b/openerp/import_xml.rng index bf5a9e1800e..5dd789c6e95 100644 --- a/openerp/import_xml.rng +++ b/openerp/import_xml.rng @@ -185,7 +185,6 @@ - diff --git a/openerp/tools/convert.py b/openerp/tools/convert.py index 5fd88889602..8269fa5d7ff 100644 --- a/openerp/tools/convert.py +++ b/openerp/tools/convert.py @@ -593,11 +593,11 @@ form: module.record_id""" % (xml_id,) a_action = rec.get('action','').encode('utf8') # determine the type of action - if ('.' in a_action): - # this is an action refering to another module: extract this module's name + if '.' in a_action: + # action referring to another module a_action_module, a_action_name = a_action.split('.') else: - # this is a local action: fetch the current module's name + # local action: use current module a_action_module = self.module a_action_name = a_action