A wrapper for Odoo's External API.
Project description
Odoo API Wrapper
A wrapper for Odoo's External API.
You can check out the official documentation here.
odoo_api_wrapper.api.Api
is the main class, odoo_api_wrapper.api.Operations
defines
the operations used for odoo_api_wrapper.api.Api.call
, raises
odoo_api_wrapper.api.APIError
.
Installation
pip install odoo-api-wrapper
Usage Examples
Instantiate an Api
Create an instance of the API to start using it.
import odoo_api_wrapper
api = odoo_api_wrapper.Api("http://localhost:8069", "db", "1001", "password")
Define your model
partner = odoo_api_wrapper.Model(api, "res.partner")
List records
Records can be listed and filtered via search()
.
partner.search([[['is_company', '=', True]]])
Count records
Rather than retrieve a possibly gigantic list of records and count them,
search_count()
can be used to retrieve only the number of records matching the query.
It takes the same domain filter as search()
and no other parameter.
partner.search_count([[['is_company', '=', True]]])
Read records
Record data are accessible via the read()
method, which takes a list of ids (as
returned by search()
), and optionally a list of fields to fetch. By default, it
fetches all the fields the current user can read, which tends to be a huge amount.
ids = partner.search([[['is_company', '=', True]]], {'limit': 1})
[record] = partner.read([ids])
# count the number of fields fetched by default
len(record)
List record fields
fields_get()
can be used to inspect a model’s fields and check which ones seem to be
of interest.
partner.fields_get([], {'attributes': ['string', 'help', 'type']})
Search and read
Because it is a very common task, Odoo provides a search_read()
shortcut which, as
its name suggests, is equivalent to a search()
followed by a read()
, but avoids
having to perform two requests and keep ids around.
partner.search_read(
[[['is_company', '=', True]]],
{'fields': ['name', 'country_id', 'comment'], 'limit': 5},
)
Create records
Records of a model are created using create()
. The method creates a single record and
returns its database identifier.
id = partner.create([{'name': "New Partner"}])
Update records
Records can be updated using write()
. It takes a list of records to update and a
mapping of updated fields to values similar to create()
.
partner.write([[id], {'name': "Newer partner"}])
Delete records
Records can be deleted in bulk by providing their ids to unlink()
.
partner.unlink([[id]])
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.