Creating a tour in Odoo

In this tutorial I will teach you how to create a tour in Odoo. You will learn how to create a tour step by step in JavaScript and how to guide your users through your custom development.
In this tutorial I will create a new tour throughout the contacts app in order to guide a new user through this module.
Updated tutorial available on Oocademy

1. Creating a new module

Let us create a new module to start. You can either manually create a module or create one with the scaffold command from Odoo. Now that you’ve created your module you should add the dependency to the module where you want to create a tour. In this tutorial I will create a tour that guides the user through the contacts app.

2. Creating the tour

The first thing to do in order to create a tour is to create a JavaScript file. In Odoo you should place all JavaScript code under /static/src/js so create these folders first. Create these new folders and then create a new JavaScript file named ‘tour.js’. You should now have this:
JavaScript folder structure
Now open up your JS file and define a new function. In this function you should require ‘web.core’ and ‘web.core.tour’ and include ‘core._t’ in order to manage translations later on. Your code should now look like this:

2.1. Registering the tour

You now have the basic JavaScript structure! It is time to register a tour and add steps to this tour. Just have a look at this code for a minute:

Does this make any sense to you? Let us walk over it line by line. The tour.register function will tell Odoo that you want to add a new tour to Odoo. ‘example_tour’ is the technical name of the tour, but be sure that it is unique! The next line shows “url” which tells Odoo on which page the tour should start (in this tutorial from the home screen). ‘tour.STEPS.MENU_MORE’ is built in in Odoo to know where/when/how the tour should be loaded.

Finally, you’ll see the options ‘trigger’, ‘content’ and ‘position’. The ‘trigger’ will tell Odoo when exactly that you would want to trigger the tour step. In this example our tour would start on the main Odoo screen and will show a little icon under the contacts app. If you would install the app with this piece of code you would get the following result:
Tour home screen

The ‘content’ will show a text dialog to the enduser and the ‘position’ tells Odoo where exactly to show this text (top, right, left or bottom).

2.2 Choosing your tour steps

A tour should contain multiple steps and a logical flow though. Take a minute to figure out the steps you would like your users to follow in your tour.
In this tutorial I will add the following steps:
– The moment the user clicks on ‘Contacts’ and when the Kanban view opens we’ll show a hint to click on the ‘Create’ button.
– After clicking on the ‘Create’ button we’ll show a hint to fill in the name of the contact.
– When the name of the contact is filled in we’ll show a hint to click on ‘Save’.

2.3 Creating all tour steps

So, how do we code all the steps? Just have a look at the full code for a minute:

If you would run this code it would do exactly the points that I’ve subscribed. The trigger tells when the next step should go off. For example with the trigger ‘.o-kanban-button-new’ it will show a blinking icon next to the ‘Create’ button. Have you noticed the ‘extra_trigger’ option and the ‘run’ option in the third step? By setting an ‘extra_trigger’ Odoo knows when the trigger should go off (in this case after the user clicked on create so he is in edit mode). The ‘run’ option will tell Odoo to automatically fill in text in the field that we’ve put a trigger on, in this example the field ‘name’. If we would run (play) the tour from the Odoo interface it would now automatically fill in the name of the new contact.
That is all! You’ve now got the JavaScript code to create a tour.

3. Including the JavaScript

Finally you should now include your JavaScript file so that it gets compiled in Odoo too. Create a new xml file named ‘assets.xml’ in a new folder ‘views’:
Assets folder structure

Open up the XML file, inherit the assets template and insert the tour.js file into the assets. Your code should look like this:

Now open up your (or if you’re in V10) and add the ‘assets.xml’ file to the data key so that it gets loaded too:

That’s it, you’ve created your very first tour! If you save this code and run the module you will get the following behaviour:

4. Translating the tour

Now what if you have Odoo users that speak different languages? Luckily you can also translate tours to any language. Activate developer mode and then go to ‘Settings’ > ‘Translations’ > ‘Export translation’. You’ll now see a dialog from which you can choose the target language and where you can select your app. Select your target language, choose the file format ‘PO File’ and choose your app. Finally click on ‘Export’:
Export translations

Next create a new folder named ‘i18n’ and add your downloaded file to this folder:
Translation folder structure
Finally, open up the PO file and translate all the terms:
Translation example
When you now update your module and switch to another language you’ll see that the tour is translated.

5. Conclusion

Because of the built-in framework from Odoo it is very easy to create a tour for users. With this tour you can guide a new user through your own custom development in a matter of minutes and with personalised text. Creating tours is really quick and just takes a few lines of code.
Do you want to try the demo code and see the source code of this tutorial? You can view it on my Github account.
Has this tutorial helped you, do you have any feedback or questions? Post away!


Tutorial sponsored by Oocademy

Configuring app settings with erppeek in Odoo 11

In this tutorial I will teach you how to automatically configure app settings with erppeek in Odoo 11. You will learn how to use the erppeek library and how to configure app settings from Python code. By doing so you can automate the configuration of your database(s).
In this tutorial I will configure the sales app to use different units of measure through Python code.
Tip: This tutorial will only work for Odoo 11. The concept will work for Odoo 8, 9 and 10 too but the code will be slightly different.

1. Installing erppeek

Before we can start using erppeek we will need to install it. Open up a Linux terminal and run the following command:

After running this command we can access and use erppeek.

2. Creating the Python script

Now create a new Python file on your system where you would like to save your new script:

2.1 Configuring the settings

Now that we have a new file we have to import erppeek, so we can access all the possibilities of the erppeek library:

The next step is to tell erppeek where it can find the database and how it can access it. In order to do this we will have to tell the library the database name, the location of the database, the username and the password. Add the following code to your script, under the import:

Tip: If you can you should use this script with the administrator user only, since this user has access to all models and settings.

2.2 Connecting to the database

So now that we’ve installed erppeek, we’ve imported the library and we’ve created the configuration the next step is to connect to the Odoo database in order to query and configure it. Just connect to the Odoo client:

This line will tell your script to which server, on which database we want to connect with what user and sets the user his password.
Thanks to this code we can now access the database and query it. We now just have to find the record that contains settings of this database and then do the actions we would like to execute.

2.3 Getting the Odoo configuration

In Odoo 11 all settings are saved in the model ‘res.config.settings’ so let us get data from this model:

So, what exactly does this code do? It tells erppeek that we want to get data from the model ‘res.config.settings’ and that we only want to get the last record from this model (limit=1, order=’id desc’ will do that).
The result will now be in the variable ‘config_id’ but there is a catch. What if this query didn’t return anything? Imagine that you have a database that you’ve just installed and you’ve never done any settings, in this case the variable config_id won’t contain any records. To prevent our script from crashing we should make an if/else statement now that handles this potential issue. Let us start with the if statement!

2.4 Setting the new configuration

If we find a result we should set the changes that we want to activate and we then have to apply them on the database. Have a look at this code:

So, what exactly does this do? The first line will get the record itself, as ‘config_id’ only contains the id for the record but not the record itself. By calling the Odoo database and using the ‘browse’ function (with the ‘config_id’ passed in the call) we will get the record back. When we have this record we can write our wanted changes on this record. In this case I will configure Odoo to use different units of measures. Remember that all settings in Odoo are booleans, so we do {‘group_uom’: True} to set the boolean to true. But, where did I get the ‘group_uom’ from? This is the field of this setting. You can get this by activating the developer mode and hovering over the field:
Field name configuration
In this screenshot you can see that the option is not yet activated, so the boolean is set to False. {‘group_uom’: True} will change this when we apply this value. This is exactly what the last line does! By calling the record its execute function we will tell Odoo to execute this change and apply it to Odoo.
If you would run this script and would go to the settings you would see that the units of measures is now activated.

2.5 Setting the configuration when there is no record yet

Now we should handle one more case. When there has never been any configuration record yet we should create one. Just have a look at the following code:

The code is almost identical to the if part (in chapter 2.4) with the minor change that we create a new and empty record with .create({}) in order to create new settings. Besides of this difference the rest of the code is identical to the if part of the code.

2.6 Running the file

Good job! You’re almost done. Now save your Python file and execute the python script to apply the setting(s) on your Odoo database. Execute the following command:

After a few seconds your script will be done. Now open up your Odoo, go to the configuration and you will see that the setting has been applied to your database:
Applied configuration
That’s it! You’ve now configured your own Odoo database settings with a simple Python script!

3. Conclusion

Thanks to the erppeek library you can easily configure app settings from a Python script. With this library you can automate your databases its settings in a matter of seconds. If you would like to learn more about erppeek and the options it offers you should have a look at the official documentation.
Do you want to try the demo code and see the source code of this tutorial? You can view it on my Github account.
Has this tutorial helped you, do you have any feedback or questions? Post away!
Tutorial sponsored by Oocademy


Installing Odoo 11 (enterprise) on Ubuntu

In this tutorial I will learn you how to install Odoo 11 community or enterprise on Ubuntu 16.04. The script that you will use is based on the code from André Schenkels but has been updated, upgraded and improved. Do notice that if you want to install the enterprise version that you will need to be an official partner or that you need to have bought the enterprise subscription from Odoo. Otherwise you will have no access to the Github repository for the enterprise code!

1. Downloading the script

The first step is to download my script from Github and to add the code in a new .sh file on your Ubuntu machine, wherever you’d like this.
For example right under /home. Open up an Ubuntu terminal and cd to the directory where you’d like to keep the script and then create the file:

If you’re curious about how the whole code looks and works you can find it on my Github account.
Now open up the file and edit the parameters to your liking:

There are some things you can configure/change to your likings at the top of the script. You can choose if you wish to install Wkhtmltopdf or not, which version you’d like, where the location is and most importantly what the master admin password is.
Tip: always modify this for every Odoo you install!
If you want the enterprise version of V11 you should change the line IS_ENTERPRISE to true:

If you want the community version you can just continue and keep the IS_ENTERPRISE key on “False” (which is the case by default):

2. Making the Odoo installation file executable

The next step is to make this file executable. After you’ve made it executable you can execute it and everything will be installed automatically.
do this with the following command:

3.Running the script

Now that the code is in your file and the file is executable you simply have to execute it with the following command:

You will see that the script automatically starts updates, downloads required packages, creates the user, downloads the code from Github, … Eventually, if you’ve chosen to install the enterprise version, you will need to give in your Github credentials to download the enterprise code (since this is a private repository). Fill in your details and let the script continue:
Odoo 9 enterprise authentication
Give the script a few minutes to configure and install everything and eventually you will see something like this:
Result install script

You now have a fully functional Odoo V11 community or enterprise on your system! Congratulations.
Odoo V11

4. Extra information about Odoo 11 Enterprise

Since Odoo Enterprise uses code from both and we will separate the code with this script. This will make future upgrades easier and the code is nicely separated. This means that the default V11 code will be under /odoo/odoo-server/ and all the enterprise code will be under /odoo/enterprise/.

In the script you saw there was an option to change the Odoo port (OE_PORT). When you’d change this port number to 8070 in the install script it would be applied to /etc/your-config-file.conf and this would give you the ability to change the default port.
To apply these changes you should do the following:
Changing Odoo settings
The -c will change the configuration and memorize what you’ve changed under /etc/your-config-file.conf. Because my port was set to 8070 this is telling the Odoo that it should run on port 8070. When you would now open up your browser and navigate to http://localhost:8070/ you will see it is running there:
Odoo V9 alternative port

Has this tutorial helped you, do you have any feedback or questions? Post away!
Tutorial sponsored by Oocademy