odoo 下 get_object_reference 函数
2024-08-27 20:05:45
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视图
最新文章
- MySQL的Grant命令[转]
- github标记
- Proc-fs 编程
- SqlServer2008R2 修改表中列为自增列
- Linux 安装挂载时注意事项
- spark stream初探
- QQ浏览器不支持JS问题
- 关于webroot与web-inf
- Java网络编程:利用apache的HttpClient包进行http操作
- Java基础之数据类型和转换
- mysql常用基础操作语法(二)~~对表的增删改操作【命令行模式】
- [高级软件工程教学]团队Alpha阶段成绩汇总
- PyQT5 helloworld教程(转载)
- 类别不平衡问题和Softmax回归
- Java——静态变量/方法与实例变量/方法的区别
- mysql8.0.13免安装版配置
- SpringBoot之基础
- 格式化输出函数:printf 那些事 (C语言)
- [leetcode]Jump Game @ Python
- CentOS编绎gcc
热门文章
- iOS开发UIResponder简介API
- 剑指offer——18打印从1到最大的n位数
- js用document.getElementById时要注意!
- 记一次java简单的if语句使用多态重构
- 面向XX程序设计到底是个啥
- java 迷你DVD管理器
- SVN Cannot merge into a working copy that has local modifications
- springboot 简单搭建(thymeleaf 视图显示)
- PokerNet-poker recognition: 扑克识别 (6)
- 为什么串行传输时总是LSB在前?