Reader small image

You're reading from  Odoo 15 Development Essentials - Fifth Edition

Product typeBook
Published inFeb 2022
Reading LevelBeginner
PublisherPackt
ISBN-139781800200067
Edition5th Edition
Languages
Tools
Right arrow
Author (1)
Daniel Reis
Daniel Reis
author image
Daniel Reis

Daniel Reis has a degree in applied mathematics and an MBA. He has had a long career in the IT industry, mostly as a consultant implementing business applications in a variety of sectors. He has been working with Odoo (OpenERP at the time) since 2010 and is an active contributor to the Odoo Community Association (OCA), where he also serves as a board member. He is the managing director of Open Source Integrators, a leading open source and Odoo consultancy firm.
Read more about Daniel Reis

Right arrow

Chapter 2: Preparing the Development Environment

Before we dive into Odoo development, we need to set up our development environment and learn about the basic administration tasks for it.

In this chapter, we will learn how to set up the working environment where we will build our Odoo applications. We will set up an Ubuntu system to host the development server instance. This can be a cloud server, a local network server, or a subsystem on your Windows 10 computer.

By the end of this chapter, you will know how to prepare a development working environment, run Odoo from source code, and have several projects and versions of Odoo on the same machine. You will also know how Odoo server instances operate, as well as how to work with them during your development work.

The following topics will be covered in this chapter:

  • Setting up a host for the Odoo server
  • Installing Odoo from source
  • Managing Odoo databases
  • Configuring the Odoo server options
  • Finding and...

Technical requirements

In this chapter, we will install Odoo from source on an Ubuntu 20.04 operating system. We only need a terminal environment; the Ubuntu graphical user interface is not needed.

If you don't have an Ubuntu 20.04 system available, a Windows 10 workstation will also work. We will be using the Windows Subsystem for Linux (WSL) to ensure you have a working Ubuntu environment on your Windows system.

The reference code for this chapter can be found in this book's GitHub repository at https://github.com/PacktPublishing/Odoo-15-Development-Essentials, in the ch02/ directory.

Setting up a host for the Odoo server

A Debian/Ubuntu system is recommended to run Odoo and is considered the reference deployment platform. Odoo's own SaaS operations are known to be Debian-based and are also the most popular choice in the community. This means that it will be easier to find help or advice if you use Debian or Ubuntu.

Note

An option for developing and running Odoo is the Odoo.sh service. It provides Git-based development workflows and provides all the complementary services needed to run a production system, such as inbound and outbound email. If this is your preference, the Odoo official documentation does a good job of introducing it. It can be found at https://www.odoo.com/documentation/user/15.0/odoo_sh/documentation.html.

If you already have an Ubuntu 20.04 system, you might be good to go. You just need to check whether you have elevated access to perform the necessary installation steps. To check this, try to run the following command on a terminal...

Installing Odoo from source

Odoo uses the Python programming language to run and uses the PostgreSQL database for data storage. To run Odoo from source, we will need to install the Python libraries it depends on. The Odoo source code can then be downloaded from GitHub. Using a Git repository should be preferred over downloading the source code ZIP or tarball file. Using Git gives us control over the code versions and is a good tool for our release process.

Note

The exact dependency installation may vary, depending on your operating system and on the Odoo version you are installing. If you have trouble with any of the previous steps, make sure you check the official documentation at https://www.odoo.com/documentation/15.0/setup/install.html. Instructions for previous editions are also available there.

Installing the PostgreSQL database

Odoo needs a PostgreSQL server to work with. The typical development setup is to have PostgreSQL installed on the same machine as Odoo.

...

Managing Odoo databases

In the previous section, we learned how to create and initialize new Odoo databases from the command line. There are more commands worth knowing about to manage Odoo databases.

The Odoo server automatically creates the new PostgreSQL database for us. But we can also do that manually using the following command:

$ createdb MyDBName

This command can be used with the --template option to copy a database. The copied database can't have open connections for this to work. So, make sure that any Odoo instance using it has been stopped.

Tip

When running PostgreSQL in WSL, it may be the case that some operations display a message such as WARNING:  could not flush dirty data: Function not implemented. A workaround for this is to modify the PostgreSQL configuration file. For version 12, it should be at /etc/postgresql/12/main/postgresql.conf. Edit it at add two lines, fsync = off and data_sync_retry = true. Then, restart the PostgreSQL server...

Configuring the Odoo server options

The Odoo server supports several options. To see all the available options, use --help:

(env15) $ odoo --help

We will review the most relevant options in the following sections. Let's start by looking at how to use configuration files.

Odoo server configuration files

Most of the options can be saved in a configuration file. By default, Odoo will use the .odoorc file. In Linux systems, the default location is in the home directory ($HOME), while in the Windows distribution, it is in the same directory as the Odoo executable.

Note

In older Odoo/OpenERP versions, the name for the default configuration file was .openerp-serverrc. For backward compatibility, Odoo will still use this if it's present and no .odoorc file is found.

In a clean installation, the .odoorc configuration file is not automatically created. We should use the --save option to create the default configuration file, if it doesn't exist yet, and store...

Finding and installing additional modules

The Odoo ecosystem has a rich community where many modules are available. Installing new modules in an Odoo instance is something that newcomers frequently find confusing. But it doesn't have to be.

Finding community modules

The Odoo Apps store at https://apps.odoo.com is a catalog of modules that can be downloaded and installed on your system.

Another important resource is the Odoo Community Association (OCA), which hosts community-maintained modules. These modules are hosted on GitHub, at https://github.com/OCA, and a searchable index is also provided at https://odoo-community.org/shop.

The OCA is a non-profit organization that was created to coordinate community contributions, promote software quality, development best practices, and open source values. You can learn more about the OCA at https://odoo-community.org.

To add a module to an Odoo installation, we could just copy it into the addons directory, alongside the...

Using the server development options

Odoo also provides a server-side development mode, which can be enabled by using the --dev=all option.

Development mode enables features to speed up the development cycle:

  • Changes to Python code are automatically reloaded when a code file is saved, avoiding a manual server restart.
  • Changes to View definitions have an instant effect, avoiding manual module upgrades (note that a browser page reload is still needed).

The --dev=all option will bring up the pdb Python debugger when an exception is raised. It is useful for doing a postmortem analysis of a server error. More details on the Python debugger commands can be found at https://docs.python.org/3/library/pdb.html#debugger-commands.

The --dev option accepts a comma-separated list of options, although the all option will be suitable most of the time. By default, the Python debugger, pdb, is used. This debugger is a bit terse, and other options are available. The supported...

Odoo commands quick reference

Here is a quick reference for the most important Odoo commands:

  • -c,--conf=my.conf: Sets the configuration file to use.
  • --save: Saves the config file.
  • --stop,--stop-after-init: Stops after module loading.
  • -d,--database=mydb: Uses this database.
  • --db-filter=^mydb$: Filters the databases that are available using a regular expression.
  • -p,--http-port=8069: The database port to use for HTTP.
  • -i,--init=MODULES: Installs the modules in a comma-separated list.
  • -u,--update=MODULES: Updates the modules in a comma-separated list.
  • --log-level=debug: The log level. Examples include debug, debug_sql, debug_rpc, debug_rpc_answer, and warn. Alternatives for debugging specific core components are as follows:
    • --log-sql: Debugs SQL calls
    • --log-request: Debugs HTTP request calls
    • --log-response: Debugs responses to HTTP calls
    • --log-web: Debugs HTTP request responses
  • --log-handler=MODULE:LEVEL: Sets the log level for a specific module...

Summary

In this chapter, we learned how to set up an Ubuntu system to host Odoo and install it from the GitHub source code. We also learned how to create Odoo databases and run Odoo instances.

You should now have a functioning Odoo environment to work with and be comfortable with managing databases and instances.

With this in place, we're ready to jump straight into the action. In the next chapter, we will create our first Odoo module from scratch and understand the main elements it involves.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Odoo 15 Development Essentials - Fifth Edition
Published in: Feb 2022Publisher: PacktISBN-13: 9781800200067
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.
undefined
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 $15.99/month. Cancel anytime

Author (1)

author image
Daniel Reis

Daniel Reis has a degree in applied mathematics and an MBA. He has had a long career in the IT industry, mostly as a consultant implementing business applications in a variety of sectors. He has been working with Odoo (OpenERP at the time) since 2010 and is an active contributor to the Odoo Community Association (OCA), where he also serves as a board member. He is the managing director of Open Source Integrators, a leading open source and Odoo consultancy firm.
Read more about Daniel Reis