Skip to content

Commit

Permalink
Merge pull request #30 from jobrad-gmbh/fix/basic-auth
Browse files Browse the repository at this point in the history
Add function to create client options
  • Loading branch information
vettloffah committed Nov 13, 2022
2 parents 345d49e + 3ef2ff6 commit 6b6b702
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,29 @@ class OdooAwait {
}
}

/**
* Assemble options for xmlrpc client using given path.
* @param {string} path The path to use for XMLRPC
* @returns options to be used with xmlrpc client
*/
createClientOptions(path){
return {
host: this.host,
port: this.port,
basic_auth: this.basicAuth,
path
};
}

/**
* Connect to Odoo. Must be called before calling other methods.
* @return {Promise<number>} - returns user ID if connected
*/
connect(){
let self = this;
let client;
const clientOptions = {
host: this.host,
port: this.port,
path: '/xmlrpc/2/common',
basic_auth: this.basicAuth
};
const clientOptions = this.createClientOptions('/xmlrpc/2/common');

if(this.secure){
client = xmlrpc.createSecureClient(clientOptions);
}else{
Expand Down Expand Up @@ -115,13 +125,9 @@ class OdooAwait {
*/
execute_kw(model, method, params) {

const clientOpts = {
host: this.host,
port: this.port,
path: '/xmlrpc/2/object'
}
const clientOptions = this.createClientOptions('/xmlrpc/2/object');

let client = this.secure ? xmlrpc.createSecureClient(clientOpts) : xmlrpc.createClient(clientOpts);
let client = this.secure ? xmlrpc.createSecureClient(clientOptions) : xmlrpc.createClient(clientOptions);

params.unshift( this.db, this.uid, this.password, model, method);

Expand Down

0 comments on commit 6b6b702

Please sign in to comment.