Blog article
Interact with Odoo via the low code scripting in XQi Engine
by Robbe

Odoo provides an external API to expose its data to the outside world. This makes getting, modifying, and even executing functions of models possible. The main way to access this API is via XML-RPC or JSON-RPC. We completely integrated this API in our XQTING Integration Engine so that via the low code scripting, you can easily interact with your Odoo system.

The operations provided are:
  • Reading (one or more fields) of a record
  • Creating records
  • Updating fields of a record
  • Deleting records
  • Executing methods defined within an Odoo model
For ease of use, The XQTING Integration Engine allows us to configure one or more Odoo environments. Each environment gets a name and the required configuration parameters:
  • The id of the Odoo user
  • The password of the Odoo user
  • The name of the database that the Odoo instance is using
  • The URL of the Odoo instance
Configuring multiple environments allows for quickly switching between them, if needed, and would even allow you to integrate or connect multiple Odoo systems.

The XQTING Integration Engine provides predefined functions to access our Odoo instances. As with other integrations, the functions calls have a common structure.

Example

Let's say we want to synchronize MsGraph contacts with Odoo users. We use the MsGraph module and the Odoo module in the XQTING Integration Engine.

Configuration

As Odoo is the focal point of this article, we will only cover the configuration of this module. Imagine your company is called 'MyCompany' and you have an Odoo instance with the same name. The database where the Odoo instance is running on is named 'my-company-odoo-db' and the URL used to access this instance is 'https://mycompany.com/odoo'. Lastly, you are a user in that Odoo instance with user id 15 and password 'pwd123!'. In the engine.js file, we configure all this information once.

odoo.configure({
          odooSettings : [
    			{
                           name: "mycompany",
                           userId: "15",
                           password: "pwd123!",
                           database: " my-company-odoo-db ",
                           url: " https://mycompany/odoo "
                        },
                        //other Odoo environments
           ]
});
Synchronization

In the process.js file, we can use the timers in the XQTING Integration Engine to periodically check whether changes are required or not. Within this timer, we start our script. We require a list of contacts defined in MsGraph. See our other blog posts or contact us to get more details on how this is achieved.

We can collect all contacts in a list in the script and then we iterate over each contact and ensure they are present in Odoo. The model we use to define users in Odoo is called 'res.users' (this is a base model, included in every Odoo instance). To check if the user already exists, we can use the get method:

odoo.get("mycompany", "res.users", [ [“email”, “=”, contactEmail] ], [], onOdooGetUser);
In the callback method, onOdooGetUser, we can count the number of results. If this is 1, the user already exists in our Odoo instance and we don't need to change anything. Alternatively, we can make sure the user is up to date using the odoo.update(...) method. If the number of results is 0, We should add this MsGraph contact as a user in Odoo. To do this, we can create a user using the create method:

odoo.create(“mycompany”, “res.users”, {“name”: contactName, “email”: contactEmail}, onOdooCreateUser);
Now we are sure that every contact in MsGraph is a user in our Odoo instance, with the corresponding email address.

Additionally, we can make sure that a user in Odoo is deleted when they do not exist as a contact in MsGraph anymore. To do this, we can operate the other way around. We first get all the users in Odoo:

odoo.get(“MC”, “res.users”, [], [“email”], onOdooGetEmails);
Note that now, the search domain is empty, meaning we will get all users in our Odoo instance. And the list of fields contains the email of the user.

In the onOdooGetEmails callback function, we can check if the email exists in MsGraph. If it does, we don't need to do anything, or again, we can update the information using odoo.update(…). If it doesn't, we should delete the Odoo user:

Odoo.delete(“MC”, “res.users”, [userId], onOdooDeleteUser);
The users in our Odoo instance are now fully synchronized with contacts in MsGraph!

Conclusion
In this article, we covered a common use case for the integration of the Odoo API in the XQTING Integration Engine and showed you how easy it is to connect to an Odoo database using the XQTING engine. This way, you can connect your Odoo data to all of your other company data in only a few lines of script code in our low code environment!
Ready to execute your digital transformation?
Contact us