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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
#!/usr/bin/python
# Future proof: the library should be Python 2.6+ and 3.x compatible.
from __future__ import print_function
# OpeneERP ROWS will be renamed if it proves to be useful.
import openerprows
if __name__ == '__main__':
c = openerprows.criteria()
rows = openerprows.rows()
# Adapt these values to your setup.
rows.configure(
host = 'runbot.openerp.com',
port = 8069,
database = 'trunk',
username = 'admin',
password = 'a',
)
# It is very simple to loop through all rows of some table.
for u in rows.res_users:
print(u.name)
# If necessary, some debugging infromation can be printed.
# TODO the syntax could drop the (): rows.res_users.debug
for u in rows.res_users.debug():
print(u.name)
# Get all the ids if necessary.
print(rows.res_partner.ids())
# Get data for a particular row...
print(rows.res_partner[1].name)
# ... or for many rows by specifying their ids.
for p in rows.res_partner(1,2):
print(p.name)
# TODO offer rows.res_partner(1,2).name to get a list of names?
# Using a domain to constrain the results TODO better example
for p in rows.res_partner.where(c.name.like('ASUS')):
print(p.name)
for p in rows.res_partner(17,18,19,20).where(c.name.like('a')).where(c.credit_limit > 100).debug():
pass
# Unfortunately, grouping is needed.
for p in rows.res_partner((c.name.like('a')) & (c.credit_limit > 100)):
pass
# In fact, since the return type is the same as the original one:
for p in rows.res_partner(c.name.like('a'))(1,2):
pass
# And thus:
for p in rows.res_partner(c.name.like('a'))(c.credit_limit > 100):
pass
cx = (c.name < 4) & (c.attendees > 5) # & child_of(c.object.company_id, c.user.company_id)
# Allow ?
#(c.name < 4)(c.attendees > 5)
|