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), Odoo.sh, 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)

How it works…

We generate a clean directory structure with clearly labeled directories and dedicated roles. We are using different directories to store the following:

  • The code maintained by other people (in src/)
  • The local-specific code
  • filestore of the instance

By having one virtualenv environment per project, we are sure that the project's dependencies will not interfere with the dependencies of other projects that may be running a different version of Odoo or will use different third-party add-on modules, which require different versions of Python dependencies. This comes at the cost of a little disk space.

In a similar way, by using separate clones of Odoo and third-party add-on modules for our different projects, we are able to let each of these evolve independently and only install updates on the instances that need them, hence reducing the risk of introducing regressions.

The bin/odoo script allows us to run the server without having to remember the various paths or activate the virtualenv environment. This also sets the configuration file for us. You can add additional scripts in there to help you in your day-to-day work. For instance, you can add a script to check out the different third-party projects that you need to run your instance.

Regarding the configuration file, we have only demonstrated the bare minimum options to set up here, but you can obviously set up more, such as the database name, the database filter, or the port on which the project listens. Refer to Chapter 1, Installing the Odoo Development Environment, for more information on this topic.

Finally, by managing all of this in a Git repository, it becomes quite easy to replicate the setup on a different computer and share the development among a team.

Speedup tip

To facilitate project creation, you can create a template repository containing the empty structure, and fork that repository for each new project. This will save you from retyping the bin/odoo script, the .gitignore file, and any other template file you need (continuous integration configuration, README.md, ChangeLog, and so on).

There's more...

The development of complex modules requires various configuration options, which leads to updating the configuration file whenever you want to try any configuration option. Updating the configuration file frequently can be a headache, and to avoid this, an alternative way is to pass all configuration options from the command line, as follows:

  1. Activate virtualenv manually:
    $ source env/bin/activate
  2. Go to the Odoo source directory:
    $ cd src/odoo
  3. Run the server:
    ./odoo-bin --addons-path=addons,../../local -d test-14 -i account,sale,purchase --log-level=debug

In step 3, we passed a few configuration options directly from the command line. The first is --add-ons-path, which loads Odoo's core add-ons directory, addons, and your add-ons directory, local, in which you will put your own add-on modules. Option -d will use the test-14 database or create a new database if it isn't present. The -i option will install the account, sale, and purchase modules. Next, we passed the log-level option and increased the log level to debug so that it will display more information in the log.

Note

By using the command line, you can quickly change the configuration options. You can also see live logs in the terminal. For all available options, refer to Chapter 1, Installing the Odoo Development Environment, or use the --help command to view a list of all options and the description of each option.