PHP code example of robroypt / odoo-client
1. Go to this page and download the library: Download robroypt/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/ */
robroypt / odoo-client example snippets
use OdooClient\Client;
........
$url = 'example.odoo.com/xmlrpc/2';
$database = 'example-database';
$user = '[email protected] ';
$password = 'yourpassword';
$client = new Client($url, $database, $user, $password);
$client->version();
$criteria = [
['customer', '=', true],
];
$offset = 0;
$limit = 10;
$client->search('res.partner', $criteria, $offset, $limit);
$criteria = [
['customer', '=', true],
];
$client->search_count('res.partner', $criteria);
$ids = $client->search('res.partner', [['customer', '=', true]], 0, 10);
$fields = ['name', 'email', 'customer'];
$customers = $client->read('res.partner', $ids, $fields);
$criteria = [
['customer', '=', true],
];
$fields = ['name', 'email', 'customer'];
$customers = $client->search_read('res.partner', $criteria, $fields, 10);
$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);