Giter VIP home page Giter VIP logo

jsodoorpc's Introduction

jsOdooRpc

Library to communicate into Odoo and other with Javascript and JSON-RPC.

This Library has no dependency. It's Vanilla Javascript !

All return of the methods are Promise (except setHost method)

Installation

<script src="/path/to/odoo_jsonrpc.js"></script>

Usage

Set the hostname

It's the only method with doesn't return a Promise.

// Without schema and port
odoo_jsonrpc.setHost('localhost');

// Or with scheme
odoo_jsonrpc.setHost('https://localhost');

// Or with no standard port
odoo_jsonrpc.setHost('localhost:8000');

Connect into Odoo

It's require only once. After a success login, all futures requests will be executed with our rights.

odoo_jsonrpc.login('database', 'login', 'password').then(
    function (result) {
        console.log('You are logged !');
        console.log('Your UID is : ' + result.uid);
    },
    function (error) {
        console.error(error);
    }
);

Session

Get informations about current session

odoo_jsonrpc.session.getInfos().then(
    function (result) {
        console.log(result);
    },
    function (error) {
        console.error(error);
    }
);

Change password of the account

odoo_jsonrpc.session.changePassword('your old password', 'your new pssword').then(
    function (result) {
        console.log('Password successful changed');
    },
    function (error) {
        console.error('Fail to change password');
        console.error(error);
    }
);

Get the list of availables languages

odoo_jsonrpc.session.getLanguages().then(
    function (result) {
        var iterator = 0,
            length = result.length
        ;
        for (; iterator < length; iterator += 1) {
            console.log('Language : ' + result[iterator][1]);
        }
    },
    function (error) {
        console.error(error);
    }
);

Get the list of availables modules

odoo_jsonrpc.session.getModules().then(
    function (result) {
        var iterator = 0,
            length = result.length
        ;
        for (; iterator < length; iterator += 1) {
            console.log('Module : ' + result[iterator]);
        }
    },
    function (error) {
        console.error(error);
    }
);

Database

List databases

odoo_jsonrpc.database.list().then(
    function (result) {
        var iterator = 0, 
            length = result.length
        ;
        for (; iterator < length; iterator += 1) {
            console.log('Database : ' + result[iterator]);
        }
    },
    function (error) {
        console.error(error);
    }
);

Create a new database

odoo_jsonrpc.database.create('database_name', 'master_password', false, 'fr_FR', 'the admin password for the new database').then(
    function (result) {
        console.log('Database created')
    },
    function (error) {
        console.error('Fail to create database');
        console.error(error);
    }
);

Duplicate a database

odoo_jsonrpc.database.duplicate('database_source', 'new_database_name', 'master_password').then(
    function (result) {
        console.log('Database duplicated')
    },
    function (error) {
        console.error('Fail to duplicate database');
        console.error(error);
    }
);

Drop a database

odoo_jsonrpc.database.drop('database_name', 'master_password').then(
    function (result) {
        console.log('Database droped')
    },
    function (error) {
        console.error('Fail to drop database');
        console.error(error);
    }
);

Model

Find a record by id

odoo_jsonrpc.model.find('res.partner', 1, ['name']).then(
    function (result) {
        console.log('Partner : ' + result.name);
    },
    function (error) {
        // an error occured
         console.error(error);
    }
);

Search and read into a model

odoo_jsonrpc.model.searchRead('res.partner', [['id', '=', 1]], ['name']).then(
    function (result) {
        // read the result
        if (0 === result.length) {
            console.log('No result for your request !');
            return;
        }

        var iterator = 0, 
            length = result.records.length
        ;
        for (; iterator < length; iterator += 1) {
            console.log('Partner : ' + result.records[iterator].name);
        }
    },
    function (error) {
        // an error occured
         console.error(error);
    }
);

Create a record

var datas = {
    name: 'Partern name',
    phone: '+33100000000'
};

odoo_jsonrpc.model.create('res.partner', datas).then(
    function (result) {
        console.log(result);
    },
    function (error) {
        // an error occured
         console.error(error);
    }
);

Update a record

var datas = {
    name: 'Partern name updated',
    phone: '+33100000000'
};

odoo_jsonrpc.model.write('res.partner', 1, datas).then(
    function (result) {
        console.log(result);
    },
    function (error) {
        // an error occured
         console.error(error);
    }
);

Remove a record

odoo_jsonrpc.model.remove('res.partner', 5).then(
    function (result) {
        console.log(result);
    },
    function (error) {
        // an error occured
         console.error(error);
    }
);

Call a custom method

var args = {
    arg1: 'value1'
};
var kwargs;

odoo_jsonrpc.model.call('res.partner', 'my_custom_method', args, kwargs).then(
    function (result) {
        console.log(result);
    },
    function (error) {
        // an error occured
         console.error(error);
    }
);

License

Licence WTFPL : http://sam.zoy.org/wtfpl/

Author

Simon Leblanc [email protected]

jsodoorpc's People

Contributors

leblanc-simon avatar

Watchers

James Cloos avatar crax avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.