美文网首页
如何使用OdooRPC

如何使用OdooRPC

作者: 千年码妖 | 来源:发表于2018-09-17 14:57 被阅读38次

    OdooRPC是一个Python包,提供了一种通过RPC访问Odoo服务的简便方法。

    主要功能:

    1. 使用类似于服务器端API的API访问所有数据模型方法(甚至是浏览);

    2. 使用模型方法命名参数;

    3. 自动发送用户上下文,为国际化提供支持

    4. 浏览记录;

    5. 执行工作流;

    6. 管理数据库;

    7. 下载报表;

    8. JSON-RPC协议(支持SSL)

    要使用OdooRPC,首先我们要在服务器上安装OdooRPC服务。

    执行命令如下:

    pip install OdooRPC

    使用rpc的代码如下:

    import odoorpc

    # Prepare the connection to the server

    odoo = odoorpc.ODOO('localhost', port=8069)

    # Check available databases

    print(odoo.db.list())

    # Login

    odoo.login('db_name', 'user', 'passwd')

    # Current user

    user = odoo.env.user

    print(user.name)            # name of the user connected

    print(user.company_id.name) # the name of its company

    # Simple 'raw' query

    user_data = odoo.execute('res.users', 'read', [user.id])

    print(user_data)

    # Use all methods of a model

    if 'sale.order' in odoo.env:

        Order = odoo.env['sale.order']

        order_ids = Order.search([])

        for order in Order.browse(order_ids):

            print(order.name)

            products = [line.product_id.name for line in order.order_line]

            print(products)

    # Update data through a record

    user.name = "Brian Jones"

    支持的Odoo服务版本:

    OdooRPC已经支持在 Odoo 8.0, 9.0, 10.0 和11.0等版本上使用. 它应该也支持在Odooo的后续版本中使用,如果Odoo保持它的API稳定的话。

    支持的Python版本:

    OdooRPC 支持Python 2.7, 3.4, 3.5 和 3.6等。

    相关文章

      网友评论

          本文标题:如何使用OdooRPC

          本文链接:https://www.haomeiwen.com/subject/uxilnftx.html