odoo 下 get_object_reference 函数

get_object_reference是 ir.model.data 模块中下的一个函数

该函数通过调用ir.model.data 模块中另外一个函数 xmlid_lookup 返回结果


def get_object_reference(self, cr, uid, module, xml_id):
    """Returns (model, res_id) corresponding to a given module and xml_id (cached) or raise ValueError if not found"""
    return self.xmlid_lookup(cr, uid, "%s.%s" % (module, xml_id))[1:3]
# NEW V8 API
    @tools.ormcache(skiparg=3)
    def xmlid_lookup(self, cr, uid, xmlid):
        """Low level xmlid lookup
        Return (id, res_model, res_id) or raise ValueError if not found
        """
        module, name = xmlid.split('.', 1)
        ids = self.search(cr, uid, [('module','=',module), ('name','=', name)])
        if not ids:
            raise ValueError('External ID not found in the system: %s' % (xmlid))
        # the sql constraints ensure us we have only one result
        res = self.read(cr, uid, ids[0], ['model', 'res_id'])
        if not res['res_id']:
            raise ValueError('External ID not found in the system: %s' % (xmlid))
        return ids[0], res['model'], res['res_id']

返回的是  xml  视图id   model  res_id

实例:

@api.multi
    def popup_wizard( self ):
        if self._context is None:
            self._context = {}
        ir_model_data = self.env['ir.model.data']
        try:
            compose_form_id = ir_model_data.get_object_reference( 'ir_export_extended_ept', 'export_wizard_view_ept' )[1]
        except ValueError:
            compose_form_id = False
        return {
            'name': _( 'Export File' ),
            'res_model': 'export.wizard.ept',
            'type': 'ir.actions.act_window',
            'view_id': compose_form_id,
            'view_mode': 'form',
            'view_type': 'form',
            'target': 'new',
        }

在odoo里有很多类似例子,用它来返回一个form视图

原文地址:https://www.cnblogs.com/dancesir/p/6865823.html