Configuring the add-ons path
With the help of the addons_path
parameter, you can load your own add-on modules into Odoo. When Odoo initializes a new database, it will search for add-on modules within directories that have been provided in the addons_path
configuration parameter. Odoo will search in these directories for the potential add-on module.
Directories listed in addons_path
are expected to contain subdirectories, each of which is an add-on module. Following initialization of the database, you will be able to install modules that are given in these directories.
Getting ready
This recipe assumes that you have an instance ready with a configuration file generated, as described in the Storing the instance configuration in a file recipe in Chapter 1, Installing the Odoo Development Environment. Note that the source code of Odoo is available in ~/odoo-dev/odoo
, and the configuration file in ~/odoo-dev/myodoo.cfg
.
How to do it…
To add the ~/odoo-dev/local-addons
directory to addons_path
of the instance, perform the following steps:
- Edit the configuration file for your instance, that is,
~/odoo-dev/myodoo.cfg
. - Locate the line starting with
addons_path=
. By default, this should look like the following:addons_path = ~/odoo-dev/odoo/addons
- Modify the line by appending a comma, followed by the name of the directory you want to add to
addons_path
, as shown in the following code:addons_path = ~/odoo-dev/odoo/addons,~/odoo-dev/local-addons
- Restart your instance from the terminal:
$ ~/odoo-dev/odoo/odoo-bin -c my-instance.cfg
How it works…
When Odoo is restarted, the configuration file is read. The value of the addons_path
variable is expected to be a comma-separated list of directories. Relative paths are accepted, but they are relative to the current working directory and therefore should be avoided in the configuration file.
At this point, we have only listed the add-on directory in Odoo, but no add-on modules are present in ~/odoo-dev/local-addons
. And even if you add a new add-on module to this directory, Odoo does not show this module in the user interface. For this, you need to perform an extra operation, as explained in the next recipe, Updating the add-on modules list.
Note
The reason behind this is that when you initialize a new database, Odoo automatically lists your custom modules in available modules, but if you add new modules following database initialization, then you need to manually update the list of available modules, as shown in the Updating the add-on modules list recipe.
There's more…
When you call the odoo-bin
script for the first time to initialize a new database, you can pass the --addons-path
command-line argument with a comma-separated list of directories. This will initialize the list of available add-on modules with all of the add-ons found in the supplied add-ons path. When you do this, you have to explicitly include the base add-ons directory (odoo/odoo/addons
), as well as the core add-ons directory (odoo/addons
). A small difference with the preceding recipe is that the local add-ons must not be empty; they must contain at least one sub-directory, which has the minimal structure of an add-on module.
In Chapter 3, Creating Odoo Add-On Modules, we will look at how to write your own modules. In the meantime, here's a quick hack to produce something that will make Odoo happy:
$ mkdir -p ~/odoo-dev/local-addons/dummy $ touch ~/odoo-dev/local-addons/dummy/  init  .py $ echo '{"name": "dummy", "installable": False}' > \ ~/odoo-dev/local-addons/dummy/  manifest  .py
You can use the --save
option to save the path to the configuration file:
$ odoo/odoo-bin -d mydatabase \ --add-ons-path="odoo/odoo/addons,odoo/addons,~/odoo-dev/local-addons" \ --save -c ~/odoo-dev/my-instance.cfg --stop-after-init
In this case, using relative paths is OK, since they will be converted into absolute paths in the configuration file.
Note
Since Odoo only checks directories in the add-ons path for the presence of add-ons when the path is set from the command line, not when the path is loaded from a configuration file, the dummy module is no longer necessary. You may, therefore, remove it (or keep it until you're sure that you won't need to create a new configuration file).