Skip to content

Commit

Permalink
Small additions
Browse files Browse the repository at this point in the history
  • Loading branch information
Edujugon committed Oct 4, 2018
1 parent bf73f65 commit e198e13
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 29 deletions.
45 changes: 22 additions & 23 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@ Odoo ERP API for Laravel. [Odoo website](https://www.odoo.com)

type in console:

```
```shel
composer require edujugon/laradoo
```

Register Laradoo service by adding it to the providers array.
```
```php
'providers' => array(
...
Edujugon\Laradoo\Providers\OdooServiceProvider::class
)
```

Let's add the Alias facade, add it to the aliases array.
```
```php
'aliases' => array(
...
'Odoo' => Edujugon\Laradoo\Facades\Odoo::class,
Expand All @@ -36,7 +36,7 @@ Let's add the Alias facade, add it to the aliases array.

Publish the package's configuration file to the application's own config directory

```
```php
php artisan vendor:publish --provider="Edujugon\Laradoo\Providers\OdooServiceProvider" --tag="config"
```

Expand All @@ -54,58 +54,57 @@ Also, you can dynamically update those values calling the available setter metho

Instance the main Odoo class:

```
```php
$odoo = new \Edujugon\Laradoo\Odoo();
```
You can get the Odoo API version just calling the version method:

```
```php
$version = $odoo->version();
```
> This methods doesn't require to be connected/Logged into the ERP.
Connect and log into the ERP:

```
```php
$odoo = $odoo->connect();
```

All needed configuration data is taken from `laradoo.php` config file. But you always may pass new values on the fly if required.

```
```php
$this->odoo = $this->odoo
->username('my-user-name')
->password('my-password)
->password('my-password')
->db('my-db')
->host('https://my-host.com')
->connect();
// Note: `host` should contain 'http://' or 'https://'
```

> // Note: `host` should contain 'http://' or 'https://'
After login, you can check the user identifier like follows:

```
```php
$userId= $this->odoo->getUid();
```

You always can check the permission on a specific model:

```
```php
$can = $odoo->can('read', 'res.partner');
```
> Permissions which can be checked: 'read','write','create','unlink'
Method `search provides a collection of ids based on your conditions:

```
```php
$ids = $odoo->where('customer', '=', true)
->search('res.partner');
```

You can limit the amount of data using `limit` method and use as many as condition you need:

```
```php
$ids = $odoo->where('is_company', true)
->where('customer', '=', true)
->limit(3)
Expand All @@ -114,15 +113,15 @@ $ids = $odoo->where('is_company', true)

If need to get a list of models, use the `get` method:

```
```php
$models = $odoo->where('customer', true)
->limit(3)
->get('res.partner');
```

Instead of retrieving all properties of the models, you can reduce it by adding `fields` method before the method `get`

```
```php
$models = $odoo->where('customer', true)
->limit(3)
->fields('name')
Expand All @@ -131,36 +130,36 @@ $models = $odoo->where('customer', true)

If not sure about what fields a model has, you can retrieve the model structure data by calling `fieldsOf` method:

```
```php
$structure = $odoo->fieldsOf('res.partner');
```

Till now we have only retrieved data from the ERP but you can also Create and Delete records.

In order to create a new record just call `create` method as follows:

```
```php
$id = $odoo->create('res.partner',['name' => 'Jonh Odoo']);
```
> The method returns the id of the new record.
For Deleting records we have the `delete` method:

```
```php
$result = $odoo->where('name', 'Jonh Odoo')
->delete('res.partner');
```
> Notice that before calling `delete` method you have to use `where`.
You can also remove records by ids like follows:

```
```php
$result = $odoo->deleteById('res.partner',$ids);
```

Update any record of your ERP:

```
```php
$updated = $odoo->where('name', 'John Odoo')
->update('res.partner',['name' => 'John Odoo Odoo','email' => '[email protected]']);
```
Expand All @@ -169,7 +168,7 @@ Notice that all `delete` and `update` methods always returns `true` except if th

`call` method is also available for those who want to set a custom API call:

```
```php
$odoo->call('res.partner', 'search',[
[
['is_company', '=', true],
Expand Down
8 changes: 4 additions & 4 deletions src/Config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
'api-suffix' => 'xmlrpc', // 'xmlrpc' from version 7.0 and earlier, 'xmlrpc/2' from version 8.0 and above.

//Credentials
'host' => '',
'db' => '',
'username' => '',
'password' => '',
'host' => 'https://my-host.com', // should contain 'http://' or 'https://'
'db' => 'my-db',
'username' => 'my-username',
'password' => 'my-password',
];
2 changes: 0 additions & 2 deletions tests/OdooTest.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
<?php


use Edujugon\Laradoo\Odoo;
use PHPUnit\Framework\TestCase;

class OdooTest extends TestCase
{


protected $odoo;

/**
Expand Down

0 comments on commit e198e13

Please sign in to comment.