Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
a02ed72
increate version to 0.5.0
kevin3274 Jan 16, 2016
63067ee
Create LICENSE
cesargutierrezo Jul 27, 2018
02aa02d
Update semver to 1.0.0
cesargutierrezo Jul 27, 2018
a75ce9b
Merge remote-tracking branch 'origin/dev' into dev
cesargutierrezo Jul 27, 2018
7c7e35c
Update package.json info
cesargutierrezo Jul 27, 2018
b972487
Add support for authentication with Odoo session id instead of user/pass
cesargutierrezo Jul 27, 2018
2061e74
Change callback-based implementation for promise-based methods
cesargutierrezo Jul 27, 2018
1b28f03
Remove old test and example files and dependencies
cesargutierrezo Aug 8, 2018
21b0393
Code cleanup and formatting
cesargutierrezo Aug 8, 2018
6431c13
Update README.md
cesargutierrezo Aug 8, 2018
cf3ea8c
Update semver to 0.6.0
cesargutierrezo Aug 8, 2018
04c3142
Merge branch 'release/v0.6.0'
cesargutierrezo Aug 8, 2018
d1b6a4c
Merge branch 'release/v0.6.0' into dev
cesargutierrezo Aug 8, 2018
7aadca2
fix: Remove http url prefix
juanchoperezj Aug 15, 2018
419a2bc
Merge branch 'hotfix/http_fix'
juanchoperezj Aug 15, 2018
edc1e72
Merge branch 'hotfix/http_fix' into dev
juanchoperezj Aug 15, 2018
51a12bc
Fix network error.
gruia-dev Nov 22, 2018
e259834
Fix getting session id from connect response.
gruia-dev Nov 22, 2018
6391495
Send set-cookie in requests.
gruia-dev Nov 22, 2018
9361b32
Merge pull request #1 from BeginnerOnPy/master
gruia-dev Nov 22, 2018
7d20ca4
Update version to v0.6.1
cesargutierrezo Nov 30, 2018
573ffe1
Merge branch 'release/v0.6.1'
cesargutierrezo Nov 30, 2018
bec6ca7
Merge branch 'release/v0.6.1' into dev
cesargutierrezo Nov 30, 2018
4c2cf24
Merge branch 'master' into dev
cesargutierrezo Nov 30, 2018
1913499
Add possibility to send custom context.
gruia-dev Dec 4, 2018
a3d1996
Add possibility configure data transfer protocol.
gruia-dev Dec 4, 2018
be131dc
Update package version and add new maintainer name.
gruia-dev Jan 24, 2019
d050ebe
Update connection instance in readme file.
gruia-dev Jan 24, 2019
1c339fa
Merge pull request #2 from cesar-gutierrez/master
gruia-dev Jan 24, 2019
ed65077
Update package version.
gruia-dev Jan 24, 2019
a9abdc6
Add Read Group method
aidoskz Mar 14, 2019
61a8926
Merge pull request #3 from aidoskz/master
gruia-dev Mar 14, 2019
64a90db
Fix issue with react-native cookie
dorcyv Oct 7, 2019
0a0e709
Fix double session key for IOS devices.
Jan 19, 2020
2486766
Format package json file.
Jan 19, 2020
5f16315
Merge pull request #4 from dorcyv/master
gruia-dev Jan 19, 2020
bae356f
Upgrade package version.
Jan 19, 2020
3e1ffca
Remove publish config.
Jan 19, 2020
423b04c
Upgrade version.
Jan 19, 2020
ca43dd2
Remove 0.6.5 changes.
Jan 19, 2020
073a85d
Update README.md
cesargutierrezo Sep 2, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 0 additions & 19 deletions .jshintrc

This file was deleted.

21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2018 César Gutiérrez Olivares

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
274 changes: 133 additions & 141 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,172 +1,164 @@
# Odoo
# react-native-odoo-promise-based

React Native library for Odoo
⚠️ This repository is no longer being maintained. Feel free to use it for reference and forking.

React Native library for Odoo using the Fetch API and JSON-RPC.

This library is a modified version from the original repository and was created to allow authentication using Odoo session ids for in-app session persistence. Also server response handling was reimplemented using Promises instead of callback functions for convenience.

**This package is still a work in progress** and hasn't been subjected to proper unit testing after the original repository was forked.

## Installation

```bash
$ npm install react-native-odoo
$ npm install react-native-odoo-promise-based
```
or
```bash
$ yarn add react-native-odoo-promise-based
```

## Usage

Please refer to the Odoo [API documentation](https://www.odoo.com/documentation/11.0/webservices/odoo.html) if you need help structuring your database queries. I'll try to make a more thorough explanation in the future about how it works.

**Creating Odoo connection instance**
Before executing any kind of query operations, a connection instance must be established either with a username/password or with a previously retrieved session id.
```js
import Odoo from 'odoo'
import Odoo from 'react-native-odoo-promise-based'

/* Create new Odoo connection instance */
const odoo = new Odoo({
host: 'localhost',
port: 8069,
database: 'demo',
username: 'admin',
password: 'admin'
});

// Connect to Odoo
odoo.connect(function (err) {
if (err) { return console.log(err); }
});

// Get a partner
// https://www.odoo.com/documentation/8.0/api_integration.html#read-records
// https://www.odoo.com/documentation/8.0/reference/orm.html#openerp.models.Model.read
var params = {
host: 'YOUR_SERVER_ADDRESS',
port: 8069, /* Defaults to 80 if not specified */
database: 'YOUR_DATABASE_NAME',
username: 'YOUR_USERNAME', /* Optional if using a stored session_id */
password: 'YOUR_PASSWORD', /* Optional if using a stored session_id */
sid: 'YOUR_SESSION_ID', /* Optional if using username/password */
protocol: 'https' /* Defaults to http if not specified */
})

```

**Connect**
Returns a promise which resolves into an object containing the current users' data, including a session id which can be stored for future connections and session persistence.
```js
odoo.connect()
.then(response => { /* ... */ })
.catch(e => { /* ... */ })
```

**Get (Odoo Read)**
Receives an Odoo database `model` string and a `params` object containing the `ids` you want to read and the `fields` you want to retrieve from each result.

Returns a promise which resolves to an array of results matching the array of ids provided in the parameters.
```js
/* Get partner from server example */
const params = {
ids: [1,2,3,4,5],
fields: [ 'name' ],
}; //params
odoo.get('res.partner', params, function (err, partners) {
if (err) { return console.log(err); }

console.log(partners);
// [
// { id: 1, name: 'Demo Company' },
// { id: 3, name: 'Administrator' },
// { id: 4, name: 'Public user' },
// { id: 5, name: 'Demo User' }
// ]
}); //get


// Search & Get products in one RPC call
// https://www.odoo.com/documentation/8.0/api_integration.html#search-and-read
// https://www.odoo.com/documentation/8.0/reference/orm.html#openerp.models.Model.search
// https://www.odoo.com/documentation/8.0/reference/orm.html#openerp.models.Model.read
var params = {
}

odoo.get('res.partner', params, context)
.then(response => { /* ... */ })
.catch(e => { /* ... */ })
```

**Search & Read items**
Just like the Get method, this one also receives a `model` string and a `params` object. With this method the parameters may include a `domain` array for filtering purposes (with filter statements similar to SQL's `WHERE`), `limit` and `offset` values for pagination and an `order` property which can be set to specific fields. The array of `ids` becomes optional.

Returns a promised which resolves to an array of results matching the parameters provided.
```js
const params = {
ids: [1,2,3,4,5],
domain: [ [ 'list_price', '>', '50' ], [ 'list_price', '<', '65' ] ],
fields: [ 'name', 'list_price', 'items' ],
order: 'list_price',
limit: 5,
offset: 0,
}; //params
odoo.search_read('product.product', params, function (err, products) {
if (err) { return console.log(err); }

console.log(products);
// [
// { list_price: 60, id: 52, name: 'Router R430' },
// { list_price: 62, id: 39, name: 'Headset standard' }
// ]

}); //search_read


// Browse products by ID
// Not a direct implementation of Odoo RPC 'browse' but rather a workaround based on 'search_read'
// https://www.odoo.com/documentation/8.0/reference/orm.html#openerp.models.Model.browse
var params = {
fields: [ 'name', 'list_price'],
limit: 5,
offset: 0,
}; //params
odoo.browse_by_id('product.product', params, function (err, products) {
if (err) { return console.log(err); }

console.log(products);
// [
// { list_price: 4.49, id: 1180, name: 'Fruit Cup' },
// { list_price: 0, id: 1139, name: 'Orange Crush' },
// { list_price: 1.59, id: 1062, name: 'Blueberry muffin' },
// { list_price: 1.35, id: 1381, name: 'Otis Harvest Bran' }
// ]
}); //browse_by_id


// Generic RPC call
// Note that, unlike the other methods, the context is not automatically included
var endpoint = '/web/dataset/call_kw';
var model = 'sale.order';
var method = 'action_view_delivery';

var args = [
[sale_order_id],
{
tz: odoo.context.tz,
uid: odoo.context.uid,
},
];//args

var params = {
model: model,
method: method,
args: args,
kwargs: {},
};//params

// View Delivery Order
odoo.rpc_call(endpoint, params, function(err, result) {
if(err) {
console.log(err);
return;
}//if

var delivery_order = result;

console.log(delivery_order);
});//odoo.rpc_call
order: 'list_price DESC',
limit: 5,
offset: 0,
}

odoo.search_read('product.product', params, context)
.then(response => { /* ... */ })
.catch(e => { /* ... */ })
```

**Read Group**
Just like the Search & read, but get the list of records in list view grouped by the given ``groupby`` fields.
If ``lazy`` true, the results are only grouped by the first groupby and the remaining groupbys are put in the __context key.
If ``lazy`` false, all the groupbys are done in one call.
Returns a promised which resolves to an array of results matching the parameters provided.
Array containing: all the values of fields grouped by the fields in ``groupby`` argument,
``__domain``: array of list specifying the search criteria, ``__context``: array with argument like ``groupby``
```js
const params = {
domain: [ ["project_id", "=", 7] ],
fields: [ "color", "stage_id" , "sequence"],
groupby: [
"stage_id"
],
order: 'sequence',
lazy: true
}

odoo.read_group('project.task', params, context)
.then(response => { /* ... */ })
.catch(e => { /* ... */ })
```

**Create**
Receives a `model` string and a `params` object with properties corresponding to the fields you want to write in the row.

```js
odoo.create('delivery.order.line', {
sale_order_id: 123
delivered: 'false',
}, context)
.then(response => { /* ... */ })
.catch(e => { /* ... */ })
```

## Methods

* odoo.connect(callback)
* odoo.get(model, id, callback)
* odoo.search(model, params, callback)
* odoo.search_read(model, params, callback)
* odoo.browse_by_id(model, params, callback)
* odoo.create(model, params, callback)
* odoo.update(model, id, params, callback)
* odoo.delete(model, id, callback)
* odoo.rpc_call(endpoint, params, callback);
**Update**
Receives a `model` string, an array of `ids` related to the rows you want to update in the database and a `params` object with properties corresponding to the fields that are going to be updated.

##Node version
Works better with NodeJS v11.16 and further
If you need to update several rows in the database you can take advantage of the Promises API to generate and populate an array of promises by iterating through each operation and then resolving all of them using `Promise.all()`
```js
odoo.update('delivery.order.line', [ids], {
delivered: 'true',
delivery_note: 'Delivered on time!'
}, context)
.then(response => { /* ... */ })
.catch(e => { /* ... */ })
```

## Reference
**Delete**
Receives an Odoo database `model` string and an `ids` array corresponding to the rows you want to delete in the database.

* [Odoo Technical Documentation](https://www.odoo.com/documentation/8.0)
* [Odoo Web Service API](https://www.odoo.com/documentation/8.0/api_integration.html)
```js
odoo.delete('delivery.order.line', [ids], context)
.then(response => { /* ... */ })
.catch(e => { /* ... */ })
```

## License
**Custom RPC Call**
If you wish to execute a custom RPC call not represented in this library's methods, you can also run a custom call by passing an `endpoint` string and a `params` object. This requires understanding how the Odoo Web API works more thoroughly so you can properly structure the functions parameters.

```js
odoo.rpc_call('/web/dataset/call_kw', params)
.then(response => { /* ... */ })
.catch(e => { /* ... */ })
```

The MIT License (MIT)
## References

Copyright (c) 2015 Marco Godínez, 4yopping and all the related trademarks
* [Odoo ORM API Reference](https://www.odoo.com/documentation/11.0/reference/orm.html)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
* [Odoo Web Service External API](https://www.odoo.com/documentation/11.0/webservices/odoo.html)

## License
This project is licensed under the MIT License - see the [LICENSE.md](https://github.com/cesar-gutierrez/react-native-odoo/LICENSE.md) file for details

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
## Acknowledgements

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
This project was built upon previous versions. It is a fork of [kevin3274](https://github.com/kevin3274/react-native-odoo)'s original React Native library which in turn is based of [saidimu](https://github.com/saidimu/odoo)'s Node.js library.
21 changes: 0 additions & 21 deletions examples/basic.js

This file was deleted.

11 changes: 0 additions & 11 deletions gulpfile.js

This file was deleted.

Loading