The core functionality of Odoo comes from its add-on modules. You have a wealth of add-ons available as part of Odoo itself, as well as add-on modules that you can downloadfrom the app store or that have been written by yourself.
In this recipe, we willdemonstrate how to install and upgrade add-on modules through the web interface and from the command line.
The main benefits of using the command line for these operations include being able to act on more than one add-on at a time and having a clear view of the server logs as the installation or update progresses, which is very useful when in development mode or when scripting the installation of an instance.
Getting ready
Make sure that you have a running Odoo instance with its database initialized and the add-ons path properly set. In this recipe, we will install/upgrade a few add-on modules.
How to do it…
There are two possible methods to install or update add-ons—you can use the web interface or the command line.
From the web interface
To installa new add-on modulein your database using the web interface, perform the following steps:
- Connect to the instance using theAdministrator account and open theApps menu:
Figure 2.1 – List of Odoo apps
- Use the search box to locate the add-on you want to install. Here are a few instructions to help you with this task:
- Activate theNot Installed filter.
- If you're looking for a specific functionality add-on rather than a broad functionality add-on, remove theApps filter.
- Type a part of the module name in the search box and use this as aModule filter.
- You may find that using the list view gives something more readable.
- Click on theInstall button under the module name in the card.
Note that some Odoo add-on modules have external Python dependencies. If Python dependencies are not installed in your system, then Odoo will abort the installation and it will show the following dialog:
Figure 2.2 – Warning for external library dependency
To fixthis, just install the relevantPython dependencies on your system.
To update a pre-installed module in your database, perform the following steps:
- Connect to the instance using theAdministrator account.
- Open theApps menu.
- Click onApps:
Figure 2.3 – Odoo apps list
- Use the search box to locate the add-on you want to install. Here are a few tips:
- Activate theInstalled filter.
- If you're looking for a specific functionality add-on rather than a broad functionality add-on, remove theApps filter.
- Type a part of the add-on module name into the search box and then pressEnter to use this as aModule filter. For example, type
CRM and pressEnter to search CRM apps. - You mayfind that usingthe list view gives you something more readable.
- Click on the three dots in the top right-corner of the card and click on theUpgrade option:
Figure 2.4 – Drop-down link for upgrading the module
Activate developer mode to see the technical name of the module. SeeChapter 1,Installing the Odoo Development Environment, if you don't know how to activatedeveloper mode:
Figure 2.5 – Application's technical names
After activating developer mode, it will show the module's technical name in red. If you are using Odoo Community Edition, you will see some extra apps with theUpgrade button. Those apps are Odoo Enterprise Edition apps,and in order to install/use them, you need to purchase a license.
From the command line
To installnew add-ons in yourdatabase, perform the following steps:
- Find the names of the add-ons. This is the name of the directory containing the _
manifest_.py file, without the leading path. - Stop the instance. If you are working on a production database, make a backup.
- Run the following command:
$ odoo/odoo-bin -c instance.cfg -d dbname -i addon1,addon2 \--stop-after-init
You may omit-d dbname if this is set in your configuration file.
- Restart the instance.
To update an already installed add-on module in your database, perform the following steps:
- Find the name of the add-on module to update; this is the name of the directory containing the _
manifest_.py file, without the leading path. - Stop the instance. If you are working on a production database, make a backup.
- Run the following command:
$ odoo/odoo-bin -c instance.cfg -d dbname -u addon1 \--stop-after-init
You may omit-d dbname if this is set in your configuration file.
- Restart the instance.
How it works…
The add-onmodule installation and update are two closely related processes, but there are some important differences, as highlighted in the following two sections.
Add-on installation
When youinstall an add-on, Odoo checks its list of available add-ons for an uninstalled add-on with the supplied name. It also checks for the dependencies of that add-on and, if there are any, it will recursively install them before installing the add-on.
The installation process of a single module consists of the following steps:
- If there are any, run the add-on
preinit hook. - Load the model definitions from the Python source code and update the database structure, if necessary (refer toChapter 4,Application Models, for details).
- Load the data files of the add-on and update the database contents, if necessary (refer toChapter 6,ManagingModule Data, for details).
- Install the add-on demo data if demo data has been enabled in the instance.
- If there are any, run the add-on
postinit hook. - Run a validation of the view definitions of the add-on.
- If demo data is enabled and a test is enabled, run the tests of the add-on (refer toChapter 18,Automated Test Cases, for details).
- Update the module state in the database.
- Update the translations in the database from the add-on's translations (refer toChapter 11,Internationalization, for details).
Note
Thepreinit andpostinit hooks are defined in the _manifest_.py file using thepre_init_hook andpost_init_hook keys, respectively. These hooks are used to invoke Python functions before and after the installation of an add-on module. To learn more aboutinit hooks,refer toChapter 3,Creating Odoo Add-On Modules.
Add-on update
When youupdate an add-on, Odoo checks in its list of available add-on modules for an installed add-on with the given name. It also checks for the reverse dependencies of that add-on (these are the add-ons that depend on the updated add-on). If any, it will recursively update them, too.
The update process of a single add-on module consists of the following steps:
- Run the add-on module's pre-migration steps, if any (refer toChapter 6,ManagingModule Data, for details).
- Load the model definitions from the Python source code and update the database structure if necessary (refer toChapter 4,Application Models, for details).
- Load the data files of the add-on and update the database's contents if necessary (refer toChapter 6,ManagingModule Data, for details).
- Update the add-on's demo data if demo data is enabled in the instance.
- If your module has any migration methods, run the add-on post-migration steps (refer toChapter 6,ManagingModule Data, for details).
- Run a validation of the view definitions of the add-on.
- If demo data is enabled and a test is enabled, run the tests of the add-on (refer toChapter 18,Automated Test Cases, for details).
- Update the module state in the database.
- Update the translations in the database from the add-on's translations (refer toChapter 11,Internationalization, for details).
Note
Note that updating an add-on module that is not installed does nothing at all. However, installing an add-on module that is already installed reinstalls the add-on, which can have some unintended effects with some data files that contain data that is supposed to be updated by the user and not updated during the normal module update process (refer to theUsing the noupdate and forcecreate flags recipe inChapter 6,ManagingModule Data). There is no risk of error from the user interface, but this can happen from the command line.
There's more…
Be careful with dependency handling. Consider an instance where you want to have thesale,sale_stock, andsale_specific add-ons installed, withsale_specific depending onsale_stock, andsale_stock depending onsale. To install all three, you only need to installsale_specific, as it will recursively install thesale_stock andsale dependencies. To update all three, you need to updatesale, as this will recursively update the reverse dependencies,sale_stock andsale_specific.
Another tricky part with managing dependencies is when you add a dependency to an add-on that alreadyhas a version installed. Let's understand this by continuing with the previous example. Imagine that you add a dependency onstock_dropshipping insale_specific. Updating thesale_specific add-on will not automatically install the new dependency, and neither will requesting the installation ofsale_specific. In this situation, you can get very nasty error messages because the Python code of the add-on is not successfully loaded, but the data of the add-on and the models' tables in the database are present. To resolve this, you need to stop the instance and manually install the new dependency.