PHP code example of spejder / odoo-client
1. Go to this page and download the library: Download spejder/odoo-client library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
spejder / odoo-client example snippets
use Spejder\Odoo\Odoo;
$url = 'example.odoo.com/xmlrpc/2';
$database = 'example-database';
$user = '[email protected] ';
$password = 'yourpassword';
$client = new Odoo($url, $database, $user, $password);
use Spejder\Odoo\Odoo;
use Laminas\Http\Client as HttpClient;
$httpClient = new HttpClient(null, [
'sslverifypeer' => false,
]);
// constructor argument
$client = new Odoo($url, $database, $user, $password, $httpClient);
// or setter
$client = new Odoo($url, $database, $user, $password);
$client->setHttpClient($httpClient);
$client->version();
$client->timezone();
$criteria = [
['customer', '=', true],
];
$limit = 10;
$offset = 0;
$client->search('res.partner', $criteria, $offset, $limit);
$ids = $client->search('res.partner', [['customer', '=', true]], 0, 10);
$fields = ['name', 'email', 'customer'];
$customers = $client->read('res.partner', $ids, $fields);
$data = [
'name' => 'John Doe',
'email' => '[email protected] ',
];
$id = $client->create('res.partner', $data);
// change email address of user with current email address [email protected]
$ids = $client->search('res.partner', [['email', '=', '[email protected] ']], 0, 1);
$client->write('res.partner', $ids, ['email' => '[email protected] ']);
// 'uncustomer' the first 10 customers
$ids = $client->search('res.partner', [['customer', '=', true]], 0, 10);
$client->write('res.partner', $ids, ['customer' => false]);
$ids = $client->search('res.partner', [['email', '=', '[email protected] ']], 0, 1);
$client->unlink('res.partner', $ids);
$ids = $client->search('res.partner', [['customer', '=', true]], 0, 10);
$report = $client->getReport('res.partner', $ids);