Enable Dark Mode!
configuring-odoo-with-visual-studio-code.jpg
By: Sreerag E

Odoo Development Environment with Visual Studio Code

Technical Odoo 14

VS Code is one of the popular coding IDEs used by developers. It has a simple UI and also the extensions feature makes the coding process a lot easier. Configuring the Odoo development environmentwithin the VS Code is also simple. But we have to do some prerequisites beforethat.

In this blog, I will be discussing the aspects of prerequisites before Configuring Odoo Development Environment with VS Code.

Prerequisites before Configuring Odoo Development Environment with VS Code

Step 1: Let’s install some of the important python packages and libraries which can be done using the following code.

sudo apt-get install -y python3-pip
sudo apt-get install python-dev python3-dev build-essentiallibjpeg-dev libpq-dev libjpeg8-dev libxml2-dev libssl-dev libffi-devlibmysqlclient-dev libxslt1-dev zlib1g-dev libsasl2-dev libldap2-devliblcms2-dev

Next, we have to install some web dependencies.

sudoapt-get install -y npm
sudo ln-s /usr/bin/nodejs/usr/bin/node
sudonpm install -g less less-plugin-clean-css
sudoapt-get install -y node-less

For creating Odoo reports we have to install a package called wkhtmltopdf.

sudo wgethttps://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.5/wkhtmltox_0.12.5-1.bionic_amd64.debsudo dpkg -i wkhtmltox_0.12.5-1.bionic_amd64.debsudo apt install -f

Step 2: Odoo requires a PostgreSQL server to run, So let’s install and configure PostgreSQL.

Run the below command for installing PostgreSQL.

sudo apt-get installpostgresql

After the installation is complete, let’screate a new PostgreSQL user so that we can manage the Odoo databases. First wehave to switch the user to Postgres,

sudo su - postgres

Then, using thefollowing command, we can create a new user ‘odoo14’

createuser --createdb --username postgres--no-createrole --no-superuser --pwprompt odoo14

It will ask for a password in this step, soprovide a password and remember it because we need that in the upcoming steps.

Now we have to make this user that we havecreated as a SUPERUSER which can be done using the following command.

psql
ALTER USER odoo14WITH SUPERUSER;

After all these successful steps, we can exitfrom psql and postgres users.

\q
exit

Step 3: If you have not already, let’s install VS Code.

This can be simply done using the following command,

sudo snap install --classic code

Or you can check this linkfor other downloading options.

Step 4: Let’s download Odoo source files. From the Odoo GitHub repository, we can manually download the files or if git is installed in our system we can directly clone it.

We can clone the Odoo source using the below command. It will create a new directory named ‘odoo’ in the home directory.

git clonehttps://www.github.com/odoo/odoo --depth 1 --branch 14.0 --single-branch odoo

After completing cloning we can install therequired dependencies that are mentioned inside the requirements.txt file. Forthat, we have to enter the ‘odoo’ directory.

cd odoo

Now using pip we can install the dependenciesinside requirements.txt

sudo pip3 install -rrequirements.txt

Sometimes the installation of dependencies maystop from the middle due to errors. We have to make sure that all thesedependencies are successfully installed, otherwise we may face issues whilerunning Odoo.

Step 5: Now that all the prerequisites for the Odoo development environment, we can start configuring Odoo in VS Code.

Installing this python extension will help us to code better and faster, which can be done as depicted in the following image.

configuring-odoo-with-visual-studio-code


Inside the Odoo directory, let’s create a newconfiguration file. For that we need to open the Odoo directory in the VS Code.Goto File > Open Folder > Select the ‘odoo’ directory.

Create a new file ‘odoo.conf’ and paste thefollowing configuration into the conf file.

[options]
; Is This ThePassword That Allows Database Operations:
; admin_passwd =admin
db_host = False
db_port = False
db_user = odoo14
db_password = False
addons_path =/home/user/odoo/addons
xmlrpc_port = 8014

In this configuration, you have to modify the db_password with the password that you gave for the ‘odoo14’ user in step 2. 

You also need to replace the addons_path. In VS Code click on the addons folder and use the Alt + Ctrl + C combination to copy the path. 

Now go Run > Start debugging. This will open ‘launch.json’ where we have to add some configuration details for running Odoo. ( The file will be inside your_odoo_directory/.vscode )

Paste these lines in ‘launch.json’

{
    "version": "0.2.0",
    "configurations": [
       
        {
            "name": "Python:Odoo",
            "type":"python",
            "request":"launch",
            "stopOnEntry": false,
            "python":"${command:python.interpreterPath}",
            "console":"integratedTerminal",
            "program":"${workspaceRoot}/odoo-bin",
            "args": [
               "--config=/home/user/odoo/odoo.conf",
            ],
            "cwd":"${workspaceRoot}",
            "env": {},
            "envFile":"${workspaceRoot}/.env",
            "debugOptions": [
                "RedirectOutput"
            ]
        }
    ]
}

In the args parameter, we have to replace the path ofthe odoo.conf file we created earlier. Save the file and now we can run Odoousing VS Code.



If you need any assistance in odoo, we are online, please chat with us.



1
Comments

Vladimir

Nothing succeeded. Parameter "python":"${???????:python.interpreterPath}" a does not work. The path to Python is correctly processed only through Default Interpreter Path. But even this does not allow you to loaded Odoo in the browser. The process stops without displaying an error.

23/08/2022

-

6:48PM



Leave a comment



whatsapp
location

Calicut

Cybrosys Technologies Pvt. Ltd.
Neospace, Kinfra Techno Park
Kakkancherry, Calicut
Kerala, India - 673635

location

Kochi

Cybrosys Technologies Pvt. Ltd.
1st Floor, Thapasya Building,
Infopark, Kakkanad,
Kochi, India - 682030.

location

Bangalore

Cybrosys Techno Solutions
The Estate, 8th Floor,
Dickenson Road,
Bangalore, India - 560042

Send Us A Message