Book Image

Odoo 15 Development Essentials - Fifth Edition

By : Daniel Reis
4.5 (2)
Book Image

Odoo 15 Development Essentials - Fifth Edition

4.5 (2)
By: Daniel Reis

Overview of this book

Odoo is fast becoming the reference open source platform for business applications thanks to the fact that it provides the infrastructure needed for developers to deliver software solutions for any business process quickly. Odoo's layered module approach makes it particularly effective for combining and extending features. This updated fifth edition is a tutorial-style introduction to essential Odoo development topics. The book starts by covering the development essentials for building business applications and takes you through Odoo installation and configuration, gradually transitioning from having no specific knowledge of Odoo to being ready for application development. You'll then learn how to develop your first Odoo application, while covering topics such as models and views. Later chapters will get you up to speed with using server APIs to add business logic, helping you lay a solid foundation for advanced topics. As you progress, you’ll get equipped to build and customize your applications and explore the new features available in Odoo 12 and beyond, such as in-memory ORM and computed writable fields. Finally, you’ll gain insights into building business logic and using the Odoo API to integrate with various applications. By the end of this book, you’ll be able to build business apps from scratch using the latest version of Odoo.
Table of Contents (22 chapters)
1
Section 1: Introduction to Odoo Development
6
Section 2: Models
9
Section 3: Business Logic
13
Section 4: Views
18
Section 5: Deployment and Maintenance

Installing Odoo in your workstation

Using an Odoo SaaS trial database will be the default choice for this chapter. For the rest of the book, we will use a local Odoo installation, and in Chapter 2, Preparing the Development Environment, we will guide you through this process.

It is still worth noting that there are a few prepackaged installation alternatives for Odoo. We will briefly guide you through the available options in case you want to try any of them:

  • Install Odoo with a prepackaged installer for your operating system: This is a good option if you're new to Odoo and want to quickly have a local environment running. Prepackaged installers are available for the following: Windows (EXE installer); Debian/Ubuntu (DEB package), and CentOS/RHEL (RPM package).
  • Install Odoo using a Docker container: This could be a good option if you have experience with Docker and already have it installed on your system. If you're not confident with Docker, you might want to try another option so that learning Docker doesn't distract you from your current goal (learning Odoo development).

Odoo packages can be downloaded from https://download.odoo.com. They are available for all stable Odoo versions, as well as for the master branch corresponding to the latest development version. We will explain each of these options in the following sections.

For additional information on installing Odoo, you can refer to the official documentation at https://www.odoo.com/documentation/15.0/setup/install.html.

Installing on Windows using the all-in-one installer

Odoo provides an all-in-one installer for Windows, providing everything needed to run Odoo: a Python 3 runtime environment, a PostgreSQL database server, and the Odoo server with the required dependencies.

The installer can be downloaded from https://download.odoo.com. Select the desired version from the home page: 15 (stable) - Community Edition. The daily builds should be in 15.0/nightly/windows, and the latest build should be at the bottom of the list.

The installer is straightforward to follow. Odoo will be automatically started at the end of the installation.

It will also create a Windows service to automatically start the Odoo and PostgreSQL services when the machine starts. Remember this when you try other installation options such as the source code installation – port 8069 will already be used by the Windows installation, and this will prevent other installations from using the same port.

Installing on Linux using a pre-packaged installer

The Odoo download site (https://download.odoo.com) provides repositories with official packages for the Debian family (including Ubuntu) and for RHEL/CentOS.

Installation instructions for using the system-packed installers (apt or yum) are provided on the home page. Make sure that you replace the Odoo version used in the command line examples with your target one – for example, 15.0.

Before installing Odoo 15 on our Linux system, you should install the PostgreSQL database. This way, Odoo will be able to create and configure its user.

Installing Odoo using Docker containers

Docker provides a convenient multi-platform solution to run applications. It can be used to run applications on Windows, Linux, and macOS. The container technology is simple to use and resource-efficient when compared to classic virtual machines.

You must first have Docker installed on your system. Docker Desktop is the community edition and is free to use. It can be downloaded from https://www.docker.com. It is worth referring to the Docker website for the latest installation details. Docker relies on virtualization hardware features, so make sure that your basic input/output system (BIOS) has these features enabled.

General guidance on how to install and run Docker can be found at https://docs.docker.com/engine/install.

For example, for Ubuntu systems, the detailed installation instructions point to https://docs.docker.com/engine/install/ubuntu/.

Important post-installation steps – such as running Docker with a non-root user – can be found at https://docs.docker.com/engine/install/linux-postinstall/.

Docker Desktop for Windows requires Hyper-V, which is only available in Windows 10 Enterprise or Education releases. Up-to-date details should be available at https://docs.docker.com/desktop/windows/install/.

Docker Desktop for Mac requires macOS 10.14 or later.  Up-to-date details should be available at https://docs.docker.com/desktop/mac/install/.

Note

Docker Toolbox used to be available as an alternative for other Windows and macOS versions, but this distribution is now deprecated. Docker Toolbox bundles VirtualBox and provides a preconfigured shell that should be used as the command-line environment to operate Docker containers. See https://docs.docker.com/toolbox/ for more details.

The Odoo Docker official images are available on Docker Hub at https://hub.docker.com/_/odoo. There, we can also find basic instructions to get started with the Odoo Docker images. To run Odoo, two Docker containers will be created: one for the PostgreSQL database and the other for the Odoo server.

The installation and operation are done from the command line. To install the PostgreSQL Docker container, run the following:

$ docker run -d -e POSTGRES_USER=odoo -e POSTGRES_PASSWORD=odoo -e POSTGRES_DB=postgres --name db postgres:13

This will download the latest PostgreSQL image from the internet and start a container for it to run as a background job.

Next, install and run the Odoo server container, linking it to the PostgreSQL container we just started, and exposing it on port 8069:

$ docker run -t -p 8069:8069 --name odoo --link db:db odoo:15.0 -d odoo15

With this, you will see the live Odoo server log in your terminal window, and you will be able to access the Odoo instance by opening http://localhost:8069 with your chosen web browser.

Note

The Odoo server can fail to start if port 8069 is already in use. For instance, it could be in use by an already running Odoo server. In this case, you could look for and stop the running service (for example, by looking at the list of running services) or try to start this Odoo server on a different port by changing the -p option. For example, to use port 8070, use -p 8070. In that case, you can also use -d <dbname> to set the database name that this instance should use.

There are a few basic commands you should know to help manage these Docker containers:

  • docker stop <name>: Stops a container
  • docker start <name>: Starts a container
  • docker start -a <name>: Starts a container and attaches the output –  such as the server log – to the terminal window
  • docker attach <name>: Reattaches a container's output to the current terminal window
  • docker ps: Lists the current Docker containers

These are the basic commands needed to operate our Docker containers.

In case you get into trouble running the containers, here is a recipe to start over:

$ docker container stop db
$ docker container rm db
$ docker container stop odoo
$ docker container rm odoo

The Docker technology has more potential, and it might be interesting to learn more about it. The Docker website has good documentation to learn from, and a good place to get started is https://www.docker.com/get-started.