odoo odoorpc RPC API

import odoorpc

# Prepare the connection to the server
odoo = odoorpc.ODOO('127.0.0.1', port=8069)

# Check available databases
print(odoo.db.list())

# # Login
odoo.login('odooshequ', 'admin', 'admin')

#
# # Current user
user = odoo.env.user

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

#
# # 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"

  

posted @ 2023-05-01 21:44  CrossPython  阅读(49)  评论(0编辑  收藏  举报