leblanc-simon / openerpbyjsonrpc
Library to communicate into PHP and OpenERP (Odoo)
2.1.0
2022-01-11 14:41 UTC
Requires
- php: ^7.3 || ~8.0.0 || ~8.1.0
- ext-json: *
- laminas/laminas-http: ^2.15
- laminas/laminas-json: ^3.3
- laminas/laminas-json-server: ^3.4
- laminas/laminas-server: ^2.11
Requires (Dev)
- phpstan/phpstan: ^0.12.49
- phpunit/phpunit: ~9.4
This package is auto-updated.
Last update: 2024-10-11 06:57:33 UTC
README
Communicate with Odoo via JSON-RPC
Installation
composer require leblanc-simon/openerpbyjsonrpc
Usage
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' );
License
Author
Simon Leblanc contact@leblanc-simon.eu