<rt id="umcai"><optgroup id="umcai"></optgroup></rt>
<tr id="umcai"><small id="umcai"></small></tr><rt id="umcai"><small id="umcai"></small></rt>
<acronym id="umcai"><small id="umcai"></small></acronym>

Odoo Web Service API

odoo使用 wsgi 提供 XML_RPC 接口, 同時也為 web client 提供了 JSON-RPC

? ?

Odoo Web服務 暴露出 相關的服務, 路由分別是

  1. /xmlrpc/
  2. /xmlrpc/2/
  3. /jsonrpc

? ?

根據 services 調用 后端對應服務的 方法method 【定義 openerp\http.py 之 dispatch_rpc()】,然后再將結果從python dict 轉換為 xml-rpc 格式 或者 json-rpc 返回

? ?

service 對應的后端服務分別是

  1. common, openerp.service.common
  2. db,openerp.service.db
  3. object , openerp.service.model
  4. 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

});

},

? ?

? ?

<rt id="umcai"><optgroup id="umcai"></optgroup></rt>
<tr id="umcai"><small id="umcai"></small></tr><rt id="umcai"><small id="umcai"></small></rt>
<acronym id="umcai"><small id="umcai"></small></acronym>