zoukankan      html  css  js  c++  java
  • Odoo Web Service API

    Odoo Web服务暴露出相关的服务,路由分别是

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

     根据 services 调用 后端对应服务的 方法method 【定义 openerphttp.py 之 dispatch_rpc()】,然后再将结果从python dict 转换为 xml-rpc 格式 或者 json-rpc 返回

       service 对应的后端服务分别是

    1. common openerp.service.common
    2. dbopenerp.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) [ addonswebcontrollersmain.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
  • 相关阅读:
    录屏软件 OBS Studio
    ubuntu安装以及美化
    win10系统软件安装列表
    GNSS数据的弱点
    理解TomoDD生成的地壳模型的格式
    acrobat DC install
    matlab平行运算 parrelpool
    写申请地震台网数据的申请表
    强震动数据的网站
    visual studio各个版本的key
  • 原文地址:https://www.cnblogs.com/odoouse/p/5882749.html
Copyright © 2011-2022 走看看