From 8e06458e9dc882395ca7181ffb270c4a784fb12e Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Thu, 25 Nov 2010 17:57:20 +0100 Subject: [PATCH] [ADD] base: method to fetch an act_window from its xml_id on ir.actions.act_window Also used it to replace the corresponding code in ir.attachment and res.widget.wizard bzr revid: xmo@openerp.com-20101125165720-62qphqpmt4fl2xcl --- bin/addons/base/ir/ir_actions.py | 13 +++++++++++++ bin/addons/base/ir/ir_attachment.py | 6 ++---- bin/addons/base/res/res_widget.py | 7 ++----- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/bin/addons/base/ir/ir_actions.py b/bin/addons/base/ir/ir_actions.py index 306ec0c1ef1..e257fd88523 100644 --- a/bin/addons/base/ir/ir_actions.py +++ b/bin/addons/base/ir/ir_actions.py @@ -272,6 +272,19 @@ class act_window(osv.osv): 'multi': False, } + def for_xml_id(self, cr, uid, module, xml_id, context=None): + """ Returns the act_window object created for the provided xml_id + + :param module: the module the act_window originates in + :param xml_id: the namespace-less id of the action (the @id + attribute from the XML file) + :return: A read() view of the ir.actions.act_window + """ + dataobj = self.pool.get('ir.model.data') + data_id = dataobj._get_id (cr, 1, module, xml_id) + res_id = dataobj.browse(cr, uid, data_id, context).res_id + return self.read(cr, uid, res_id, [], context) + act_window() class act_window_view(osv.osv): diff --git a/bin/addons/base/ir/ir_attachment.py b/bin/addons/base/ir/ir_attachment.py index fb621ea58fc..235254569d0 100644 --- a/bin/addons/base/ir/ir_attachment.py +++ b/bin/addons/base/ir/ir_attachment.py @@ -81,10 +81,8 @@ class ir_attachment(osv.osv): return super(ir_attachment, self).create(cr, uid, values, context) def action_get(self, cr, uid, context=None): - dataobj = self.pool.get('ir.model.data') - data_id = dataobj._get_id(cr, 1, 'base', 'action_attachment') - res_id = dataobj.browse(cr, uid, data_id, context).res_id - return self.pool.get('ir.actions.act_window').read(cr, uid, res_id, [], context) + return self.pool.get('ir.actions.act_window').for_xml_id( + cr, uid, 'base', 'action_attachment', context=context) def _name_get_resname(self, cr, uid, ids, object,method, context): data = {} diff --git a/bin/addons/base/res/res_widget.py b/bin/addons/base/res/res_widget.py index b240ba7dfb3..f83cbe364b4 100644 --- a/bin/addons/base/res/res_widget.py +++ b/bin/addons/base/res/res_widget.py @@ -49,11 +49,8 @@ class res_widget_wizard(osv.osv_memory): } def action_get(self, cr, uid, context=None): - dataobj = self.pool.get('ir.model.data') - data_id = dataobj._get_id(cr, 1, 'base', 'action_res_widget_wizard') - res_id = dataobj.browse(cr, uid, data_id, context).res_id - return self.pool.get('ir.actions.act_window').read( - cr, uid, res_id, [], context) + return self.pool.get('ir.actions.act_window').for_xml_id( + cr, uid, 'base', 'action_res_widget_wizard', context=context) def res_widget_add(self, cr, uid, ids, context=None): wizard = self.read(cr, uid, ids, context=context)[0]