File: example.py

package info (click to toggle)
python-odoorpc 0.5.1-1
  • links: PTS, VCS
  • area: main
  • in suites: buster, stretch
  • size: 568 kB
  • ctags: 520
  • sloc: python: 2,894; makefile: 154; sh: 4
file content (34 lines) | stat: -rw-r--r-- 846 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# taken from http://pythonhosted.org/OdooRPC/index.html#quick-start

from __future__ import print_function

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