zoukankan      html  css  js  c++  java
  • 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视图

  • 相关阅读:
    PayPal(贝宝)支付接口、文档、IPN
    C# LiveUpdate.exe实现文件在线更新升级
    C# 邮件发送
    VisualStudio11预览
    zen coding for visual studio 2010(vs2010)
    淘宝API开发系列淘宝API相关了解
    多年积累
    专业淘友必不可少的资料,教你如何玩转淘宝!
    极速理解设计模式系列
    ASP.NET开发人员经常使用的三十三种代码
  • 原文地址:https://www.cnblogs.com/dancesir/p/6865823.html
Copyright © 2011-2022 走看看