Wednesday 24 May 2017

Odoo connect using Node JS

I was trying to connect to an Odoo database on my local machine using some npm modules, as I am using a NodeJS application.

  1. I started by using odoo-xmlrpc.

    var Odoo = require('odoo-xmlrpc');
    var odoo1 = new Odoo({
    url: "localhost",
    port: 8069,
    db: 'localdb',
    username: 'Php',
    password: 'pwd'
    });
    
    odoo1.connect(function (err) {
      if (err) { return console.log(err); }
      console.log('Connected to Odoo server.');
      odoo1.execute_kw('res.partner', 'check_access_rights', ['read',false], function (err1, value) {
        if (err1) { return console.log(err1.body); }
        console.log('Result: ', value);
      });
    });
    
    

    The odoo.connect was successful, but I was not able to read or make any method calls as I was getting the following error.

    ProgrammingError: operator does not exist: integer = boolean
    LINE 1: ...T password, password_crypt FROM res_users WHERE id=false AND...
    HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts.

  2. Then I tried using node-odoo

    var Odoo2 = require('node-odoo');
    var params = {
      ids: [1,2,3,4,5],
      fields: [ 'name' ],
    };
    
    var odoo2 = new Odoo2({
      database: "localdb",
      host: "localhost",
      port: 8069,
      username: 'Php',
      password: 'pwd'
    });
    
    odoo2.connect(function (err) {
      if (err) { return console.log(err); }
      console.log('Connected to Odoo server.');
      odoo2.get('res.partner', params, function (err2, partners) {
        if (err2) { return console.log(err2); }
        console.log(partners);
      });
    });
    
    

    The connection is successful again, but I am getting the following error when trying to get some data.

    message: 'Odoo session expired',
    code: 100,
    data: ...

  3. Finally, I used odoo and I got the following error while trying to connect.

    var Odoo3 = require('Odoo');
    var odoo3 = new Odoo3({
      host: 'localhost',
      port: 8069,
      database: 'localdb',
      username: 'Php',
      password: 'pwd'
    });
    
    odoo3.connect(function (err) {
      if (err) { return console.log(err); }
      odoo3.get('res.partner', params, function (err3, partners) {
        if (err3) { return console.log(err3); }
        console.log(partners);
      });
    });
    
    

    I got the same session expired error in this case while trying to get.

I used Odoo v8 and got these issues. I m confused where I am going wrong here. Or is there some other way to make a successful connection with the NodeJs and Odoo database and make some get and create requests successfully?



via Philip John

No comments:

Post a Comment