I'm trying to fetch data from Odoo8 database using XML-RPC.
I have request like this written in Python:
common = xmlrpclib.ServerProxy('{}/xmlrpc/2/common'.format(url))
uid = common.authenticate(db, username, password, {})
models = xmlrpclib.ServerProxy('{}/xmlrpc/2/object'.format(url))
test = models.execute_kw(db, uid, password,
'calendar.event', 'search_read',
[['&',['start_datetime', '>=', '2019-09-03 00:00:00'],['stop_datetime', '<', '2019-09-10 00:00:00']]],
{'fields': ['allday', 'start_datetime', 'start_date', 'stop_datetime'], 'limit': 5})
But I get records that exceed requested date range.
I also tried to use date instead datetime (this fields are used when event is marked as all day) but does not work as well.
I’m using hard-coded string just for testing. Ultimately I will use something like this:
datetime.today().strftime("%Y-%m-%d %H:%M:%S")
How do I fetch data only from desired date range?
I just found the solution.
I was trying to use start_date
or start_datetime
inside my domain but actually there is another field called just start
which is working fine (or stop
for that matter if stop date is what you are looking for).
Opposed to start_date
and start_datetime
it is stored field so it can be used inside domain.
This is how modified request would look like:
models = xmlrpclib.ServerProxy('{}/xmlrpc/2/object'.format(url))
test = models.execute_kw(db, uid, password,
'calendar.event', 'search_read',
[[['start', '>=', '2019-09-01 00:00:00'],['start', '<=', '2019-09-08 00:00:00']]],
{'fields': ['name', 'allday', 'start', 'stop']})
Thanks to @Elegant Odoo for the help and pushing me on the right track.