Skip to main content

Preparing the Development Environment

Preparing the Development Environment

Before we dive into Odoo development, we need to set up our development environment and learn 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 in your Windows 10 computer.
We will learn how to do the following:
  • Set up the host computer, either an Ubuntu system or a Windows 10 system, with the Windows Subsystem for Linux
  • Install Odoo from source, including the installation of the database and the system dependencies
  • Manage Odoo databases includes creating, dropping, and copying
  • Configure the Odoo server options
  • Find and install community add-on modules
  • Use virtual environments to manage different Odoo versions and projects
  • Enable the server developer mode to simplify development tasks

Setting up a host for the Odoo server

A Debian/Ubuntu system is recommended to run Odoo servers. While Odoo is multi-platform and can run on a variety of operating systems, it's also true that the Odoo R&D team considers Debian the reference deployment platform. In fact, Odoo's own SaaS operations are known to be Debian-based. It is 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. Even if you're from a Windows background, it will be important that you have some knowledge about it.
You will still be able to work from your favorite desktop system, be it Windows, Mac, or other Linux flavors, such as CentOS.

Note

Keep in mind that these instructions are intended to set up a new system for development. If you want to try some of them in an existing system, always take a backup ahead of time in order to be able to restore it in case something goes wrong.

Installing the Windows Subsystem for Linux

On a Windows system, the simplest solution is to use the Windows Subsystem for Linux (WSL), available on Windows 10. With it, we can have an Ubuntu system running inside Windows, capable of performing everything we need for Odoo development. More information on the WSL can be found at https://docs.microsoft.com/en-us/windows/wsl/about.
The WSL is a Windows 10 optional feature, available in recent builds, and must first be enabled. After that, we should install Ubuntu from the Windows store. The official instructions for that are at https://docs.microsoft.com/en-us/windows/wsl/install-win10.


At the time of writing, these are the steps needed to complete the installation:
  • Our first step is to ensure that the WSL optional feature is enabled. Open PowerShell as administrator and run the following:
Enable-WindowsOptionalFeature -Online -FeatureName 
  Microsoft-Windows-Subsystem-Linux
The preceding command should be typed in a single line. Then, restart the computer when prompted.
After this, we should install the Ubuntu Windows app. The simplest way to do that is to open the Windows store and search for Ubuntu. When writing this book, we used the latest Ubuntu long-term support (LTS) release, 18.04. Follow the installation process, including setting up a user account and corresponding password.
Running the Ubuntu application will open a Window bash command line where we can perform the same commands we would use on an Ubuntu system. Remember the user and password configured during the Ubuntu installation, since they will be prompted for whenever you need to perform actions with elevated privileges (for example, running sudo).

Installing a Linux server

We can also install Linux in our machine, in a computer in our network or in a cloud private server.
We will need a Debian-based server for our development Odoo server. If these are your first steps with Linux, note that Ubuntu is a Debian-based Linux distribution, so they are very similar.
Odoo is guaranteed to work with the current stable version of Debian or Ubuntu. At the time of writing, these are Debian 9 Stretch and Ubuntu 18.04 LTS Bionic Beaver.
We do recommend you choose Ubuntu, since it is easier to install than Debian. Ubuntu ISO images can be downloadedfrom https://www.ubuntu.com. It is recommended to use the latest LTS version available.
If you're just getting started with Linux, a ready-to-use image can be easier to start with. TurnKey Linux provides easy-to-use preinstalled images in several formats, including ISO. The ISO format will work with any virtualization software you choose, even on a bare-metal machine you might have. A good option might be the LAPP image, which includes Python and PostgreSQL, and can be found at http://www.turnkeylinux.org/lapp.
We probably want an OpenSSH server installed, to be able to remotely work on the server. Ubuntu has that option available in the setup assistant, but it can also be installed with the following command:
$ sudo apt-get install openssh-server
After this, we can use any Secure Shell (SSH) client to connect to our Odoo host. In a Windows machine, a popular option is to use PuTTY. It can be downloaded from http://www.putty.org.
We can check our server's IP address using the following:
$ ip addr show
Using an SSH client not only allows you to work on a remote server, it is also more comfortable to work with than the virtual machine console screens, providing better copy/paste support and allowing you to choose window size, font type, and so on.

Installing Odoo from source

In Chapter 1, Quick Start Using the Developer Mode, we discussed the different options available to quickly get Odoorunning on our computer. We want to go a little deeper, and run Odoo directly from the source code.
Odoo is built using the Python programming language, and it uses the PostgreSQL database for data storage; these are the two main requirements of an Odoo host. To run Odoo from source, we will first need to install the Python libraries it depends on. The Odoo source code can then be downloaded from GitHub. While we can download a ZIP file or tarball, we will see that it's better if we get the sources using the Git version control application; it'll help us to have it installed on our Odoo host as well.

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/12.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 in the same machine as Odoo. We still need to install the PostgreSQL database, required to run Odoo:
$ sudo apt update
$ sudo apt install postgresql # Install PostgreSQL
$ sudo su -c "createuser -s $USER" postgres # Create db superuser
The last command creates a PostgreSQL user for the current system user. We need that so that we can create and drop the databases to be used by our Odoo instances.
If you are running Ubuntu inside the WSL, note that system services are not automatically started. This means that you may need to manually start the PostgreSQL service before running any command that needs a database connection, such as createuser or starting an Odoo server. To manually start the PostgreSQL service, run the following: sudo service postgresql start.

Installing Odoo system dependencies

To be able to run, Odoo needs some system packages and software. To get the version controlled source code, we need Git. To install and run Odoo, we need Python 3.5 or later, pip for Python 3, and a few system dependencies needed for some Python packages:
$ sudo apt update
$ sudo apt upgrade
$ sudo apt install git  # Install Git
$ sudo apt install python3-dev python3-pip # Python 3 for dev
$ sudo apt install build-essential libxslt-dev \
libzip-devlibldap2-devlibsasl2-devlibssl-dev
Odoo releases 9, 10, and 11 require the less CSS preprocessor. So, you need to install it if you need to also these Odoo versions:
$ sudo apt install npm # Install Node.js and its package manager
$ sudo ln -s /usr/bin/nodejs /usr/bin/node# node runs Node.js
$ sudo npm install -g less less-plugin-clean-css# Install less
The preceding command is not required to run Odoo 12, but it is often the case that you need to also work on these versions and, if this is the case, you will end up needing it.

Note

Changed in Odoo 12  The CSS preprocessor used changed from less to Sass. This means that less is no longer required to run Odoo. The Sass compiler does not require additional installation steps, since it is made available by libsass-python, a Python dependency of Odoo 12. The reasons for the change include: bootstrap 4 changing from less to Sass, existing Python bindings, and avoiding Node.js (or Ruby) dependencies. 

Installing Odoo from source

To keep things organized, we will work in a /odoo-dev directory inside our home directory. Throughout the book, we will assume that the /odoo-dev is the directory where your Odoo server is installed.
Odoo 12 uses Python 3, specifically 3.5 or later. This means that on the command line, we should use python3 and pip3, instead of python and pip.

Note

Changed in Odoo 11 Starting from version 11, Odoo runs on Python 3.5 or later. Odoo 11 still runs on Python 2.7, but Odoo 12 only runs on Python 3.5+. Odoo 10 and before only run on Python 2.7.
To install Odoo from source, we start by cloning the Odoo source code directly from GitHub:
$ mkdir ~/odoo-dev  # Create a directory to work in$ cd ~/odoo-dev  # Go into our work directory
$ git clone https://github.com/odoo/odoo.git -b 12.0 \
 --depth=1  # Get Odoo sources
The ~ symbol is a shortcut for the user's home directory, such as /home/daniel.

If using Windows Subsystem for Linux, the files in the home directory are stored in a difficult to find place, inside the Windows system folder. A way to avoid this issue is to store our work files in the Windows folder of our preference, and then use a symbolic link for it (similar to a shortcut) in the Linux subsystem. For example, mkdir /mnt/c/Users/Public/odoo-dev creates the C:\Users\Public\odoo-dev working directory, and then ln -s /mnt/c/Users/Public/odoo-dev ~/odoo-dev creates the ~/odoo-dev Linux directory, which is actually a link to the  Windows directory. Now, you can run all commands on ~/odoo-dev, such as the previous git clone, and the files are all also available in C:\Users\Public\odoo-dev.
The -b 12.0 option in the Git command explicitly downloads the 12.0 branch of Odoo. At the time of writing, this is redundant since it is the default branch; however, this may change. The --depth=1 option tells Git to download only the last revision, instead of the full change history, making the download significantly smaller and faster.

Note

To download the missing commit history later, you can run git fetch --unshallow.
Before we can run Odoo, we need to install the Python dependencies declared in the requirements.txt file:
$ pip3 install -r ~/odoo-dev/odoo/requirements.txt
Many of these dependencies have Debian packages available to install them, such as python3-lxml. A valid alternative is to install them using the apt package manager. This has the advantage of automatically installing the system dependencies when necessary. The list of dependencies used can be found in the ./odoo/debian/controlfile.
A few additional Python packages, not included in requirements.txt, can be installed to suppress warning messages or enable additional features:
$ pip3 install num2words phonenumbers psycopg2-binary watchdog xlwt


Note

The pip3 utility can be installed in several different ways: the system package way and the native Python way. If a pip3command fails with an import error, reinstalling it in your system may solve the issue. The command for that is this:  sudo python3 -m pip uninstall pip && sudo apt install python3-pip --reinstall.
Now, we can start the Odoo server instance by running the following:
$ ~/odoo-dev/odoo/odoo-bin
To stop the server and return to Command Prompt, press Ctrl + C.

Note

Changed in Odoo 10The script used to start Odoo is now  ./odoo-bin. In previous Odoo versions, it was ./odoo.py.
By default, Odoo instances listen on port 8069, so if we point a browser to http://<server-address>:8069, we will reach these instances.
As developers, we will need to work with several databases, so it's more convenient to create them from the command line, and we will learn how to do this. Now, press Ctrl + C in the terminal to stop the Odoo server and get back to Command Prompt.

Initializing a new Odoo database

To create and initialize an Odoo database with the Odoo data schema, we should run the Odoo server using the -doption:
$ ~/odoo-dev/odoo/odoo-bin -d testdb
This may take a minute to initialize the testdb database, and it will end with an INFO log message, Modules loaded. Note that it might not be the last log message, and it can be in the last three or four lines. With this, the server will be ready to listen to client requests.

Note

Changed in Odoo 9Since Odoo 9, the database is automatically created if it doesn't exist yet. In version 8, this was not so, and you needed to create the database manually, using the PostgreSQL createdb command.
By default, this will initialize the database with demonstration data, which is often useful for development databases. This is the equivalent to having the Load demonstration data checkbox ticked when creating a new database from the user interface.






To initialize a database without demonstration data, add the --without-demo=all option to the command.

Note

At the time of writing, an issue with PostgreSQL specific to the Ubuntu WSL environment prevented the clean creation of new databases. The workaround for this is to manually create an empty database with the createdb 12-library command. This will show repeated messages saying WARNING: could not flush dirty data: Function not implemented. Despite the warning messages, the new database was correctly created. Press Ctrl + C to interrupt the warnings, and now you will be able to run the command to start Odoo and initialize the new database.
To be able to create a new database, your user must be a PostgreSQL superuser. The PostgreSQL setup script used in the Installing Odoo from source section takes care of that.

Note

For a development environment, it is fine for the user running the Odoo instance to be a database superuser. However, for a production environment, Odoo security best practices recommend to never run a production instance with a database user that is a superuser.
Now that we have a running Odoo instance, we can access it by opening the http://<server-name>:8069 URL with a web browser. This should present us with the Odoo login screen. If you don't know your server name, type the hostname command in the terminal in order to find it or use the ifconfig command to find the IP address.
The default administrator account is admin, with its password as admin. Upon logging in, you are presented with the Apps menu, displaying the available applications.
To stop the Odoo server instance and return to the command line, press Ctrl + Cat the Terminal window running the server. Pressing the up arrow key will bring up the previous shell command, so it's a quick way to start Odoo again with the same options. The Ctrl + C keys followed by the up arrow key and Enter is a frequently used combination to restart the Odoo server during development.

Managing Odoo databases

We've seen how to create and initialize new Odoo databases from the command line. There are more commands worth knowing about for managing databases.


Although the Odoo server automatically takes care of managing databases, we can manually create PostgreSQL databases from the command line, using the following:
$ createdb MyDB
More interestingly, Odoo can also create a new database by copying an existing one, using the --template option. For this to work, the copied database can't have open connections to it, so make sure your Odoo instance is stopped and there is no other connection open for it. The command to use looks like this:
$ createdb --template=MyDB MyDB2
In fact, every time we create a database, a template is used. If none is specified, a predefined one called template1is used.
To list the existing databases in your system, use the PostgreSQL psql utility with the -l option:
$ psql -l
Running the preceding command will list the databases we have created so far. If you followed the previous commands, you should see MyDB and MyDB2 listed . The list will also display the encoding used in each database. The default is UTF-8, which is the encoding needed for Odoo databases.
To remove a database you no longer need (or want to recreate), use the dropdb command:
$ dropdb MyDB2
Now, you know the basics to work with databases. To learn more about PostgreSQL, refer to the official documentation at http://www.postgresql.org/docs/.

Note

WarningThe dropdb command will irrevocably destroy your data. Be careful when using it and always keep backups of important databases before using this command.

More server configuration options

The Odoo server supports quite a few other options. We can check all the available options with --help:
$ ~/odoo-dev/odoo/odoo-bin --help
We will review some of the most important options in the following sections. Let's start by looking at how the currently active options can be saved in a configuration file.

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, its default location is in the home directory ($HOME), and in the Windows distribution, it is in the same directory as the executable used to launch Odoo.

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 --saveoption to create the default configuration file, if it doesn't exist yet, and store the current instance configuration into it:
$ ~/odoo-dev/odoo/odoo-bin --save --stop-after-init
Here, we also used the --stop-after-init option to stop the server after it finishes its actions. This option is often used when running tests or asking to run a module upgrade to check whether it is installed correctly.

Note

Command options can be shortened as long as they remain unambiguous. For example, the --stop-after-init option can be shortened to --stop.
Now, we can inspect what was saved in this default configuration file:
$ more ~/.odoorc# show the configuration file
This will show all the configuration options available with their default values. Editing them will be effective the next time you start an Odoo instance. Type q to quit and go back to the prompt.
We can also choose to use a specific configuration file, using the --conf=<filepath> option (or -c <filepath>). Configuration files don't need to have all the options you've just seen. Only the ones that actually change a default value need to be there.

Changing the listening port

The --http-port=<port> command option (or just -p <port>) allows us to change the listening port of a server instance from the default 8069. This can be used to run more than one instance at the same time, on the same machine.

Note

Changed in Odoo 11The --http-port server option was introduced in Odoo 11 and replaces the old --xmlrpc-portoption, used in previous versions.
Let's try this out. Open two terminal windows. On the first, run this:
$ ~/odoo-dev/odoo/odoo-bin --http-port=8070
Run the following command on the second terminal:
$ ~/odoo-dev/odoo/odoo-bin --http-port=8071
There you go, two Odoo instances on the same server listening on different ports! The two instances can use the same or different databases, depending on the configuration parameters used, and the two could be running the same or different versions of Odoo.

Note

Different Odoo versions must work with different databases. Trying to use the same database with different Odoo versions won't work, since major versions have incompatible database schemas.

Database selection options

When developing with Odoo, it is common to work with several databases, and sometimes even with different Odoo versions. Stopping and starting different server instances on the same port, and switching between different databases, can cause web client sessions to behave improperly. This is because the browser stores session cookies.
Accessing our instance using a browser window running in private mode can help avoid some of these problems.
Another good practice is to enable a database filter on the server instance to ensure that it only allows requests for the database we want to work with, ignoring all others.

Note

Changed in Odoo 11Since Odoo 11, the --database (or -d) server option accepts a comma-separated list of database names, and setting the --database option automatically also sets the --db-filter option, so that only these databases can be used by that server instance. For versions before Odoo 11, we need to use --db-filter to limit the databases accessible through this server.
The --db-filter option limits the databases that an Odoo server instance can work with. It accepts a regular expression to be used as a filter for valid database names. To match an exact name, the expression should begin with ^ and end with $.
For example, to allow only the testdb database, we would use this command:
$ ~/odoo-dev/odoo/odoo-bin --db-filter=^testdb$
It is a good practice for the --database and --db-filter options to match the same database. In fact, since Odoo 11, this is the default, since setting --database by default sets the corresponding --db-filter.

Managing server log messages

The --log-level option allows us to set the log verbosity. This can be very useful to understand what is going on in the server. For example, to enable the debug log level, use the --log-level=debug option.
The following log levels can be particularly interesting:
  • debug_sql to inspect SQL queries generated by the server
  • debug_rpc to detail requests received by the server
  • debug_rpc_answer to detail responses sent by the server
In fact, --log-level is a simplified way to set the Odoo logging verbosity. You might like to know that the more complete --log-handler option allows you to selectively turn on/off specific loggers.
By default, the log output is directed to standard output (your console screen), but it can be directed to a log file with the --logfile=<filepath> option.

Installing additional modules

Making new modules available in an Odoo instance so they can be installed is something that newcomers to Odoo frequently find confusing. But it doesn't have to be, so let's get familiar with that.

Finding community modules

There are many Odoo modules available on the internet. The Odoo app store at 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) maintained modules, also available on GitHub at https://github.com/OCA/. The OCA is a non-profit organization created to coordinate community contributions, promoting 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 official modules. In our case, the addons directory is at ~/odoo-dev/odoo/addons/. However, this is not a good idea. Our Odoo installation is a Git version-controlled code repository, and we want to keep it synchronized with the upstream GitHub repository. Polluting it with foreign modules will make it hard to manage.
Instead, we can select one or more additional locations for modules, which will also be used when the Odoo server looks for modules. Not only can we keep our custom modules in a different directory, without having them mixed with the official ones, we can also have them organized in several directories.
We can try this now by downloading the code from this book, available in GitHub, and making those add-on modules available in our Odoo installation. To get the source code from GitHub, run the following commands:
$ cd ~/odoo-dev 
$ git clone https://github.com/PacktPublishing/Odoo-12-Development-Essentials-Fourth-Edition.git library
After this, we will have a new /library directory alongside the /odoo directory containing the modules. Now, we need to let Odoo know about this new module directory.

Configuring the add-ons path

The Odoo server has a configuration option called addons_path to set where the server should look for modules. By default, this points to the /addons directory, where the Odoo server is running. We can provide not only one, but a list of directories where modules can be found. This allows us to keep our custom modules in a different directory, without having them mixed with the official add-ons.
Let's start the server with an add-ons path that includes our new module directory:
$ cd ~/odoo-dev/odoo
$ ./odoo-bin -d 12-library --addons-path="../library,./addons"
If you look closer at the server log, you will notice a line reporting the add-ons path in use: INFO ? odoo: addons paths: [...]. Confirm that it contains our library/ directory.

Installing Odoo in a Python virtual environment

It is a common case among Odoo developers to maintain code for several Odoo versions. Some organizational effort is needed to keep these projects alongside each other and working on the same development machine. And, there is some context switching needed when changing from one version to another. For example, the Odoo start executable is now odoo-bin, but in older versions it was odoo.py, and you need to remember that. With the move to Python 3, this can be even more confusing; you need to choose whether to use python / pip or python3 / pip3, depending on the Odoo server version you are working on at that moment.
Python includes virtualenv, a tool to manage independent Python environments on the same machine. Each environment has its own Python executable and installed libraries. You just need to activate the environment you want to work with; from that point on, the python and pip commands will run the executable from that environment, and the Python libraries installed in it.
To ensure that virtualenv is available in our Debian/Ubuntu, run the following command:
$ sudo apt install virtualenv


Suppose we are working in the ~/odoo-dev directory, and we have Odoo 12 source code cloned at ~/odoo-dev/odoo. We will now create an virtual environment for our Odoo 12 project:
$ virtualenv -p python3 ~/odoo-dev/odoo12env
$ source ~/odoo-dev/odoo12env/bin/activate
The first command creates the odoo12env virtual environment, which uses Python 3. The corresponding directory is created, to store the corresponding files. The environment directory has a bin/ subdirectory including, among other things, the scripts to activate and deactivate this environment.
The second command uses the source Linux command to execute the environment's activate script. This will change the current context, so that the commands available from the environment's bin/ subdirectory are used first. It also changes Command Prompt, so that it shows the current activated environment. At this point, your terminal session should look like this:
(odoo12denv) $ python --version
Python 3.5.2
(odoo12denv) $ which python
/home/daniel/odoo-dev/odoo12env/bin/python
Once we have a virtual environment activated, we can install Odoo in it. This can be done using pip  with the Odoo source code:
(odoo12denv) $ pip install -e ~/odoo-dev/odoo
The preceding command will install the Odoo source code at ~/odoo-dev/odoo, and the corresponding dependencies, in this virtual environment.
The -e option is important; it makes it an editable installation. Instead of copying a snapshot of the Odoo code into the virtual environment, it just keeps a reference to the original location of the Odoo code. Since the original source code is being used, we see in this environment the effect of changes in the source code.
The Odoo Python dependencies are automatically installed, so there is no need to manually install the packages in the requirements.txt file.
And, we can use pip to install any additional Python libraries we might need:
(odoo12denv) $ pip install phonenumbers num2words psycopg2-binary watchdog xlwt


Notice that we don't need to remember whether we are working with Python 2 or Python 3. In a virtual environment, the pip command will always point to the correct version.
Next, we can run Odoo. The pip installation creates a bin/odoo command, which can be executed fromanywhere, without the need to reference the directory where the source code is.

Note

If you decide to use virtual environments, whenever you come across a command using odoo-bin to run Odoo commands, you can replace it with just odoo.
The following command will start and stop your installed version of Odoo, printing a few log messages that can be useful to confirm things such as the Odoo version and the add-ons paths being used:
(odoo12denv) $ odoo --stop-after-init
A good practice is to keep the configuration files for your projects inside the virtual directory environment. This will initialize a 12-library database for our project and create the corresponding 12-library.conf file:
(odoo12denv) $ odoo -c ~/odoo-dev/odoo12-env/12-library.conf \
-d 12-library --addons-path=~/odoo-dev/library --save --stop
From now on, to start an Odoo server for our Library project, we use the following:
(odoo12denv) $ odoo -c ~/odoo-dev/odoo12-env/12-library.conf
Finally, when we are done, we can deactivate the environment, running the corresponding command:
(odoo12denv) $ deactivate
Now, suppose we also want to work on an Odoo 10 project on the same machine, which uses Python 2.7. Let's create that environment and install Odoo 10 in it:
$ cd ~/odoo-dev
$ git clone https://github.com/odoo/odoo.git -b 10.0 --depth=1 odoo10
$ virtualenv odoo10env
$ source odoo10env/bin/activate
(odoo10env) $ pip install -e ./odoo10
(odoo10env) $ odoo --version
(odoo10env) $ deactivate # To finish working with this env.


To make it easier to switch between Odoo versions, we make another clone of the Odoo source, for branch 10.0, in the ~/odoo-dev/odoo10 directory. We then create the virtual environment, activate it, and use pip to make an editable installation of Odoo 10. virtualenv was used with no specific Python version (-p option), and so it defaults to Python 2, the version needed for Odoo 10.
If Python 2 is not available in your system, which is the case for out-of-the-box Ubuntu 18.04, you should install it in order to be able to run older Odoo versions:
$ sudo apt install python-dev

Downloading and installing add-on modules from PyPI

Community-contributed Odoo add-ons can be packaged as Python libraries, published to Python Package Index(PyPI), and installed using pip like other libraries. For this to work, Odoo automatically adds the Python site-packages/ directory, where libraries are installed, to the Odoo addons path configuration. This packaging can be done using the setuptools-odoo tool (https://pypi.org/project/setuptools-odoo).
This is used by the OCA projects (https://github.com/OCA) to package and publish add-on modules on PyPI . Since the same module can exist for different Odoo versions, a prefix with the Odoo version is added to the module name. For example, the odoo12-addon-partner-fax PyPI package is the partner_fax add-on module for Odoo 12, which simply adds a fax field to partner: https://pypi.org/project/odoo12-addon-partner-fax/.
To download this module (and dependencies) from PyPI, and then install it in the odoo12env environment, use the following:
$ source ~/odoo-dev/odoo12env/bin/activate
(odoo12denv) $ pip install odoo12-addon-partner-fax
(odoo12denv) $ odoo -c ~/odoo-dev/odoo12-env/12-library.conf \
-i partner_fax --stop

The server development mode

To make life easier for developers , Odoo has the additional --dev=all  option to active a few developer-friendly features.

Note

Changed in Odoo 10The --dev=... option was introduced in Odoo 10. It replaces the simpler and less featured --debug option, available in versions before 10.
This enables a few handy features to speed up our development cycle. The most important are the following:
  • Reload Python code automatically once a Python file is saved, avoiding a manual server restart
  • Read view definitions directly from the XML files, avoiding manual module upgrades
The --dev=all option will bring up the Python debugger (pdb) when an exception is raised. It's useful for doing a postmortem analysis of a server error. Note that it doesn't have any effect on logger verbosity. 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. Some people might prefer to install and use alternative debuggers, for their improved features or usability. Odoo allows us to also specify a specific debugger to use. Some popular options are ipdb and pudb.  In Chapter 8,Business Logic – Supporting Business Processes, we will address how to make use of debuggers in our Odoo development.
To be able to automatically detect the changes in code files, the server developer mode requires an additional dependency to be installed, python3-watchdog. Before you can use it in an Ubuntu/Debian system, you need to install it using the following command:
$ sudo apt-get install python3-watchdog
For versions before Odoo 11 running on Python 2, install python-watchdog instead. It can also be installed using pip, with the pip install watchdog command .

Comments

  1. Great blog, Very helpful for Odoo developer. Thanks for this and I think you should post similar articles in the future.
    Hire Odoo Developer
    Odoo ERP Training

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. Thanks for providing us the services to host the development server instance by Odoo Application. In the field of technology we need a website and it's server security to grow our business online. So You must go with the choice of USA VPS Hosting. You can contact us for further details.

    ReplyDelete
  4. Really good work there. Informative and helpful. Appreciate it. But might be looking for Odoo Development Company in Virginia

    ReplyDelete

Post a Comment

Popular posts from this blog

The message and activity features

The message and activity features Odoo has available global  messaging  and activity planning features, provided by the  Discuss  application, with technical name mail. The mail module provides the  mail.thread  abstract class that makes it simple to add the messaging features to any model, and the  mail.activity.mixin  that adds planned activity features. This was done in  Chapter 4 ,  Extending Modules , to explain how to inherit features from mixin abstract classes. To add these features, we need to add the mail dependency to the add-on module,  library_checkout , and then have the library checkout model class inherit from the abstract classes providing the following features. Edit the  'depends'  key in the  library_checkout/__manifest__.py   file, to add the mail module, shown as follows: Copy 'depends': ['library_member' , 'mail' ], And edit the  library_checkout/m...

Setting up an nginx reverse proxy

Setting up an nginx reverse proxy While Odoo itself can serve web pages, it's strongly recommended that there is a  reverse  proxy positioned in front of it. A reverse proxy acts as an intermediary that manages the traffic between clients sending requests and the Odoo servers responding to them. Using a reverse proxy has several benefits. On the security side, it can do the following: Handle (and enforce) HTTPS protocols to encrypt traffic Hide the internal network characteristics Act as an application firewall, limiting the URLs accepted for processing Also, on the performance side, it can provide the following significant improvements: Cached static content, hence reducing the load on the Odoo servers Compressed content to speed up loading time Act as a load balancer, distributing load between several servers Apache is a popular choice when considering a reverse proxy, although  nginx  is a recent alternative with good technical argumen...

The QWeb template language

The QWeb template language The  QWeb  parser looks for special directives in the templates and replaces them with dynamically generated HTML. These directives are XML element attributes and can be used in any valid tag or element, such as  <div> ,  <span> , or  <field> . Sometimes, we may want to use a QWeb directive but we don't want to place it in any of the XML elements in our template. For those cases, we have a  <t>  special element that can have QWeb directives, such as  t-if  or  t-foreach , but is silent and won't have any output on the final XML/HTML produced. The QWeb directives will frequently make use of evaluated expressions to produce different results, depending on the current record values. There are two different QWeb implementations: client-side JavaScript and server-side Python. The reports and website pages use the server-side Python implementation of QWeb. Kanban views us...