Download the PHP package wdelfuego/php-odoo-api-client without Composer
On this page you can find all versions of the php package wdelfuego/php-odoo-api-client. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package php-odoo-api-client
PHP Odoo API client
Odoo API client using XML-RPC Odoo ORM External API. It allows you call your odoo instance and manage records easily.
You are reading the documentation of version , if your version is older, please read this documentation (6.1.3). Please see the file UPGRADE-7.0.md to upgrade your version easily.
Main features
- Authentication
- Basic XML-RPC calls
- Expression builder
- Database Abstraction Layer (DBAL)
- Record manager
- Repositories`
- Query builder
Good to know
If you are in Symfony application you should be interested in the bundle ang3/odoo-bundle (client integration).
Requirements
- The PHP extension must be enabled.
Odoo server | Compatibility | Comment |
---|---|---|
newer | Unknown | Needs feddback |
v13.0 | Yes | Some Odoo model names changed (e.g account.invoice > account.move) |
v12.0 | Yes | First tested version |
< v12 | Unknown | Needs feddback |
Installation
Open a command console, enter your project directory and execute the following command to download the latest stable version of the client:
This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.
Basic usage
First, you have to create a client instance:
Exceptions:
- when a required parameter is missing from the static method .
Then, make your call:
Exceptions:
- when authentication failed.
- when request failed.
These previous exception can be thrown by all methods of the client.
DBAL (Database Abstraction Layer)
First of all, Odoo is a database. Each "model" is a table and has its own fields.
DBAL features was added in version - If your version is older, please use the built-in ORM methods of the client like explained in the dedicated documentation: be aware that these client ORM methods are deprecated since version .
Record manager
The client provides a record manager to manage records of your Odoo models.
You can get the related manager of the client like below:
You can also create your own with a client instance:
Built-in ORM methods
Here is all built-in ORM methods provided by the record manager:
For in select/search queries and for data writing context, please read the section Expression builder.
Schema
You can get the schema of your Odoo database by calling the getter method :
The schema helps you to get all model names or get metadata of a model.
Get all model names
Get model metadata
An exception of type is thrown if the model does not exist.
Query builder
It helps you to create queries easily by chaining helpers methods (like Doctrine for SQL databases).
Create a query builder
The variable represents the target model of your query (clause ).
Build your query
Here is a complete list of helper methods available in :
Then, build your query like below:
Your query is an instance of .
Execute your query
You can get/count results or execute insert/update/delete by differents ways depending on the query type.
Repositories
Sometimes, you would want to keep your queries in memory to reuse it in your code. To do it, you should use a repository. A repository is a class that helps you to isolate queries for a dedicated model.
For example, let's create the repository for your companies and define a query to get all french companies:
Note that Odoo will always return the record ID in the result, even if you didn't select it explicitly.
Each repository is registered inside the record manager on construct. That's why you can retrieve your repository directly from the record manager:
If no repository exists for a model, the default repository
is used. Last but not least, all repositories are stored into the related record manager to avoid creating multiple
instances of same repository.
Expression builder
There are two kinds of expressions : for criteria and in data writing context. Odoo has its own array format for those expressions. The aim of the expression builder is to provide some helper methods to simplify your programmer's life.
Here is an example of how to get a builder from a client or record manager:
You can still use the expression builder as standalone by creating a new instance:
Domains
For all select/search/count queries, Odoo is waiting for an array of domains with a polish notation for logical operations (, and ).
It could be quickly ugly to do a complex domain, but don't worry the builder makes all for you. :-)
Each domain builder method creates an instance of . The only one method of this interface is to get a normalized array of the expression.
To illustrate how to work with it, here is an example using helper methods:
Of course, you can nest logical nodes:
Internally, the client formats automatically all domains by calling the special builder method .
Here is a complete list of helper methods available in for domain expressions:
Collection operations
In data writing context with queries of type insert/update, Odoo allows you to manage *toMany collection fields with special commands.
Please read the ORM documentation to known what we are talking about.
The expression builder provides helper methods to build a well-formed operation command: each operation method returns an instance of . Like domains, the only one method of this interface is to get a normalized array of the expression.
To illustrate how to work with operations, here is an example using helper methods:
Internally, the client formats automatically the whole query parameters for all writing methods ( and ) by calling the special builder method .
Here is a complete list of helper methods available in for operation expressions:
Data support
- Scalar values are unchanged
- Arrays recursive conversion
- Objects of type are automatically formatted into string in UTC timezone
- Iterable/generator are fetched into an array
- Non-iterable values are automatically casted to string (so any non-supported objects must define the method )
Resources
- CHANGELOG.md
All versions of php-odoo-api-client with dependencies
ext-json Version *
ang3/php-xmlrpc-client Version ^1.0.2
psr/log Version ^1.1|^2.0|^3.0