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
Let’s create python environment with pipenv for our project(this story is not about how to install multiple versions of python, so I hope you have required python version installed).
mkdir odoo-tips
cd odoo-tips
pipenv --python 3.8.7
pipenv shell
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 https://github.com/odoo/odoo.git odoo-14.0
or (preferable):
wget -c https://github.com/odoo/odoo/archive/refs/heads/14.0.zip
unzip 14.0.zip
Make sure you are inside active pipenv shell and let’s make a small fix in setup.py and try to install Odoo:
cd odoo-14.0
vi setup.py
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 setup.py 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 14.0.zip
So only one file in your project’s directory is Pipfile
yet.
Postgresql database
Make sure you have Postgresql v.10 or later installed and create a new database for your project:
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
Just to check Odoo is working we can run it from command line using variables found in --help
:
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
:
Odoo config file and run-script
Let’s add some more usability — create a simple config file and shell-script to run our Odoo easily.
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 run.sh
./run.sh -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 :)