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
Conferences
Free Learning
Arrow right icon
Odoo Development Cookbook
Odoo Development Cookbook

Odoo Development Cookbook: Build effective applications by applying Odoo development best practices

Arrow left icon
Profile Icon Daniel Reis Profile Icon Holger Brunn Profile Icon Fayolle
Arrow right icon
$54.99
Full star icon Full star icon Full star icon Full star icon Half star icon 4.6 (5 Ratings)
Paperback Apr 2016 400 pages 1st Edition
eBook
$9.99 $43.99
Paperback
$54.99
Subscription
Free Trial
Renews at $19.99p/m
Arrow left icon
Profile Icon Daniel Reis Profile Icon Holger Brunn Profile Icon Fayolle
Arrow right icon
$54.99
Full star icon Full star icon Full star icon Full star icon Half star icon 4.6 (5 Ratings)
Paperback Apr 2016 400 pages 1st Edition
eBook
$9.99 $43.99
Paperback
$54.99
Subscription
Free Trial
Renews at $19.99p/m
eBook
$9.99 $43.99
Paperback
$54.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Shipping Address

Billing Address

Shipping Methods
Table of content icon View table of contents Preview book icon Preview Book

Odoo Development Cookbook

Chapter 1. Installing the Odoo Development Environment

In this chapter, we will cover the following topics:

  • Easy installation of Odoo from source
  • Managing Odoo environments using the start command
  • Managing Odoo server databases
  • Storing the instance configuration in a file
  • Activating the Odoo developer tools
  • Updating Odoo from source

Introduction

There are lots of ways to set up an Odoo development environment. This chapter proposes one of these, although you will certainly find a number of other tutorials on the web explaining other approaches. Keep in mind that this chapter is about a development environment, which has different requirements from a production environment, covered in Chapter 16, Server Deployment.

Easy installation of Odoo from source

For Odoo deployment, it is recommended to use a GNU/Linux environment. You may be more at ease using Microsoft Windows or Mac OS X, but the fact is that most of the Odoo developers are using GNU/Linux and you are much more likely to get support from the community for OS-level issues happening on GNU/Linux than on Windows.

It is also recommended to develop using the same environment (same distribution, same version) as the one which will be used in production. This will avoid nasty surprises such as discovering on the day of deployment that some library has a different version than expected, with a slightly different and incompatible behavior. If your workstation is using a different OS, a good approach is to set up a virtual machine on your workstation and to install a GNU/Linux distribution in the VM.

Tip

To avoid copying files between your workstation where you are running your development environment and the virtual machine which runs Odoo, you can configure a SAMBA share inside the virtual machine and store the source code there. You can then mount the share on your workstation in order to edit the files easily.

This book assumes you are running Debian GNU/Linux as its stable version (Jessie at the time of writing). Ubuntu is another popular choice, and since it is built on top of Debian, most of the examples in this book should work unchanged. Whatever Linux distribution you choose, you should have some notion of how to use it from the command line, and having a few ideas about system administration will certainly not cause any harm.

Getting ready

We assume that Linux is up and running and that you have an account with root access, either because you know the root password or because sudo has been configured. In the following pages, we will be using $(whoami) whenever the login of your work user is required in a command line. This is a shell command which will substitute your login in the command you are typing.

Some operations will definitely be easier if you have a GitHub account. Go to https://github.com and create one if you don't have one already.

How to do it...

To install Odoo from source, you need to follow these steps:

  1. Run the following commands to install the main dependencies:
    $ sudo apt-get install git python2.7 postgresql nano \
    python-virtualenv
    
  2. Download and install wkhtmltopdf:
    $ wget http://nightly.odoo.com/extra/wkhtmltox-0.12.1.2_linux-jessie-amd64.deb
    $ sudo dpkg -i wkhtmltox-0.12.1.2_linux-jessie-amd64.deb
    

    Note

    Caution!

    This is a package provided by the Odoo maintainer for Debian Jessie. If you are using another distribution, browse to http://download.gna.org/wkhtmltopdf/0.12/0.12.1/ and download the package for your operating system.

  3. Now, use this to install the build dependencies:
    $ sudo apt-get install gcc python2.7-dev libxml2-dev \
    libxslt1-dev libevent-dev libsasl2-dev libldap2-dev libpq-dev \
    libpng12-dev libjpeg-dev
    
  4. Configure PostgreSQL:
    $ sudo -u postgres createuser --createdb $(whoami)
    $ createdb $(whoami)
    
  5. Configure git:
    $ git config --global user.name "Your Name"
    $ git config --global user.email youremail@example.com
    
  6. Clone the Odoo code base:
    $ mkdir ~/odoo-dev
    $ cd ~/odoo-dev
    $ git clone -b 9.0 --single-branch https://github.com/odoo/odoo.git
    $ cd odoo
    
  7. Create an odoo-9.0 virtual environment and activate it:
    $ virtualenv ~/odoo-9.0
    $ source ~/odoo-9.0/bin/activate
    
  8. Install the Python dependencies of Odoo in virtualenv:
    $ pip install -r requirements.txt
    
  9. Create and start your first Odoo instances:
    $ createdb odoo-test
    $ python odoo.py -d odoo-test --addons-path=addons \
    --dbfilter=odoo-test$
    
  10. Point your browser to http://localhost:8069 and authenticate using the admin account and admin as password.

Tip

You can download the example code files for this book from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

You can download the code files by following these steps:

  • Log in or register to our website using your e-mail address and password
  • Hover the mouse pointer on the SUPPORT tab at the top
  • Click on Code Downloads & Errata
  • Enter the name of the book in the Search box
  • Select the book for which you're looking to download the code files
  • Choose from the drop-down menu where you purchased this book from
  • Click on Code Download

You can also download the code files by clicking on the Code Files button on the book's webpage at the Packt Publishing website. This page can be accessed by entering the book's name in the Search box. Please note that you need to be logged in to your Packt account.

Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

  • WinRAR / 7-Zip for Windows
  • Zipeg / iZip / UnRarX for Mac
  • 7-Zip / PeaZip for Linux

How it works...

Dependencies come from various sources. First, you have the core dependencies of Odoo, the Python interpreter that is used to run the source code, and the PostgreSQL database server used to store the instance data. Git is used for source code versioning and getting the source code of Odoo itself.

Since we will need to edit some files as root or as postgres (the PostgreSQL administrative user) on our server, we need to install a console-based text editor. We suggest nano as it is very simple to use, but feel free to choose any editor with which you feel at ease as long as it works on the console, such as vim, e3, or emacs-nox.

Wkhtmltopdf is a runtime dependency of Odoo used to produce PDF reports. The version required by Odoo 9.0 is 0.12.1, which is not included in current GNU/Linux distributions. Fortunately for us, the maintainers of wkhtmltopdf provide prebuilt packages for various distributions on http://wkhtmltopdf.org/downloads.html (in the archive section). However, Debian Jessie is not there, so the Odoo maintainers provide their own version of the package on http://nightly.odoo.com/extra/.

There are lots of other runtime dependencies that are Python modules, which we can install using pip in a virtual environment. However, some of these Python modules can feature some dependencies on native C libraries for which the Python bindings need to be compiled. We therefore install the development packages for these C libraries as well as the Python development package and a C compiler. Once these build dependencies are installed, we can use pip -r requirements.txt (a file which comes from the Odoo source code distribution) to download, compile, and install the Python modules.

Virtual environments

Python virtual environments, or virtualenv for short, are isolated Python workspaces. They are very useful to Python developers because they allow different workspaces with different versions of various Python libraries installed, possibly on different Python interpreter versions.

You can create as many environments as you wish using the command virtualenv path/to/newenv. This will create a newenv directory in the specified location, containing a bin/ subdirectory and a lib/python2.7 subdirectory.

In bin/ you will find several scripts:

  • activate: The script is not executed, it is sourced using the built-in source shell. This will activate the environment by adjusting the PATH environment variable to include the bin/ directory of the virtualenv. It also installs a shell function called deactivate, which you can run to exit the virtualenv, and changes the shell prompt to let you know which virtualenv is currently activated
  • pip: This is a special version of the pip command which acts inside the virtualenv only.
  • python: This is a wrapper around your system Python interpreter which uses the packages installed in the virtualenv.

Tip

The built-in source shell is also available (as a single dot, followed by a space, and the path to the file to source). The shortcut form is perfectly fine, but we will stick to source in this book for readability.

There are two main ways of using a virtualenv. You may activate it as we show in the recipe (and call deactivate when you're done) or you may use the scripts in the bin/ directory of the environment explicitly by calling them with their full path, in which case you don't need to activate the virtualenv. This is mainly a matter of taste, so you should experiment and find out which style suits you better for which case.

You may have executable Python scripts with the first line looking like the following:

#! /usr/bin/env python

These will be easier to use with an activated virtualenv. This is the case with the odoo.py script, which you can therefore call in the following way:

$ ./odoo.py -d odoo-test --addons-path=addons --db-filter=odoo-test$

PostgreSQL configuration

On a GNU/Linux system, Odoo works very well with the default values of psycopg2, the Python module used to access a PostgreSQL database:

  • Passwordless authentication if the database user has the same name as the current user on local connections
  • Local connection uses Unix domain sockets
  • The database server listens on port 5432

In that case, there is nothing special to do: we use the postgres administrative user to create a database user which shares our login name and give it the right to create new databases. We then create a new database with the same name as the new user, which will be used as a default database when using the psql command.

When on a development server, it is OK to give the PostgreSQL user more rights and to use the --superuser command-line option rather than just --createdb. The net effect is that this user can then also create other users and globally manage the database instance. If you feel --superuser is too much, you may still want to use --createrole in addition to --createdb when creating your database user. Avoid doing this on production servers as it would give additional leverage to an attacker exploiting a vulnerability in some part of the deployed code (see Chapter 16, Server Deployment).

If you want to use a database user with a different login, you will need to provide a password for the user. This is done by passing the --pwprompt flag on the command line when creating the user, in which case the command will prompt you for the password.

If the user has already been created and you want to set a password (or modify a forgotten password) you can use the following command:

$ psql -c "alter role $(whoami) with password 'newpassword'"

Note

If this command fails with an error message saying that the database does not exist, it is because you did not create a database named after your login name in step 3. That's fine; just add the --dbname option with an existing database name such as --dbname template1.

Git configuration

At some point in the book, you will need to use git commit. This will fail unless some basic configuration is performed; you need to provide Git with your name and email address. Git will remind you to do this with a nice error message, but you may as well do it now.

Note

This is also something to keep in mind if you are using a service such as Travis for continuous integration, and your test scripts need to perform some git merges: you have to provide a dummy name and e-mail for the merging to succeed.

Downloading the Odoo source code

Downloading the Odoo code base is done by performing a git clone operation. Be patient as this will take some time. The options --branch 9.0 --single-branch avoid downloading other branches and save a little time. The --depth option can also be used to avoid downloading the whole repository history, but the downside of that option is that you will not be able to explore that history when looking for issues.

The Odoo developers also propose nightly builds, which are available as tarballs and distribution packages. The main advantage of using a git clone is that you will be able to update your repository when new bug fixes are committed in the source tree. You will also be able to easily test any proposed fixes and track regressions, so you can make your bug reports more precise and helpful for the developers.

Starting the instance

Now comes the moment you've been waiting for. To start our first instance, we first create a new empty database and then use the odoo.py script with the following command-line arguments:

  • -d database_name: Use that database by default.
  • --db-filter=database_name$: Only try to connect to databases matching the supplied regular expression. One Odoo installation can serve multiple instances living in separate databases and this argument limits the available databases. The trailing $ is important as the regular expression is used in match mode; this avoids selecting names starting with the specified string.
  • --addons-path=directory1,directory2,...: This is a comma separated list of directories in which Odoo will look for addons. This list is scanned at the instance creation time to populate the list of available add-on modules in the instance.

If you are using a database user with a database login different from your Linux login, you need to pass the following additional arguments:

  • --db_host=localhost: use a TCP connection to the database server
  • --db_user=database_username: use the specified database login
  • --db_password=database_password: the password to use to authenticate against the PostgreSQL server

To get an overview of all the available options, use the --help argument. We will see much more about the odoo.py script in this chapter as well as in Chapter 2, Managing Odoo Server Instances.

When Odoo is started on an empty database, it will first create the database structure needed to support its operations. It will also scan the addons path to find the available addon modules, and insert some the initial records in the database. This includes the admin user with the default password admin which you will use to authenticate with.

Odoo includes an HTTP server. By default, it listens on all local network interfaces on TCP port 8069 so pointing your web browser to http://localhost:8069/ leads you to your newly created instance.

There is more…

In the recipe, we downloaded the latest stable version of Odoo using the following command:

$ git clone -b 9.0 --single-branch https://github.com/odoo/odoo.git

This uses the official branch maintained by Odoo. One issue with this branch is that bug fixes contributed by the community are not always merged in a timely fashion. The Odoo Community Association (OCA) maintains a parallel branch in which fixes and improvements are peer-reviewed by the community and tend to be merged faster than on the official branch. It is not a fork of Odoo, and the latest version of Odoo is merged back into that branch daily. You may want to use it for your developments and deployments, in which case you need to clone Odoo like this:

$ git clone -b 9.0 --single-branch https://github.com/OCA/OCB.git odoo

Managing Odoo environments using the start command

We will often want to use custom or community modules with our Odoo instance. Keeping them in a separate directory makes it easier to install upgrades to Odoo or troubleshoot issues from our custom modules. We just have to add that directory to the addons path and they will be available in our instance, just like the core modules are.

It is possible to think about this module directory as an Odoo environment. The Odoo start command makes it easy to organize Odoo instances as directories, each with its own modules.

Getting ready

For this recipe we need to have already installed Odoo. We assume that it will be at ~/odoo-dev/odoo, and that the virtualenv is activated.

This means that the following command should successfully start an Odoo server:

$ ~/odoo-dev/odoo/odoo.py

How to do it...

To create a work environment for your instance, you need to follow these steps:

  1. Change to the directory where Odoo is:
    $ cd ~/odoo-dev
    
  2. Choose a name for the environment and create a directory for it:
    $ mkdir my-odoo
    
  3. Change to that directory and start an Odoo server instance for that environment:
    $ cd my-odoo/
    $ ../odoo/odoo.py start
    

How it works...

The Odoo start command is a shortcut to start a server instance using the current directory. The directory name is automatically used as the database name (for the -d option), and the current directory is automatically added to the addons path (the --addons-path option) as long as it contains an Odoo addon module. In the preceding recipe you won't see the current directory in the addons path because it doesn't contain any modules yet.

There's more

By default the current directory is used, but the --path option allows you to set a specific path to use instead. For example, this would work from any directory:

$ ~/odoo-dev/odoo/odoo.py start --path=~/odoo-dev/my-odoo

The database to use can also be overridden using the usual -d option. In fact, all the other usual odoo.py command-line arguments, except --addons-path, will work. For example, to set the server listening port, use the following command:

$ ../odoo/odoo.py start --xmlrpc-port=8080

As we can see, the Odoo start command can be a convenient way to quickstart Odoo instances with their own module directory.

Managing Odoo server databases

When working with Odoo, all the data of your instance is stored in a PostgreSQL database. All the standard database management tools you are used to are available, but Odoo also proposes a web interface for some common operations.

Getting ready

We assume that your work environment is set up and you have an instance running. Do not start it using the odoo.py start command shown in the previous recipe, as it configures the server with some options which interfere with multi-database management.

How to do it...

The Odoo database management interface provides tools to create, duplicate, remove, back up, and restore a database. There is also a way to change the master password which is used to protect access to the database management interface.

Access the Database Management interface

To access the database, the following steps need to be performed:

  1. Go to the login screen of your instance (if you are authenticated, log out).
  2. Click on the Manage Databases link. This will navigate to http://localhost:8069/web/database/manager (you can also point your browser directly to that URL.).

Set or change the master password

If you've set up your instance with default values, and not yet modified it as explained in the following section, the database management screen will display a warning telling you that the master password is not set, and advising you to set one, with a direct link:

Set or change the master password
  1. To set the Master Password, you can click on that link. You will get a dialog box asking you to provide the new password:
    Set or change the master password
  2. Type in a non-trivial new password and click on Continue.
  3. When the master password is already set, click the Set Master Password button at the bottom of the screen to change it
  4. In the displayed dialog box, type the previous master password and the new one, and then click on Continue.

Note

The master password is in the server configuration file under the admin_password key. If the server was started without specifying a configuration file, a new one will be generated in ~/.openerp_serverrc. See the next recipe for more information about the configuration file.

Creating a new database

This dialog box can be used to create a new database instance which will be handled by the current Odoo server:

  1. In the database management screen, click on the Create Database button at the bottom of the screen.
    Creating a new database
  2. Fill the form in as follows:
    • Master password: The master password for this instance.
    • Database name: Input the name of the database you wish to create.
    • Language: Select the language you wish to be installed by default in the new database.
    • Password of admin user: Type the password you want to set for the admin user of the new instance.
    • Load demonstration data: Check this box to have demonstration data. This is useful to run tests or set up a demonstration for a customer, but should not be checked for a database meant to contain production data.
  3. Click on the Continue button, and wait a little until the new database is initialized. You will then be redirected to the instance, connected as the Administrator.

Tip

Troubleshooting

If you are redirected to a login screen, this is probably because the option --db-filter was passed to Odoo and the new database name did not match the new database name. Note that the odoo.py start command does this silently, making only the current database available. To work around this, simply restart Odoo without the start command, as shown in the first recipe of this chapter. If you have a configuration file (see the Storing the instance configuration in a file recipe later in this chapter), then check that the db_filter option is unset or set to a value matching the new database name.

Duplicating a database

Very often you will have an existing database and you want to experiment with it to try a procedure or run a test, but without modifying the existing data. The answer is simple: duplicate the database and run the tests on the copy. Repeat as many times as required:

  1. In the database management screen, click on the Duplicate link next to the name of the database you wish to clone.
    Duplicating a database
  2. Fill in the form:
    • Master Password: the master password of the Odoo server
    • New Name: the name you want to give to the copy
  3. Click on the Continue button.
  4. You can then click on the name of the newly created database in the database management screen to access the login screen for that database.

Removing a database

When you have finished your tests, you will want to clean up the duplicated databases. To do this, perform the following steps:

  1. In the database management screen, click on the Delete link next to the name of the database you want to remove.
    Removing a database
  2. Fill in the form; enter the Master Password, which is the master password of the Odoo server.
  3. Click the Delete button.

Note

Caution! Potential data loss!

If you selected the wrong database, and have no backup, there is no way to recover the lost data.

Backing up a database

For creating a backup, the following steps need to be performed:

  1. In the database management screen, click the Backup link next to the database you want to back up.
    Backing up a database
  2. Fill in the form:
    • Master Password: the master password of the Odoo server.
    • Backup Format: always use zip for a production database, as it is the only real full backup format. Only use the pg_dump format for a development database where you don't really care about the file store (admin by default).
  3. Click the Backup button. The backup file will be downloaded to your browser.

Restoring a database backup

If you need to restore a backup, this is what you need to do:

  1. In the database management screen, click the Restore Database button at the bottom of the screen.
    Restoring a database backup
  2. Fill in the form:
    • Master Password: the master password of the Odoo server.
    • File: a previously downloaded Odoo backup.
    • Database Name: provide the name of the database in which the backup will be restored. The database must not exist on the server.
    • Generate a new database uuid: leave unchecked if you are installing a database which has been deleted from the server; otherwise check the box. There is little difference between them, and if in doubt, leaving it unchecked is a safe choice.
  3. Click the Continue button.

Note

Note: It is not possible to restore a database on top of itself. If you try to do this, you will get an error message (Database restore error: Database already exists). You need to remove the database first.

How it works...

These features, apart from the Change master password screen, run postgresql administration commands on the server and report back through the web interface.

The master password is a very important piece of information which only lives in the Odoo server configuration file and is never stored in the database. There used to be a default value of admin, but using this value is a security liability as it is well known. In Odoo v9, this is identified as an "unset" master password and you get urged to change it when accessing the database administration interface. Even if it is stored in the configuration file under the admin_passwd entry, this is not the same as the password of the admin user; these are two independent passwords: the master password is set for an Odoo server process, which itself can handle multiple database instances, each of which has an independent admin user with his own password.

Note

Security considerations: Remember that we are considering a development environment in this chapter. The Odoo database management interface is something which needs to be secured when you are working on a production server as it gives access to a lot of sensitive information, especially if the server hosts Odoo instances for several different clients. This will be covered in Chapter 16, Server Deployment.

To create a new database, Odoo uses the PostgreSQL createdb utility and calls the internal Odoo function to initialize the new database in the same way as when you start Odoo on an empty database.

To duplicate a database, Odoo uses the --template option of createdb passing the original database as an argument. This essentially duplicates the structure of the template database in the new database using internal and optimized PostgreSQL routines, which is much faster than creating a backup and restoring it (especially when using the web interface which requires downloading the backup file and uploading it again).

Backup and restore operations use the pg_dump and pg_restore utilities respectively. When using the .zip format, the backup will also include a copy of the file store which contains a copy of the documents when you configure Odoo to not keep these in the database, which is the default in 9.0. Unless you configure it otherwise, these files live in ~/.local/share/Odoo/filestore.

Note

If the backup gets large, downloading it may fail, either because the Odoo server itself is not able to handle the large file in memory or if the server runs behind a reverse proxy (see Chapter 16, Server Deployment) because there is a limit to the size of HTTP responses set in the proxy. Conversely, for the same reasons, you will likely experience issues with the database restore operation. When you start running into these issues, it is time to invest in a more robust external backup solution.

There is more...

Experienced Odoo developers generally don't use the database management interface, and perform the operations from the command line. To initialize a new database with demo data for instance, the following one-liner can be used:

$ createdb testdb && odoo.py -d testdb

The additional bonus of this command line is that you can request installation of addons while you are at it using for instance -i sale,purchase,stock (more on this in Chapter 2, Managing Odoo Server Instances).

To duplicate a database, stop the server, and run the following command:

$ createdb -T dbname newdbname
$ cd ~/.local/share/Odoo/filestore # adapt if you have changed the data_dir
$ cp -r dbname newdbname
$ cd -

Note that in the context of development, the file store is often omitted.

Tip

The use of createdb -T only works if there are no active sessions on the database, which means you have to shut down your Odoo server before duplicating the database from the command line.

To remove an instance, run the following command:

$ dropdb dbname
$ rm -rf ~/.local/share/Odoo/filestore/dbname

To create a backup (assuming the PostgreSQL server is running locally), use the following command:

$ pg_dump -Fc -f dbname.dump dbname
$ tar cjf dbname.tgz dbname.dump ~/.local/share/Odoo/filestore/dbname

To restore the backup, run the following command:

$ tar xf dbname.tgz
$ pg_restore -C -d dbname dbname.dump

Note

Caution!

If your Odoo instance uses a different user to connect to the database you need to pass -U username so that the correct user is the owner of the restored database.

Storing the instance configuration in a file

The odoo.py script has dozens of options, and it is tedious to remember them all and to remember to set them properly when starting the server. Fortunately, it is possible to store them all in a configuration file and to only specify by hand the ones you want to alter, for example, for development.

How to do it...

To generate a configuration file for your Odoo instance, run the following command:

$ odoo.py --save --config myodoo.cfg --stop-after-init

You can add additional options, and their values will be saved in the generated file. All the unset options will be saved with their default value set. To get a list of possible options, use:

$ odoo.py --help | less

This will provide you with some help about what the various options perform. To convert from the command line form to the configuration form, use the long option name, remove the leading dashes, and convert the dashes in the middle to underscores: --without-demo becomes without_demo. This works for most options, but there are a few exceptions listed in the next section.

Edit the file myodoo.cfg (use the table in the following section for some parameters you may want to change). Then to start the server with the saved options, run the following command:

$ odoo.py -c myodoo.cfg

Note

The --config option is commonly abbreviated as -c

How it works...

At start up, Odoo loads its configuration in three passes. First a set of default values for all options is initialized from the source code. Then the configuration is parsed, and any value defined in the file overrides the defaults. Finally, the command-line options are analyzed and their values override the configuration obtained from the previous pass.

As mentioned earlier, the names of the configuration variables can be found from the names of the command-line options by removing the leading dashes and converting the middle dashes to underscores. There are a few exceptions, notably:

Command line

Configuration file

--db-filter

dbfilter

--no-xmlrpc

xmlrpc = True / False

--database

db_name

--debug

debug_mode = True / False

--i18n-import / --i18n-export

Unavailable

Here is a list of options commonly set through the configuration file:

Option

Format

Usage

without_demo

 

Prevents module demo data from being loaded.

addons_path

Comma separated list of paths

A list of directory names in which the server will look for addons (see Chapter 2, Managing Odoo Server instances).

admin_passwd

Text

The master password (see previous recipe).

data_dir

Path to a directory

A directory in which the server will store session information, addons downloaded from the Internet, and documents if you enable the file store.

db_host

Host name

The name of the server running the PostgreSQL server. Use False to use local Unix Domain sockets, and localhost to use TCP sockets locally.

db_user

Database user login

 

db_password

Database user password

This is generally empty if db_host is False and db_user has the same name as the user running the server. Read the man page of pg_hba.conf for more information on this.

database

Database name

Used to set the database name on which some commands operate by default). This does not limit the databases on which the server will act. See the following dbfilter option for this.

dbfilter

A regular expression

The expression should match the name of the databases considered by the server. If you run the website, it should match a single database, so it will look like ^databasename$. More information on this is in Chapter 16, Server Deployment.

xmlrpc_interface

IP address of a network interface

Defaults to 0.0.0.0, meaning the server listens on all interfaces

xmlrpc_portlongpolling_port

Port number

The ports on which the Odoo server will listen. You will need to specify both to run multiple Odoo servers on the same host. longpolling_port is only used if workers is not 0.

logfile

Path to a file

The file in which Odoo will write its logs.

log_level

Log verbosity level

Specify the level of logging. Accepted values (in increasing verbosity order): critical, error, warn, info, debug, debug_rpc, debug_rpc_answer, debug_sql.

workers

Integer

The number of worker processes. See Chapter 16, Server Deployment, for more information.

no_database_list

True / False

Set to True to disable listing of databases. See Chapter 16, Server Deployment, for more information.

There is more...

The parsing of the configuration file by Odoo is done using the Python ConfigParser module. This module supports defining values for variables from the values of other variables using the %(section.variable)s notation. You can omit section if the value comes from the same section or if it is defined in the special [DEFAULT] section.

For instance, if you want to define the database login to be the same as the database name, you can write the following in your Odoo configuration file:

[options]
db_name = projectname
db_user = %(options.db_name)s

A very common use is to define a common prefix for the paths of the addons:

[DEFAULT]
project = /home/odoo/projects/project1
env = dev
prefix = %(project)s/%(env)s

[options]
addons-path = %(prefix)s/odoo/addons,%(prefix)s/OCA/server-tools
data_dir = %(prefix)s/data_dir

Activating the Odoo developer tools

When using Odoo as a developer, you need to know how to activate Developer Mode in the web interface to access the advanced settings menu and developer information.

How to do it...

To activate Developer Mode in the web interface:

  1. Connect to your instance and authenticate (not necessarily as admin; this function is available to all users, but the Administrator has more tools available).
  2. Click on the down arrow next to your user name in the top right corner of the page .
    How to do it...
  3. In the drop-down menu, click on About.
  4. In the dialog box which is displayed, click on Activate the developer mode in the top right corner.
    How to do it...

    Note

    It is also possible to activate the developer mode by editing the URL: before the # sign, insert ?debug=. For instance, if you are starting from: http://localhost:8069/web#menu_id=102&action=94, then you need to change this to: http://localhost:8069/web?debug=#menu_id=102&action=94.

  5. To exit developer mode, you can edit the URL and remove that string, close your browser tab and open a new one, or use the Leave Debug Mode option at the bottom of the debug drop-down menu next to the user menu in the top right of the screen.

    How to do it...

How it works...

When in developer mode, three things happen:

  • The JavaScript and CSS code sent to the browser is not minified, which means that the web development tools of your browser are easy to use for debugging the JavaScript code (more on this in Chapter 15, Web Client Development).
  • You get tooltips when hovering over a field in a form view or over a column in list view providing technical information about the field (internal name, type, and so on).
  • A drop-down menu with a Bug icon is displayed next to the user's menu in the top right corner giving access to technical information about the model being displayed, the various related view definitions, the workflow, custom filter management, and so on.

Note

Caution!

Test your addons both with and without developer mode, as the unminified versions of the JavaScript libraries can hide bugs which only bite you in the minified version.

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Each recipe stands by itself as much as possible, so that you can jump straight into the topics you prefer
  • The recipes included cover all the major development areas of Odoo and the most important techniques explained through real-life projects
  • From seasoned authors, learn the tricks of becoming a productive developer with the Odoo framework

Description

Odoo is a full-featured open source ERP with a focus on extensibility. The flexibility and sustainability of open source is also a key selling point of Odoo. It is built on a powerful framework for rapid application development, both for back-end applications and front-end websites. The book starts by covering Odoo installation and administration, and provides a gentle introduction to application development. It then dives deep into several of the areas that an experienced developer will need to use. You’ll learn implement business logic, adapt the UI, and extend existing features.

Who is this book for?

If you are a Python developer who wants to learn or consolidate your Odoo development skills, then this book is for you! Some experience with the JavaScript programming language and web development is required to fully benefit from the front-end chapters.

What you will learn

  • Install and manage Odoo environments and instances
  • Use Models to define your application s data structures
  • Add business logic to your applications
  • Implement automated tests and debug Odoo apps
  • Use back-end views to create a user interface
  • Get to know about the access security model and internationalization features
  • Develop front-end website features
  • Extend the web client with new widgets and features
Estimated delivery fee Deliver to Taiwan

Standard delivery 10 - 13 business days

$12.95

Premium delivery 5 - 8 business days

$45.95
(Includes tracking information)

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Apr 29, 2016
Length: 400 pages
Edition : 1st
Language : English
ISBN-13 : 9781785883644
Vendor :
Odoo S.A
Category :
Languages :
Tools :

What do you get with Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Shipping Address

Billing Address

Shipping Methods
Estimated delivery fee Deliver to Taiwan

Standard delivery 10 - 13 business days

$12.95

Premium delivery 5 - 8 business days

$45.95
(Includes tracking information)

Product Details

Publication date : Apr 29, 2016
Length: 400 pages
Edition : 1st
Language : English
ISBN-13 : 9781785883644
Vendor :
Odoo S.A
Category :
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total $ 136.97
Odoo Development Essentials
$32.99
Odoo 10 Development Essentials
$48.99
Odoo Development Cookbook
$54.99
Total $ 136.97 Stars icon
Banner background image

Table of Contents

17 Chapters
1. Installing the Odoo Development Environment Chevron down icon Chevron up icon
2. Managing Odoo Server Instances Chevron down icon Chevron up icon
3. Creating Odoo Modules Chevron down icon Chevron up icon
4. Application Models Chevron down icon Chevron up icon
5. Basic Server Side Development Chevron down icon Chevron up icon
6. Advanced Server Side Development Techniques Chevron down icon Chevron up icon
7. Debugging and Automated Testing Chevron down icon Chevron up icon
8. Backend Views Chevron down icon Chevron up icon
9. Module Data Chevron down icon Chevron up icon
10. Access Security Chevron down icon Chevron up icon
11. Internationalization Chevron down icon Chevron up icon
12. Automation and Workflows Chevron down icon Chevron up icon
13. Web Server Development Chevron down icon Chevron up icon
14. CMS Website Development Chevron down icon Chevron up icon
15. Web Client Development Chevron down icon Chevron up icon
16. Server Deployment Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Full star icon Half star icon 4.6
(5 Ratings)
5 star 60%
4 star 40%
3 star 0%
2 star 0%
1 star 0%
N. Demarco Aug 16, 2016
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I always want to know know who is writing the computer software book review, so I'll start there. I'm pretty comfortable in Linux. I'm not really a developer or DevOp. I have a lot of manufacturing and ERP experience. Let's get into the book review.The book is written for Odoo v9. v10 comes out ~October 2016. Most info will still apply. v8 was a bit different, and v7 was wholly different. This book should work for quite a while.What it won't do:This won't teach you Linux, Python, or XML syntax, but it shouldn't. You should have a reasonable understanding of git (like GitHub). You should have already played with Odoo a bit to learn how it comes together. You should also know about your business processes.What it will do:Teach you by doing first, explaining second. Chapters are organized with the _how it works_ following the procedural _recipe_. This works well because you're curious to see how a certain bit you just typed works. Brunn et.al. have done well referring to related recipes, including those you haven't seen yet.You'll learn, by example, how to set up a new Odoo instance. The authors give good tips for building a maintanable infrastructure to run your Odoo project.You'll learn how to create and extend Odoo modules. After building out some basic functionality, the authors explain more broad concepts. Don't expect your pace through the book to be linear. The first few chapters may take 1-2 days. Mastering later chapters could take months or more. In this way, Cookbook is instructional and a reference.If you're building out an Odoo instance, or if you develop Odoo modules professionally, this is definitely worth the small price.
Amazon Verified review Amazon
Wilton Beltre Aug 08, 2016
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I'm just half of the book and am very surprised with the details which it covers, terrific book!
Amazon Verified review Amazon
Jaidev Shah Nov 28, 2016
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This is the book to buy for practically any reference for Odoo. Great book!!
Amazon Verified review Amazon
Ravi Bhattarai May 10, 2016
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
This is one of the detailed and widely covered book on Odoo Development. I liked the simplicity and coverage made in the book. It was one of the long awaited and need for the market for new and experienced developers alike.
Amazon Verified review Amazon
shrek Jan 25, 2017
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
Nice one but not much in use for odoo 10. Odoo 10 has major syntax change
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is the delivery time and cost of print book? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela
What is custom duty/charge? Chevron down icon Chevron up icon

Customs duty are charges levied on goods when they cross international borders. It is a tax that is imposed on imported goods. These duties are charged by special authorities and bodies created by local governments and are meant to protect local industries, economies, and businesses.

Do I have to pay customs charges for the print book order? Chevron down icon Chevron up icon

The orders shipped to the countries that are listed under EU27 will not bear custom charges. They are paid by Packt as part of the order.

List of EU27 countries: www.gov.uk/eu-eea:

A custom duty or localized taxes may be applicable on the shipment and would be charged by the recipient country outside of the EU27 which should be paid by the customer and these duties are not included in the shipping charges been charged on the order.

How do I know my custom duty charges? Chevron down icon Chevron up icon

The amount of duty payable varies greatly depending on the imported goods, the country of origin and several other factors like the total invoice amount or dimensions like weight, and other such criteria applicable in your country.

For example:

  • If you live in Mexico, and the declared value of your ordered items is over $ 50, for you to receive a package, you will have to pay additional import tax of 19% which will be $ 9.50 to the courier service.
  • Whereas if you live in Turkey, and the declared value of your ordered items is over € 22, for you to receive a package, you will have to pay additional import tax of 18% which will be € 3.96 to the courier service.
How can I cancel my order? Chevron down icon Chevron up icon

Cancellation Policy for Published Printed Books:

You can cancel any order within 1 hour of placing the order. Simply contact customercare@packt.com with your order details or payment transaction id. If your order has already started the shipment process, we will do our best to stop it. However, if it is already on the way to you then when you receive it, you can contact us at customercare@packt.com using the returns and refund process.

Please understand that Packt Publishing cannot provide refunds or cancel any order except for the cases described in our Return Policy (i.e. Packt Publishing agrees to replace your printed book because it arrives damaged or material defect in book), Packt Publishing will not accept returns.

What is your returns and refunds policy? Chevron down icon Chevron up icon

Return Policy:

We want you to be happy with your purchase from Packtpub.com. We will not hassle you with returning print books to us. If the print book you receive from us is incorrect, damaged, doesn't work or is unacceptably late, please contact Customer Relations Team on customercare@packt.com with the order number and issue details as explained below:

  1. If you ordered (eBook, Video or Print Book) incorrectly or accidentally, please contact Customer Relations Team on customercare@packt.com within one hour of placing the order and we will replace/refund you the item cost.
  2. Sadly, if your eBook or Video file is faulty or a fault occurs during the eBook or Video being made available to you, i.e. during download then you should contact Customer Relations Team within 14 days of purchase on customercare@packt.com who will be able to resolve this issue for you.
  3. You will have a choice of replacement or refund of the problem items.(damaged, defective or incorrect)
  4. Once Customer Care Team confirms that you will be refunded, you should receive the refund within 10 to 12 working days.
  5. If you are only requesting a refund of one book from a multiple order, then we will refund you the appropriate single item.
  6. Where the items were shipped under a free shipping offer, there will be no shipping costs to refund.

On the off chance your printed book arrives damaged, with book material defect, contact our Customer Relation Team on customercare@packt.com within 14 days of receipt of the book with appropriate evidence of damage and we will work with you to secure a replacement copy, if necessary. Please note that each printed book you order from us is individually made by Packt's professional book-printing partner which is on a print-on-demand basis.

What tax is charged? Chevron down icon Chevron up icon

Currently, no tax is charged on the purchase of any print book (subject to change based on the laws and regulations). A localized VAT fee is charged only to our European and UK customers on eBooks, Video and subscriptions that they buy. GST is charged to Indian customers for eBooks and video purchases.

What payment methods can I use? Chevron down icon Chevron up icon

You can pay with the following card types:

  1. Visa Debit
  2. Visa Credit
  3. MasterCard
  4. PayPal
What is the delivery time and cost of print books? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela