我必须使用节点js从Web上获取数据并将其发布到odoo,因此来自该Web的数据将自动在odoo中发布 我已经使用节点js从该网络获取数据,但是我的问题是使用节点js将其发布到odoo,请帮助我,谢谢
ubuntu 18.04 LTS中的odoo 11
答案 0 :(得分:0)
您可以使用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);
});
});
});