DEV Community

Alfadil mustafa
Alfadil mustafa

Posted on • Updated on

My Odoo Development Environment

First of all it does not has to be the best way but it's the way that works for me and I would like to share it with you.

RUNNING THE SERVICE

Technologies used:

1- Docker more about it.

at the start we need a postgres database server so we create a container using docker.

docker run -d p 5436:5432 -v -e POSTGRES_USER=odoo -e POSTGRES_PASSWORD=odoo -e POSTGRES_DB=postgres --name dev_pg_12 postgres:12
Enter fullscreen mode Exit fullscreen mode

This means we have a pg server exposed at port 5436 so we can access it in localhost:5436

so you want to get on with your life which is running odoo server and develop awesome odoo apps (or you would be wasting your life here my friend 😕)

so you have this project which based on odoo 12 and you have some custom code so you need to create a docker file to tell docker how to create your container.

1 FROM odoo:12.0
2 USER root
3 RUN mkdir /opt/odoo && mkdir /opt/odoo/extra-addons
4 WORKDIR /opt/odoo
5 COPY requirements.txt requirements.txt
6 RUN apt-get update && apt-get install -y python3-pip && pip3 install --no-cache-dir -r requirements.txt
7 RUN chown -R odoo /opt/odoo
Enter fullscreen mode Exit fullscreen mode
What every line means:

1- The first line mean we are going to use odoo:12.0 as the base image so after this step we gonna get all v12 stuff.

2- Switch to the root user (we need the permissions).

3- We need to create directory to store custom modules(you know, what you think you need to add or change in odoo functionality you big shot).

4- Change the working directory (like 'cd' in bash).

5- Copping the requirements file ,I forgot if you have a requirements file for python of course you need to put it at the same directory as the docker file.

6- Just installing the requirements.txt file.

7- Change the owner of the /opt/odoo we created in step 3 cause the service runs with odoo user permissions.

save the file above on with name (Dockerfile) along side requirements.txt file.
if you don't have requirements.txt omit steps 5 and 6.

Now in the same directory open the terminal and run

docker build -t custom_odoo_v12 .
Enter fullscreen mode Exit fullscreen mode

Congratulation you have a working odoo v12 image on your device.

In this step you need to get odoo source, For v12

wget https://nightly.odoo.com/12.0/nightly/tgz/odoo_12.0.latest.zip
Enter fullscreen mode Exit fullscreen mode

now extract it any where in your pc.
and navigate to the odoo directory inside it
the path should be something like

/opt/odoo_12.0.latest/odoo-12.0.post20210215/odoo
Enter fullscreen mode Exit fullscreen mode

next we gonna need an odoo.conf file
let's keep it simple
/etc/odoo.conf

[options]
addons_path = /opt/odoo/extra-addons/
data_dir = /var/lib/odoo
Enter fullscreen mode Exit fullscreen mode

next we gonna run odoo service by creating an odoo container

docker run -p 8082:8069 -v odoo12-dev-web-data:/var/lib/odoo -v path/to/custom/addons:/opt/odoo/extra-addons -v /etc/odoo.conf:/etc/odoo/odoo.conf -v /opt/odoo_12.0.latest/odoo-12.0.post20210215/odoo:/usr/lib/python3/dist-packages/odoo --name odoo12-dev --link dev_pg_12:db -t custom_odoo_v12
Enter fullscreen mode Exit fullscreen mode

what does it means 🤔
1) -p 8082:8069
Mapping odoo port(8069) to port(8082) on the host (your device).
2) -v odoo12-dev-web-data:/var/lib/odoo
Creating a volume to store odoo data (like filestore ...).
3) -v path/to/custom/addons:/opt/odoo/extra-addons
You add the path to your custom addons.
4) -v /etc/odoo.conf:/etc/odoo/odoo.conf
The path to the conf file
5) -v /opt/odoo_12.0.latest/odoo-12.0.post20210215/odoo:/usr/lib/python3/dist-packages/odoo
The path to odoo source (this is optional you need it if you gonna debug the odoo files like set up a debugger or add some print statements 😅).
6) --name odoo12-dev
The name of the container.
7) --link dev_pg_12:db
Linking the PostgreSQL db to odoo as db (this is confusing I know but it's the easiest way to do it 🤷‍♂️ ).
8) -t custom_odoo_v12
The Image we gonna use.

now you can access the service on HTTP://localhost:8082.
to restart the service and see the log just do

docker restart odoo12-dev && docker logs -f odoo12-dev
Enter fullscreen mode Exit fullscreen mode

MANIPULATING THE DATA:

Technologies used:

1- Odooly get it.

You can always access odoo service via the browser like (chrome , firefox ,...), But some highly repeated processes like upgrading modules or reading data from a model or checking users access rights and rules you may need a faster way to do things.
I personally prefer Odooly it's an amazing tool which I depend on daily.
to access odoo via Odooly you just

odooly --server="http://localhost:8082" -d dev-db-1 -u admin -p admin
Enter fullscreen mode Exit fullscreen mode
there are lots of variations but I prefer this one

then you will be inside Odooly terminal just type help and you will find lots of options like
1- env.install("module_name")
2- env['res.partner'].search([],limit=10)
3- env['hr.employee'].sudo(uid).search([]) #uid of a user
Enjoy...

Top comments (2)

Collapse
 
siwaphatpg profile image
Aum Siwaphat

I'm also learning about odoo development too.
But not on docker. I'm developing on my machine.
After I understand most of odoo's concepts. I will develop it on docker too for scaleable.
Thanks for sharing your techniques.

Collapse
 
ahmadalwa profile image
ahmad alwa

how to set this enviroment with pycharm
or vs code please