Book Image

Odoo 14 Development Cookbook - Fourth Edition

By : Parth Gajjar, Alexandre Fayolle, Holger Brunn, Daniel Reis
5 (2)
Book Image

Odoo 14 Development Cookbook - Fourth Edition

5 (2)
By: Parth Gajjar, Alexandre Fayolle, Holger Brunn, Daniel Reis

Overview of this book

With its latest iteration, the powerful Odoo framework released a wide variety of features for rapid application development. This updated Odoo development cookbook will help you explore the new features in Odoo 14 and learn how to use them to develop Odoo applications from scratch. You'll learn about the new website concepts in Odoo 14 and get a glimpse of Odoo's new web-client framework, the Odoo Web Library (OWL). Once you've completed the installation, you'll begin to explore the Odoo framework with real-world examples. You'll then create a new Odoo module from the ground up and progress to advanced framework concepts. You'll also learn how to modify existing applications, including Point of Sale (POS) applications. This book isn't just limited to backend development; you'll discover advanced JavaScript recipes for creating new views and widgets. As you progress, you'll learn about website development and become a quality Odoo developer by studying performance optimization, debugging, and automated testing. Finally, you'll delve into advanced concepts such as multi-website, In-App Purchasing (IAP),, the IoT Box, and security. By the end of the book, you'll have all the knowledge you need to build impressive Odoo applications and you'll be well versed in development best practices that will come in handy when working with the Odoo framework.
Table of Contents (26 chapters)

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:

  1. Edit the configuration file for your instance, that is, ~/odoo-dev/myodoo.cfg.
  2. Locate the line starting with addons_path=. By default, this should look like the following:
    addons_path = ~/odoo-dev/odoo/addons
  3. 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
  4. 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.


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 \
--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.


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).