post 数据使用nodejs转odoo

post data using nodejs to odoo

我必须使用节点 js 从 Web 获取数据,然后 post 将该数据传输到 odoo,因此来自该 Web 的数据将自动 post 在 odoo 中 我已经使用节点 js 从该网站获取数据,但我的问题是 post 使用节点 js 将其传输到 odoo,请任何人帮助我,谢谢

odoo 11 在 ubuntu 18.04 LTS

您可以使用 odoo-xmlrpc

var Odoo = require('odoo-xmlrpc');


var odoo = new Odoo({
    url: <insert server URL>,
    port: <insert server Port (by default 80)>,
    db: <insert database name>,
    username: '<insert username>',
    password: '<insert password>'
});

odoo.connect(function (err) {
    if (err) { return console.log(err); }
    console.log('Connected to Odoo server.');
    var inParams = [];
    inParams.push({'name': 'FFNew Partner'})
    var params = [];
    params.push(inParams);
    odoo.execute_kw('res.partner', 'create', params, function (err, value) {
        if (err) { return console.log(err); }
        console.log('Result: ', value);
    });

    // Update product price
    var inParams = [];
    inParams.push([3626]); //id to update
    inParams.push({'name': 'NewFF Partner'})
    var params = [];
    params.push(inParams);
    odoo.execute_kw('res.partner', 'write', params, function (err, value) {
        if (err) { return console.log(err); }
        console.log('Result: ', value);
    });
});

正在搜索和更新产品fix_price

// Update given product price
// First you need to get the corrsesponding database `id`
// Then you will need to call write method to update the price
odoo.connect(function (err) {
    if (err) { return console.log(err); }
    console.log('Connected to Odoo server.');
    var inParams = [];
    // You well need a criteria to identify the product
    // and if many call `search_read` and check for
    // the product inside the loop

    inParams.push([['name', '=', "Laptop E5023"]]);
    var params = [];
    params.push(inParams);
    odoo.execute_kw('product.product', 'search', params, function (err, value) {
        if (err) { return console.log(err); }
        console.log(value);
        var inParams = [];
        // `value` array can contain more than one product id, it depends on 
        // the search criteria
        inParams.push(value);
        inParams.push({'list_price': PRODUCT_PRICE})
        var params = [];
        params.push(inParams);
        odoo.execute_kw('product.product', 'write', params, function (err, value) {
            if (err) { return console.log(err); }
            console.log('Result: ', value);
        });
    });
});