npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@intelica/odoo-xmlrpc

v1.1.0

Published

Intelica Odoo XMLRPC Interface

Downloads

176

Readme

Intelica Odoo XMLRPC API

Utility wrappers to interact with Odoo instance. Allow to handle defined Odoo data models without the requeriments to know the whole protocol.

Version npmnpm Downloads

NPM

Installation

npm install @intelica/odoo-xmlrpc

Supported data models

Currently the package support for three base models: Contacts (res.partner), Employees (hr.employee) and Leads/Opportunities (crm.lead). Also the XMLRPC protocol can be used as RAW data to interact with other data models. In this case for each supported data model there are a reduced subset of fields handled

For Contacts the data model interface is defined as

interface IContact {
  name?: string;
  phone?: string;
  email?: string;
  ref?: string;
  category_id?: any[];
}

For Employees the data model interface is defined as

interface IEmployee {
  department_id?: number;
  name?: string;
  work_email?: string;
  work_phone?: string;
  category_ids?: any[];
}

And for Leads the data model interface is defined as

interface ILead {
  name?: string;
  partner_id?: number;
  contact_name?: string;
  email_from?: string;
  phone?: string;
  description?: string;
  source_id?: number;
  user_id?: number;
  team_id?: number;
  tag_ids?: number[];
  type?: "lead" | "opportunity";
}

Odoo connection initialization

To establish a connection with the Odoo server you must provide the server address, database name and the credentials to connect to the server. Credentials can be used with user password or used with user access key.

const server = new Odoo("sample-odoo.server.com");

To check the Odoo server connection can use the public action to get the server version

server
  .version()
  .then((value: IServerVersion) => {
    console.log("Running server version: " + value.server_version);
  })
  .catch((err) => {
    console.error("There were some errors connecting to Odoo Server");
    console.error(err);
  });

Authenticate against Odoo Server

To authenticate with the Odoo server and interact with the protected data model you must provide ther user credentials. You must take into account that credentials used must have permissions to interact with the data models.

Once you have configured the Odoo server can authenticate the user account on the configured server:

server
  .authenticate("my-database", "[email protected]", "my-password or access-key")
  .then(() => {
    console.log("We are ready to interact with Odoo data models");
  })
  .catch((err) => {
    console.error("There were some errors authenticating against the Odoo Server");
    console.error(err);
  });

Once the user is authenticated the server controller will store the required parameters (such as: user id, database and password or access key) to perform calls on the data models.

CRUD operations on Odoo data models

To interact with Odoo data models there is the OdooCRUD class that implements the RAW basic operations over a generic data model.

class OdooCRUD<T> {
  constructor(model: string, odoo: Odoo, keys: string[] = []);
  public count(): Promise<number>;
  public create(value: T): Promise<number>;
  public searchRead(query: any[], limit = 10): Promise<T[]>;
  public read(ids: number[]): Promise<T[]>;
  public update(id: number, data: T): Promise<boolean>;
  public delete(id: number): Promise<boolean>;
}

This class implements basic XMLRPC operations defined in the Odoo documentation. This class can be used to interact with any Odoo data model but in this case you must handle model and fields values, also the query filters.

To interact with defined data models whe can ask to the server controller for the specific class.

const contacts = server.getModelActions(MODEL_TYPE.CONTACTS);
...
const leads = server.getModelActions(MODEL_TYPE.LEAD_OPPORTUNITY);
...
const employees = server.getModelActions(MODEL_TYPE.EMPLOYEES);

This classes extends from OdooCRUD to allow more dinamic methods and filters such as search inside data models using email address or phone number without knowledge of writing the XMLRPC domain filters. In some case it also prevent to handle manually the insertion on many2many relationships, such as contact tags.

Future work

In middle-long term we pretend to have covered the most part of Odoo data models to allow interact with Odoo without the knowledge of the internal structure.

If you want to collaborate with the project, you are welcome.


Enjoy it! .: Happy Coding :.