Setup local development environment for Odoo

This is the first short story for a series of articles about poor-documented Odoo features and problems I had an experience to solve in past. And current one is about how to setup local development environment with python 3.8 and pipenv.

Python environment and Odoo package

mkdir odoo-tips
cd odoo-tips
pipenv --python 3.8.7
pipenv shell
building python environment with pipenv

Do not forget to upgrade pip to the latest version:

pip install --upgrade pip
pip install setuptools wheel

My way is to install Odoo as a package inside the project’s python env. Let’s clone (long time and 4Gb of disk space) or download (much quicker and 600Mb of disk space) the latest Odoo code from official repository :

git clone odoo-14.0

or (preferable):

wget -c

Make sure you are inside active pipenv shell and let’s make a small fix in and try to install Odoo:

cd odoo-14.0

Add the following command somewhere inside a configuration settings:

zip_safe = False

You should get something like this:

Install all defined Odoo requirements first:

pip install -r requirements.txt

Then run the Odoo installation:

python install

Installing can take some time and a lot of warnings could be generated during dependencies installation, but I hope none of them requires additional attention and manual re-installation, I’m sure you know what to do in such case ;)

To check all is okay, try to get odoo help:

odoo --help

The main problem in this point that only Odoo base module was installed, so we need to copy all Community version modules into the package or into our working dir manually to include them into odoo run script later:

mkdir ../community
cp -r addons/* ../community/

But I prefer to copy addons inside the installed odoo package:

pipenv --venv
# /Users/snake/.local/share/virtualenvs/odoo-tips-XvudoZ8m
cp -r addons/* /Users/snake/.local/share/virtualenvs/odoo-tips-XvudoZ8m/lib/python3.8/site-packages/odoo-14.0-py3.8.egg/odoo/addons/

That way you will have all community modules in one place and it’s very usefull having code-completion and jumps to implementations when using IDEs such as PyCharm and even VSCode.

Now you can delete Odoo source directory and/or downloaded archive:

cd ..
rm -rf odoo-14.0

So only one file in your project’s directory is Pipfile yet.

Postgresql database

createuser odootipsuser
createdb odootips
psql -d odootips

Then in psql shell set user’s password and grant him access to the database:

alter user odootipsuser with encrypted password 'YOUR_PASSWORD';
grant all privileges on database odootips to odootipsuser;

Press Ctrl+d or type \q to exit to shell.

First Odoo run

odoo --database odootips --db_user odootipsuser --db_password qwerty123 --without-demo all --init base

This command will initialize the base module and run odoo server, so you can access it on localhost:8069 using username admin and password admin :

Applications list in base Odoo installation

Odoo config file and run-script

vi odoo-local.conf    # or use you favorite editor, even PyCharm ;)

My config is very simple:

Let’s only discuss two final options data_dir and addons_path. Odoo is storing sessions, caches, file attachments into the ‘default’ directory, but I prefer to define own directory for each project, so do not forget to create it somewhere and define full path in the config file.

Addons to be created or extended in future I’ll place into ./addons/ inside my project directory.

mkdir addons
mkdir data

Let’s create run-script:

$1 and $2 is a simple cheat to force send some extra arguments to Odoo, for example I’m using it to upgrade a module when starting Odoo.

Do not forget to make script executable and simply run it :)

chmod a+x
./ -u base

I hope this story will be helpful for someone who just started to develop for Odoo. Please feel free to send comments if you found mistakes or just your ideas :)

Python developer / Odoo developer