ODOOJSONRPC:获取M2M,M2O或One2many Nested字段,带有readMethod

问题描述 投票:0回答:1

odoo jsonrpc默认API,是否有一种方法可以在ODOO上获得直接嵌套的字段内容,例如Many2many,Many2One或One2many在单个读取中:

{
  "jsonrpc": "2.0",
  "params": {
    "model": "car.rental.contract",
    "method": "read",
    "args": [[7]],
    "kwargs": {}
  }
}

对于此示例,我想做类似的事情:

{
    "kwargs": {
      "fields": ["customer_id__email"]
    }
}
python odoo json-rpc odoo-17
1个回答
0
投票
Afaik在Odoo的本地JSON-RPC中不可能。但是您可以使用一个更好的库之一,甚至在

文件文档中提到了这些库:

  • https://github.com/akretion/ooor
  • https://github.com/oca/odoorpc
  • https://github.com/nicolas-van/openerp-client-lib
  • http://pythonhosted.org/odoorpc
  • https://github.com/abhishek-jaiswal/php-openerp-lib
例如,

odoorpc

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"

    
	

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.