Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
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

Installing and upgrading local add-on modules

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 download from the app store or that have been written by yourself.

In this recipe, we will demonstrate 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 install a new add-on module in your database using the web interface, perform the following steps:

  1. Connect to the instance using the Administrator account and open the Apps menu:
    Figure 2.1 – List of Odoo apps

    Figure 2.1 – List of Odoo apps

  2. 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 the Not Installed filter.
    • If you're looking for a specific functionality add-on rather than a broad functionality add-on, remove the Apps filter.
    • Type a part of the module name in the search box and use this as a Module filter.
    • You may find that using the list view gives something more readable.
  3. Click on the Install 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

Figure 2.2 – Warning for external library dependency

To fix this, just install the relevant Python dependencies on your system.

To update a pre-installed module in your database, perform the following steps:

  1. Connect to the instance using the Administrator account.
  2. Open the Apps menu.
  3. Click on Apps:
    Figure 2.3 – Odoo apps list

    Figure 2.3 – Odoo apps list

  4. Use the search box to locate the add-on you want to install. Here are a few tips:
    • Activate the Installed filter.
    • If you're looking for a specific functionality add-on rather than a broad functionality add-on, remove the Apps filter.
    • Type a part of the add-on module name into the search box and then press Enter to use this as a Module filter. For example, type CRM and press Enter to search CRM apps.
    • You may find that using the list view gives you something more readable.
  5. Click on the three dots in the top right-corner of the card and click on the Upgrade option:
Figure 2.4 – Drop-down link for upgrading the module

Figure 2.4 – Drop-down link for upgrading the module

Activate developer mode to see the technical name of the module. See Chapter 1, Installing the Odoo Development Environment, if you don't know how to activate developer mode:

Figure 2.5 – Application's technical names

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 the Upgrade 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 install new add-ons in your database, perform the following steps:

  1. Find the names of the add-ons. This is the name of the directory containing the _manifest_.py file, without the leading path.
  2. Stop the instance. If you are working on a production database, make a backup.
  3. 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.

  4. Restart the instance.

To update an already installed add-on module in your database, perform the following steps:

  1. 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.
  2. Stop the instance. If you are working on a production database, make a backup.
  3. 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.

  4. Restart the instance.

How it works…

The add-on module 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 you install 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:

  1. If there are any, run the add-on preinit hook.
  2. Load the model definitions from the Python source code and update the database structure, if necessary (refer to Chapter 4, Application Models, for details).
  3. Load the data files of the add-on and update the database contents, if necessary (refer to Chapter 6, Managing Module Data, for details).
  4. Install the add-on demo data if demo data has been enabled in the instance.
  5. If there are any, run the add-on postinit hook.
  6. Run a validation of the view definitions of the add-on.
  7. If demo data is enabled and a test is enabled, run the tests of the add-on (refer to Chapter 18, Automated Test Cases, for details).
  8. Update the module state in the database.
  9. Update the translations in the database from the add-on's translations (refer to Chapter 11, Internationalization, for details).

    Note

    The preinit and postinit hooks are defined in the _manifest_.py file using the pre_init_hook and post_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 about init hooks, refer to Chapter 3, Creating Odoo Add-On Modules.

Add-on update

When you update 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:

  1. Run the add-on module's pre-migration steps, if any (refer to Chapter 6, Managing Module Data, for details).
  2. Load the model definitions from the Python source code and update the database structure if necessary (refer to Chapter 4, Application Models, for details).
  3. Load the data files of the add-on and update the database's contents if necessary (refer to Chapter 6, Managing Module Data, for details).
  4. Update the add-on's demo data if demo data is enabled in the instance.
  5. If your module has any migration methods, run the add-on post-migration steps (refer to Chapter 6, Managing Module Data, for details).
  6. Run a validation of the view definitions of the add-on.
  7. If demo data is enabled and a test is enabled, run the tests of the add-on (refer to Chapter 18, Automated Test Cases, for details).
  8. Update the module state in the database.
  9. Update the translations in the database from the add-on's translations (refer to Chapter 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 the Using the noupdate and forcecreate flags recipe in Chapter 6, Managing Module 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 the sale, sale_stock, and sale_specific add-ons installed, with sale_specific depending on sale_stock, and sale_stock depending on sale. To install all three, you only need to install sale_specific, as it will recursively install the sale_stock and sale dependencies. To update all three, you need to update sale, as this will recursively update the reverse dependencies, sale_stock and sale_specific.

Another tricky part with managing dependencies is when you add a dependency to an add-on that already has a version installed. Let's understand this by continuing with the previous example. Imagine that you add a dependency on stock_dropshipping in sale_specific. Updating the sale_specific add-on will not automatically install the new dependency, and neither will requesting the installation of sale_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.

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
Banner background image