Odoo Web Service API
Odoo Web服务暴露出相关的服务,路由分别是
- /xmlrpc/
- /xmlrpc/2/
- /jsonrpc
根据 services 调用 后端对应服务的 方法method 【定义 openerp\http.py 之 dispatch_rpc()】,然后再将结果从python dict 转换为 xml-rpc 格式 或者 json-rpc 返回
service 对应的后端服务分别是
- common, openerp.service.common
- db,openerp.service.db
- object , openerp.service.model
- report, openerp.service.report
各服务提供的方法如下
service
method
说明
common
login
authenticate
version
about
set_loglevel
db
create_database
duplicate_database
drop
dump
restore
rename
change_admin_password
migrate_database
db_exist
list
list_lang
list_countries
server_version
object
execute
execute_kw
execute_workflow
report
report
report_get
render_report
实现自己的方法时,要按照约定,以 'exp_' 开头。
XML-RPC接口调用
#在 note.note 模型创建新纪录
- import xmlrpclib
- root = 'http://%s:%d/xmlrpc/' % (HOST, PORT)
- uid = xmlrpclib.ServerProxy(root + 'common').login(DB, USER, PASS) # common是服务,login 是方法
- print "Logged in as %s (uid: %d)" % (USER, uid)
- # Create a new note
- sock = xmlrpclib.ServerProxy(root + 'object')
- args = {
- 'color' : 8,
- 'memo' : 'This is a note',
- 'create_uid': uid,
- }
note_id = sock.execute(DB, uid, PASS, 'note.note', 'create', args) #调用服务'object'的方法 execute(),传入的参数为 (DB, uid, PASS, 'note.note', 'create', args)
JSON-RPC接口调用
#在 note.note 模型创建新纪录
import jsonrpclib
# server proxy object
url = "http://%s:%s/jsonrpc" % (HOST, PORT)
server = jsonrpclib.Server(url)
# log in the given database
uid = server.call(service="common", method="login", args=[DB, USER, PASS]) #调用服务'common'的方法 login()
# helper function for invoking model methods
def invoke(model, method, *args):
args = [DB, uid, PASS, model, method] + list(args)
return server.call(service="object", method="execute", args=args) #调用服务'object'的方法 execute()
# create a new note
args = {
'color' : 8,
'memo' : 'This is another note',
'create_uid': uid,
}
note_id = invoke('note.note', 'create', args) #传入参数
其他
同时odoo Web 还为 odoo web client 提供了 大量的 json-rpc接口。例如数据集提供的服务如下, 定义在 class DataSet(http.Controller) [ addons\web\controllers\main.py ]。
routing
说明
/web/dataset/search_read
/web/dataset/load
/web/dataset/call
/web/dataset/call_kw
/web/dataset/call_buttion
/web/dataset/exec_workflow
/web/dataset/resequence
webclient 在调用 工作流时,直接 调用 rpc服务
/**
* Executes a signal on the designated workflow, on the bound OpenERP model
*
* @param {Number} id workflow identifier
* @param {String} signal signal to trigger on the workflow
*/
exec_workflow: function (id, signal) {
return session.rpc('/web/dataset/exec_workflow', {
model: this.name,
id: id,
signal: signal
});
},
转载注明原作者 /by Jeffery
Odoo Web Service API的更多相关文章
- 【完全开源】百度地图Web service API C#.NET版,带地图显示控件、导航控件、POI查找控件
目录 概述 功能 如何使用 参考帮助 概述 源代码主要包含三个项目,BMap.NET.BMap.NET.WindowsForm以及BMap.NET.WinformDemo. BMap.NET 对百度地 ...
- 【转】【完全开源】百度地图Web service API C#.NET版,带地图显示控件、导航控件、POI查找控件
[转][完全开源]百度地图Web service API C#.NET版,带地图显示控件.导航控件.POI查找控件 目录 概述 功能 如何使用 参考帮助 概述 源代码主要包含三个项目,BMap.NET ...
- VMware 虚拟化编程(3) —VMware vSphere Web Service API 解析
目录 目录 前文列表 VMware vSphere Web Services API VMware vSphere Web Services SDK vSphere WS API 中的托管对象 Man ...
- 使用Web Service进行网络编程-----Web Service简介
Android应用通常都是运行在手机平台上,手机系统的硬件资源是有限的,不管是存储能力还是计算能力都是有限的,在Android系统上开发.运行一些单用户.小型应用是可能的,但对于需要进行大量的数据处理 ...
- REST和SOAP Web Service的区别比较
本文转载自他人的博客,ArcGIS Server 推出了 对 SOAP 和 REST两种接口(用接口类型也许并不准确)类型的支持,本文非常清晰的比较了SOAP和Rest的区别联系! ///////// ...
- 微软BI 之SSIS 系列 - 在 SSIS 中使用 Web Service 以及 XML 解析
开篇介绍 Web Service 的用途非常广几乎无处不在,像各大门户网站上的天气预报使用到的第三方 Web Service API,像手机客户端和服务器端的交互等都可以通过事先设计好的 Web Se ...
- WCF、Web API、WCF REST、Web Service比较
原文地址:http://www.dotnet-tricks.com/Tutorial/webapi/JI2X050413-Difference-between-WCF-and-Web-API-and- ...
- Difference between WCF and Web API and WCF REST and Web Service
The .Net framework has a number of technologies that allow you to create HTTP services such as Web S ...
- WCF 、Web API 、 WCF REST 和 Web Service 的区别
WCF .Web API . WCF REST 和 Web Service 的区别 The .Net framework has a number of technologies that allow ...
随机推荐
- Mysql数据库中存储中文为乱码
1. 修改数据库的编码格式为utf8 2. 修改表的编码格式为utf8 3. 修改字段的编码格式为utf8 祝你好运!
- js访问xml
从w3school中获取代码 <html> <head> <script type="text/javascript"> var xmlhttp ...
- C语言获得文件一行
C语言获得一行的数据还是比较麻烦的,这里讲一下几种曾经用过的方法. 第一种,是最笨的方法,就是一个一个字符的读取,也是最容易想到的方法.具体实现如下:void read_line(char l ...
- 如何在winform或者wpf里面打开浏览器并设置宽高位置
需要SHDocVw.dll 文件或AxSHDocVw.dll 文件,.net默认是没有的,先生产这两个文件,请在Visual Studio 命令提示符下运行下面的命令: aximp %WINDIR%\ ...
- (转)C语言_测试程序运行内存状态GlobalMemoryStatus使用案例
在做毕业设计的时候,需要验证算法的空间复杂度,C语言网上都说是用GlobalMemoryStatus这个函数,但是网上却没有这个函数的使用实例,也有人说是用内存分析器的东西,但是这个显然是不靠谱的. ...
- python多进程提高cpu利用率
cpu参数: 1个物理cpu,2个逻辑cpu(超线程),单核 具体 http://blog.csdn.net/dba_waterbin/article/details/8644626 物理CPU. ...
- vc-complex-type.2.3: Element 'filter-mapping' cannot have character [children], because the type's content type is element-only.
报这种错一般是因为导入的项目或者黏贴的代码中有中文空格或者中文编码,只需将报错代码重写一遍即可.
- openstack vm_lifecycle
nova instance状态:power_state, vm_state, task_state 2015-09-22 Openstack 185 nova instance有3种状态:power_ ...
- Linux:安装rstatd,报错
[安装] 下载地址:http://heanet.dl.sourceforge.net/sourceforge/rstatd/安装:一次执行--tar -xzvf rpc.rstatd-4.0.1.ta ...
- FreeMark学习(二)
(1)用户定义指令 宏和变换器变量是两种不同类型的用户定义指令,它们之间的区别是宏是在模板中使用macro指令定义,而变换器是在模板外由程序定义,这里只介绍宏 基本用法 宏是和某个变量关联的模板片断, ...