How to do it...

Perform the following steps to fetch book data from the library.book model:

  1. Add the jsonrpc_fetch_data.py file. You can place this file anywhere you want because the RPC program will work independently.
  2. Add the following code to the file:
# place authentication and get_json_payload methods (see first jsonrpc recipe)

if user_id:
# search for the books ids
search_domain = ['|', ['name', 'ilike', 'odoo'], ['name', 'ilike', 'sql']]
payload = get_json_payload("object", "execute_kw",
db_name, user_id, password,
'library.book', 'search', [search_domain], {'limit': 5})
res = requests.post(json_endpoint, data=payload, headers=headers).json()
print('Search Result:', res) # ids will be in result keys

# read data for books ids
payload = get_json_payload("object", "execute_kw",
db_name, user_id, password,
'library.book', 'read', [res['result'], ['name', 'date_release']])
res = requests.post(json_endpoint, data=payload, headers=headers).json()
print('Books data:', res)
else:
print("Failed: wrong credentials")
  1. Run the Python script from the Terminal with the following command:
python3 jsonrpc_fetch_data.py

The preceding program will give you the following output. The first RPC call will print the book's id and the second one will print the information for the book's id:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset