Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Odoo 14 Development Cookbook

You're reading from   Odoo 14 Development Cookbook Rapidly build, customize, and manage secure and efficient business apps using Odoo's latest features

Arrow left icon
Product type Paperback
Published in Dec 2020
Publisher Packt
ISBN-13 9781800200319
Length 784 pages
Edition 4th Edition
Languages
Tools
Arrow right icon
Authors (4):
Arrow left icon
Parth Gajjar Parth Gajjar
Author Profile Icon Parth Gajjar
Parth Gajjar
Alexandre Fayolle Alexandre Fayolle
Author Profile Icon Alexandre Fayolle
Alexandre Fayolle
Holger Brunn Holger Brunn
Author Profile Icon Holger Brunn
Holger Brunn
Daniel Reis Daniel Reis
Author Profile Icon Daniel Reis
Daniel Reis
Arrow right icon
View More author details
Toc

Table of Contents (26) Chapters Close

Preface 1. Chapter 1: Installing the Odoo Development Environment 2. Chapter 2: Managing Odoo Server Instances FREE CHAPTER 3. Chapter 3: Creating Odoo Add-On Modules 4. Chapter 4: Application Models 5. Chapter 5: Basic Server-Side Development 6. Chapter 6: Managing Module Data 7. Chapter 7: Debugging Modules 8. Chapter 8: Advanced Server-Side Development Techniques 9. Chapter 9: Backend Views 10. Chapter 10: Security Access 11. Chapter 11: Internationalization 12. Chapter 12: Automation, Workflows, Emails, and Printing 13. Chapter 13: Web Server Development 14. Chapter 14: CMS Website Development 15. Chapter 15: Web Client Development 16. Chapter 16: The Odoo Web Library (OWL) 17. Chapter 17: In-App Purchasing with Odoo 18. Chapter 18: Automated Test Cases 19. Chapter 19: Managing, Deploying, and Testing with Odoo.sh 20. Chapter 20: Remote Procedure Calls in Odoo 21. Chapter 21: Performance Optimization 22. Chapter 22: Point of Sale 23. Chapter 23: Managing Emails in Odoo 24. Chapter 24: Managing the IoT Box 25. Other Books You May Enjoy

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.

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

You have been reading a chapter from
Odoo 14 Development Cookbook - Fourth Edition
Published in: Dec 2020
Publisher: Packt
ISBN-13: 9781800200319
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime