Skip to content
Home » My Blog Tutorial » Odoo VSCode Ubuntu : Setting Up

Odoo VSCode Ubuntu : Setting Up

install vscode for odoo development

Odoo VSCode Ubuntu : Welcome to this step-by-step guide on setting up Odoo 16 and VSCode (Visual Studio Code) on Ubuntu 23.04. Odoo is an all-in-one business software solution that includes CRM, e-commerce, billing, accounting, manufacturing, warehouse, project management, and inventory management modules, amongst many others. It’s a powerful tool that can be tailored to fit the unique needs of any business, big or small.

The reason

There are numerous reasons to choose Odoo for your business solutions. One of the main reasons is its open-source model, which means it’s constantly updated and improved by a vast community of developers. It’s adaptable and can be customized to fit the specific needs of your business. Additionally, it’s straightforward to use with an intuitive user interface.

VSCode

In terms of a text editor, Visual Studio Code, or VS Code, comes as a highly recommended option. It’s lightweight, open-source, and supports a multitude of programming languages. Its speed and efficiency, combined with its array of useful features such as IntelliSense (a code completion aid), debugging, built-in Git commands, and numerous extensions, make it a favorable choice for developers.

Odoo16

By the end of this tutorial, you’ll have a fully functional Odoo 16 development environment set up on Ubuntu 23.04 using Visual Studio Code. Whether you’re an established developer or just starting, this guide will provide all the necessary steps to get you started.

Ubuntu

We chose Ubuntu 23.04 as the operating system for this guide as it’s the most recent version available, offering the latest updates and security features, minimizing any potential security vulnerabilities. Plus, Ubuntu’s reputation as one of the most user-friendly Linux distributions makes it a great choice for new developers.

Before we dive into the configuration process, make sure you have a fully updated Ubuntu 23.04 system. If you’re using another version of Ubuntu or a different Linux distribution, the commands might differ slightly.

Preparing install Odoo

Step 1: Install Important Python Packages and Libraries

To start Odoo VSCode Ubuntu, let’s install some essential Python packages and libraries.

sudo apt-get update

sudo apt-get upgrade
sudo apt-get install -y python3-pip

sudo apt-get install python3-dev build-essential libjpeg-dev libpq-dev libjpeg8-dev libxml2-dev libssl-dev libffi-dev libmysqlclient-dev libxslt1-dev zlib1g-dev libsasl2-dev libldap2-dev liblcms2-dev

Step 2: Install Web Dependencies

Next, we need to install some web dependencies:

sudo apt-get install -y npm

sudo npm install -g less less-plugin-clean-css

sudo apt-get install -y node-less

Step 3: Install wkhtmltopdf for Odoo Reports

Odoo uses a package called ‘wkhtmltopdf’ to create reports. Before installing ‘wkhtmltopdf’, we need to add the appropriate source for Ubuntu 20.04 and install some required packages

echo "deb http://security.ubuntu.com/ubuntu focal-security main" | sudo tee /etc/apt/sources.list.d/focal-security.list

sudo apt-get update

sudo apt-get install libssl1.1 xfonts-75dpi

We need to install this package using the following commands:

sudo wget https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.5/wkhtmltox_0.12.5-1.bionic_amd64.deb

sudo dpkg -i wkhtmltox_0.12.5-1.bionic_amd64.deb

sudo apt install -f

With this, we’ve finished setting up the prerequisites. In the following sections, we’ll delve into setting up the Odoo environment and integrating it with VS Code.

Always remember to check the official documentation of each package or software you are installing to resolve any potential installation issues.

Step 4: Install PostgreSQL and Create a Database User Role

The next step is to install PostgreSQL, a powerful, open-source object-relational database system. Odoo uses PostgreSQL as its database back-end. Use the following command to install it:

sudo apt-get install postgresql

Once the installation is complete, we need to create a database user role for handling Odoo databases. To do this, switch to the ‘postgres’ user and create a new user (in this case, we’re creating a user named ‘odoo16’):

sudo su - postgres

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

During this step, you will be enter a password. For this example, we’ll use ‘odoo16’ as the password. Please remember it, as you’ll need it in the subsequent steps.

Next, we need to give our new user ‘superuser’ privileges. Access the PostgreSQL command prompt by typing psql, and then use the following command to alter the user:

psql
ALTER USER odoo16 WITH SUPERUSER;

Now, you can exit from the PostgreSQL command prompt and the ‘postgres’ user with the following commands:

\q 
exit

With this, PostgreSQL is set up and ready to go for our Odoo installation. In the next steps, we’ll move onto downloading and configuring Odoo.

Installing Odoo

Step 1: Install VSCode for odoo on ubuntu

If you haven’t already installed VSCode on Ubuntu for odoo, now is the time to do so. Visual Studio Code is a lightweight but powerful source code editor which runs on your desktop. It’s available for Windows, macOS, and Linux. It comes with built-in support for JavaScript, TypeScript, and Node.js, and has a rich ecosystem of extensions for other languages.

You can check this link for other download options based on your operating system.

However, for Ubuntu users, you can easily install it using the following command:

sudo snap install --classic code

With Visual Studio Code installed, we can proceed with setting up our Odoo development environment.

Step 2: Download Odoo 16 Source Code

Next, we need to download the source code for Odoo 16. You can download the Community Source Code for Odoo 16 directly from the Odoo Github repository.

Alternatively, you can clone it from Github using git. If you haven’t already installed git, you can do so with the following command:

sudo apt-get install git

Once git is installed, you can clone the Odoo 16 repository with this command:

git clone https://github.com/odoo/odoo.git --depth 1 --branch 16.0 --single-branch odoo16

Step 3: Install Python Packages Required by Odoo

Odoo requires some Python packages to function, which are listed in the requirements.txt file inside the Odoo directory.

Before installing the required Python packages, it is recommended to create an isolated environment using virtualenv and place it inside the project folder. The project folder will be named “odoo16-vs” and created in the home directory. Here are the steps to accomplish this on Ubuntu:

Create the project folder:

mkdir odoo16-vs

cd odoo16-vs

Install virtualenv:

sudo apt-get install python3-pip

sudo apt-get install python3-virtualenv

Once virtualenv is installed, create and activate the virtual environment:

python3 -m venv .venv

source .venv/bin/activate

After activating the virtual environment, you can proceed to install the Python packages by executing the following command:

sudo pip3 install -r requirements.txt

Alternatively, if the requirements.txt file is located inside the Odoo directory, you can use the following command:

sudo pip3 install -r <path to inside odoo directory>/requirements.txt

For example, if the requirements.txt file is located at “~/odoo16/requirements.txt”, the command will be:

sudo pip3 install -r ~/odoo16/requirements.txt

Step 4: Build Odoo binary

Next in odoo vscode on ubuntu, we will create an Odoo binary that can be executed through the virtual environment. This step is explained in detail on the following GitHub repository: https://github.com/acsone/setuptools-odoo. The easiest way to accomplish this is by following these instructions:

Change to the Odoo directory:

cd ~/odoo16

Install the necessary packages using pip:

(venv) $ python3 -m pip install --upgrade pip wheel

Add library the requirements specified in the Odoo directory:

(venv) $ python3 -m pip install -r ./odoo/requirements.txt

Install Odoo in editable mode:

(venv) $ python3 -m pip install -e ./odoo

By following these steps, you will create a binary for Odoo that can be executed within the virtual environment. This will allow you to run and manage your Odoo instance smoothly.

Step 5: Set up Odoo Development Environment in Visual Studio Code

Once Odoo VSCode Ubuntu you have fulfilled the requirements for the Odoo development environment, you can proceed with configuring Odoo in Visual Studio Code. By installing extensions like Python, PyLance, and other tools, you can enhance your coding experience and increase productivity. Follow the steps below to install the required extensions:

  1. Open Visual Studio Code.
  2. Navigate to the Extensions sidebar by clicking on the square icon on the left sidebar or by using the shortcut Ctrl+Shift+X.
  3. In the search bar of the Extensions sidebar, type “Python” and select the Python extension by Microsoft.
  4. Click on the “Install” button to install the Python extension.
  5. After the installation is complete, search for “PyLance” in the Extensions sidebar and select the PyLance extension.
  6. Click on the “Install” button to install the PyLance extension.
  7. Additionally, you may install other tools or extensions that suit your development needs and preferences.
  8. Once the installation is finished, you can begin configuring your Odoo project in Visual Studio Code.

By setting up Odoo in Visual Studio Code and installing the necessary extensions, you will have a powerful development environment that enables efficient coding and enhances your productivity.

You can refer to the image below to see some additional extensions that you can install

add .env folder

Next, we need to select the Python interpreter for our project, which will be located in the .env folder. To do this in Visual Studio Code, follow these steps:

  1. Open Visual Studio Code.
  2. Press Ctrl+Shift+P to open the Command Palette.
  3. In the Command Palette, type “Select Interpreter” and select the option “Python: Select Interpreter”.
  4. A list of available Python interpreters will be displayed.
  5. Navigate to the .env folder located in your Odoo project directory (e.g., odoo16-vs).
  6. Select the Python interpreter within the .env folder to associate it with your project.

By selecting the Python interpreter from the .env folder, you ensure that your project uses the correct Python environment and dependencies. This step is crucial for the successful execution of your Odoo development environment in Visual Studio Code.

Step 6: VSCode Project Folder

To open your odoo16-vs project folder in Visual Studio Code, follow these steps:

  1. Select “File” from the menu bar.
  2. Choose “Open Folder” and navigate to your odoo16-vs project folder.
  3. Select the folder and click “Open” to open it in Visual Studio Code.

By opening your project folder in Visual Studio Code, you can easily access and manage your Odoo development files within the editor.

Odoo.conf

Create the odoo.conf File inside the Odoo16 Directory. While inside the Odoo16 project directory, follow these steps to create the odoo.conf file:

  1. Select “File” from the menu bar.
  2. Choose “New File” and name it “odoo.conf”.
  3. Press Enter to create the file.

Next, you need to add the necessary configuration details to the odoo.conf file. Use the following block as a template, but make sure to modify the db_password and addons_path according to your specific setup:

[options]
admin_passwd = admin
db_host = localhost
db_port = 5432
db_user = odoo16
db_password = False
addons_path =  ~/odoo16-vs/addons, ~/odoo16-vs/customize
xmlrpc_port = 8016

In this configuration, replace the db_password with the password you set for the database user odoo16 in the previous step. Also, update the addons_path value with the actual path to the addons directory inside your Odoo16 project.

Next, let’s create a symbolic link to the Odoo addons directory and create a folder for Odoo customization, such as “customize”. Follow these steps:

  1. Open the integrated terminal in Visual Studio Code. You can do this by pressing Ctrl+` (backtick).
  2. In the terminal, execute the following command to create a symbolic link to the Odoo addons directory:
ln -s ~/odoo16/addons addons

This command creates a symbolic link named “addons” that points to the actual addons directory in your Odoo16 project.

  1. To create a folder for Odoo customization, run the following command in the terminal:
mkdir customize

This command creates a folder named “customize” within your project directory. You can use this folder to store any custom modules or customizations specific to your Odoo project.

create launch.json

By using the terminal provided by Visual Studio Code, you can conveniently execute these commands to create the symbolic link and customization folder within your Odoo project.

Configure launch.json for Visual Studio Code. To configure the launch.json file for running Odoo in Visual Studio Code, follow these steps:

  1. Go to the “Run” menu.
  2. Select “Add Configuration” and choose “Node.js”. This will open the launch.json file.
  3. Clear the existing code inside the launch.json file.
  4. Replace the contents of launch.json with the following configuration:
{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "odoo 16",
      "type": "python",
      "request": "launch",
      "console": "integratedTerminal",
      "justMyCode": false,
      "env": {},
      "cwd": "${workspaceRoot}",
      "envFile": "${workspaceRoot}/.env",
      "stopOnEntry": false,
      "program": ".env/bin/odoo",
      "args": ["--config=/home/user/odoo16-vs/odoo.conf"]
    }
  ]
}

In the “program” parameter, specify the path to the Odoo-bin file inside your Odoo16 project.

In the “–config” parameter, provide the path to the odoo.conf file, which contains the configuration settings.

Once you have saved the launch.json file, you can run Odoo using Visual Studio Code.

By following these steps, you will be able to set up your development environment in Visual Studio Code and configure it for running and debugging your Odoo16 project.

Step 7 : Running Odoo

After completing the previous steps, you can run Odoo through Visual Studio Code by using the Run > Debugging feature. Here’s how you can do it:

  1. Make sure you have your Odoo project open in Visual Studio Code.
  2. Go to the Run menu and select the “Start Debugging” option, or you can use the shortcut F5.
  3. Visual Studio Code will start the debugging process and run Odoo using the configured launch settings.
  4. The integrated terminal in Visual Studio Code will display the Odoo server output and any debug information.
  5. You can interact with your Odoo instance through the browser by navigating to the specified URL (usually http://localhost:8069) in your preferred web browser.

By running Odoo through Visual Studio Code’s debugging feature, you can easily monitor the server’s output and debug any issues that may arise during development. This streamlined workflow allows you to efficiently develop and test your Odoo project within the Visual Studio Code environment.

Debugging Odoo in Visual Studio Code: Key Articles

Several articles provide valuable insights on debugging Odoo using Visual Studio Code. These resources typically guide you through setting up your development environment, configuring the launch.json file, and utilizing VS Code’s debugging features. Some articles also delve into advanced techniques, such as remote debugging and performance optimization. By following these guides, developers can streamline their debugging process, making it easier to identify and resolve issues in their Odoo applications.


Discover more from teguhteja.id

Subscribe to get the latest posts sent to your email.

1 thought on “Odoo VSCode Ubuntu : Setting Up”

  1. Pingback: Odoo module development guide - teguhteja.id

Leave a Reply

Optimized by Optimole
WP Twitter Auto Publish Powered By : XYZScripts.com

Discover more from teguhteja.id

Subscribe now to keep reading and get access to the full archive.

Continue reading