Closed sebalix closed 5 years ago
Hi,
Yes it is, all public methods of a data model are available dynamically, search
is just one of them, just pass the keyword arguments:
>>> import odoorpc
>>> odoo = odoorpc.ODOO('x.x.x.x')
>>> odoo.login('db', 'admin', 'password')
>>> odoo.env['res.partner'].search([])
[3, 23, 22, 28, 27, 29, 25, 33, 35, 32, 21, 6, 8, 9, 7, 1, 5, 34]
>>> odoo.env['res.partner'].search([], limit=4)
[3, 23, 22, 28]
>>> odoo.env['res.partner'].search([], limit=4, offset=2)
[22, 28, 27, 29]
Then pass the result to the browse
function:
>>> Partner = odoo.env['res.partner']
>>> ids = Partner.search([], limit=4, offset=2)
>>> for partner in Partner.browse(ids):
... print partner.name
...
Regards,
@kvdb is this issue resolved?
From @kvdb on March 16, 2016 15:10
Yes, thank you!
Just one remark: future me and perhaps other users might not know this ability of search()
.
You might want to add this info to your otherwise very complete tutorial page at http://odoorpc.readthedocs.org/en/stable/tutorials.html.
I will do that, thanks for the feedback. I let the issue open until the documentation is updated.
From @Paramon on June 22, 2017 22:29
BWT same in search_read()
If you want the same result as in execute_kw
>>> odoo.execute_kw('res.partner', 'search_read',
... [[['is_company', '=', True], ['customer', '=', True]]],
... {'fields': ['name', 'country_id', 'comment'], 'limit': 1})
[{'comment': False,'country_id': [21, 'Belgium'],'id': 8,'name': 'Agrolait'}]
>>> # Country not used locale !?!
>>> Partner = odoo.env['res.partner']
>>> Partner.search_read([['is_company', '=', True], ['customer', '=', True]],
... {'fields': ['name', 'country_id', 'comment'], 'limit': 1})
[{'id': 8}, {'id': 12}, {'id': 9}, {'id': 45}, {'id': 11}, {'id': 13}]
>>> # Return all ids ???
>>> Partner.search_read ([['is_company', '=', True], ['customer', '=', True]],
... limit=1, fields=['name', 'country_id', 'comment'])
[{'comment': False, 'country_id': [21, 'Бельгія'], 'id': 8, 'name': 'Agrolait'}]
>>> # The same as in execute_kw. But it used my locale!!!
@sebalix the thing with search_read from /jsonrpc is that unlike the search_read from /web/dataset/search_read, it does not returns the length of all the records despite the limit and offset given to the argument, which i think it is necessary for a pagination feature.
From @kvdb on March 14, 2016 15:24
I read about
offset
andlimit
when listing records (https://www.odoo.com/documentation/8.0/api_integration.html). Is this also possible using the search or browse function in odoorpc?Copied from original issue: osiell/odoorpc#28