PHP code example of leblanc-simon / openerpbyjsonrpc
1. Go to this page and download the library: Download leblanc-simon/openerpbyjsonrpc 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/ */
leblanc-simon / openerpbyjsonrpc example snippets
use OpenErpByJsonRpc\JsonRpc\ZendJsonRpc;
use OpenErpByJsonRpc\JsonRpc\OpenERP;
use OpenErpByJsonRpc\Storage\FileStorage;
use OpenErpByJsonRpc\Client\Session;
use OpenErpByJsonRpc\Client\Database;
use OpenErpByJsonRpc\Client\Model;
use OpenErpByJsonRpc\Criteria;
$jsonrpc = new ZendJsonRpc('http://odoo.com');
$odoo = new OpenERP($jsonrpc, new FileStorage([
'directory' => 'path/to/cache',
'prefix' => 'session_',
]));
$odoo
->setBaseUri('http://odoo.com')
->setPort(null)
->setUsername('admin')
->setPassword('admin')
->setDatabase('main')
->reconnectOrLogin(null)
;
// If you use FileStorage, you can reconnect without username and password
// $session_id can be retrieve via Session::getInfos()
$odoo->reconnectOrLogin($session_id);
///////////////////////////////
// Model methods
//
$model = new Model($odoo);
// Read a single record
$model->readOne('res.users', 1, ['id', 'login']);
// Search records
// * use array for criteria
$model->search('res.users', [['login', '=', 'admin']], ['id', 'login']);
// * use Criteria class : search login = admin AND name = admin
$criteria = new Criteria();
$criteria
->equal('login', 'admin')
->equal('name', 'admin')
;
$model->search('res.users', $criteria, ['id', 'login']);
// Create record
$id = $model->create('res.partner', [
'name' => 'Jean Dupont',
'function' => 'DRH',
'phone' => '+330120304050',
]);
// Update record
$model->create('res.partner', $id, [
'name' => 'Jean Dupond',
]);
// Delete record
$model->create('res.partner', $id);
///////////////////////////////
// Session methods
//
$session = new Session($odoo);
// Get the session informations
$session->getInfos();
// Get the availables languages
$session->getLangList();
// Get the availables modules
$session->getModules();
// Change your current password
$session->changePassword('admin', 'new pass');
///////////////////////////////
// Database methods
//
$database = new Database($odoo);
// Get the list of available database
$database->getList();
// Create a new database
$database->create(
'master password', // your master password in your odoo config file
'database_name',
false, // true if you want add demo data
'fr_FR',
'admin' // the admin password for the created database
);
// Duplicate a database
$database->duplicate(
'master password', // your master password in your odoo config file
'database_to_duplicate',
'new_database'
);
// Drop a database
$database->drop(
'master password', // your master password in your odoo config file
'database_name'
);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.