Flutter + Odoo

The Flutter plugin for communicating with Odoo backend api. Supports iOS and Android with Flutter

Changelog

Installing

Use this package as library

1. Depend on it
Add this to your package's pubspec.yaml file:

dependencies:
    odoo_api: ^1.0.4

2. Install it
You can install packages from the command line: with Flutter

$ flutter packages get

Alternatively, your editor might support flutter packages get. Check the docs for your editor to learn more.

3. Import it
Now in your Dart code, you can use:

import 'package:odoo_api/odoo_api.dart';

Features

Basic method support

Supported Odoo versions

Both community and enterprise version supported

Getting started

Connecting to Odoo

Creating odoo instance with OdooClient

var client = new OdooClient("http://yourdomain.com");

// Asynchronous way
client.connect().then((OdooVersion version) {
    // connected
});

// Synchronize way
final version = await client.connect();

Session information

Without login your will get Session Expire and after login you will get current active user information

client.getSessionInfo().then((OdooResponse result) {
	// deal with session result    
});
	

Databases List

For getting all available database lists you need to call getDatabases()

client.getDatabases().then((List databases){
    // deal with database list
});

Authenticating

Odoo required authentication before fetching data from backend models. Todo that, user need to use their credetials Username/Email, Password and Database With OdooClient you can use authenticate() method for getting basic user detail and making session between flutter app and odoo.

client.authenticate("username", "password", "database").then((AuthenticateCallback auth) {
    if(auth.isSuccess) {
        final user = auth.getUser();
        print("Hello ${user.name}");
    } else {
        // login fail
    }
});

Reading Data

Required authentication before calling this methods.

read()

Reading specified records from model. It takes IDs as list and Fields list to fetch record from server. Use when you have fix ids' data to read from model.

final ids = [1, 2, 3, 4, 5];
final fields = ["id", "name", "email"];
client.read("res.partner", ids, fields).then((OdooResponse result) {
    if (!result.hasError()) {
        List records = result.getResult();
    } else {
        print (result.getError());
    }
});

searchRead()

Used to read records from server with custom domain filtering, fields, offset, limit and sorting of data.

final domain = [["email", "!=", false]];
final fields = ["id", "name", "email"];
client.searchRead("res.partner", domain, fields, limit: 10, offset: 0, order: "date").then((OdooResponse result) {
    if(!result.hasError()) {
        final data = result.getResult();
        print("Total: ${data['length']");
        final records = data['records'];
    } else {
        print(result.getError());
    }
});

domain is set of conditions to applied when fetching data from server uses prefix unary mechanism same as Odoo

Creating record

Required authentication before calling this methods.

create()

Create record on server and return new created server id in response result.

final values = {
    "name": "John Doe",
    "email": "johndoe@mydomain.com"
};
client.create("res.partner", values).then((result) {
    if(!result.hasError()) {
        final newId = result.getResult();
    } else {
        print(result.getError());
    }
});

Here, Values is set of key-value pair data

Updating, deleting record

Required authentication before calling this methods.

write()

Write or Update specified records with values for given server record ids.

final ids = [1, 2, 3, 4];
final valuesToUpdate = {
    "city": "Mumbai"
};
client.write("res.partner", ids, valuesToUpdate).then((result) {
    if(!result.hasError() && result.getResult()) {
        print("Updated");
    } else {
        print (result.getError());
    }
});

unlink()

Remove record from server permanently.

final ids = [1, 2, 3, 4];
client.unlink("res.partner", ids).then((result) {
    if(!result.hasError() && result.getResult()) {
        print("Unlinked");
    } else {
        print (result.getError());
    }
});

Calling model methods

callKW()

There are some method you need to call from flutter, by use of callKW you can call any method of model.

var args = ["OOGBox"];
client.callKW("res.partner", "create_name", args, kwargs: {}, context: {}).then((result) {
    // deal with result
});

When calling @api.multi method the parameter arguments are only two. First List of record ids and second User context (json object) or you can just pass empty json object See issue: https://github.com/oogbox/odoo-mobile-api/issues/8#issuecomment-403684787

Calling controller of type JSON

callController()

Yes, you can call controllers of odoo with type JSON.

var params = {};
client.callController("/my/controller", params).then((result) {
    // deal with result
});

Here,
- Path must be url path after domain name, e.g., http://www.example.com/my/controller
- Params are key-value pair data to pass in controller method

Security for Operations (Access Rights)

Don't worry for access rights, every JSON Request treated by Odoo Server, and server will check for all access rights for user.

If Access failed, you got response in getError()

GIVE FEEDBACK

Follow us on Twitter: @oogbox