Skip to content

Unleash Productivity: Your Ultimate Guide to Odoo Development Environment Setup

odoo development environment

Are you frustrated with Odoo development, finding your environment cluttered, debugging a nightmare, and struggling to manage multiple client projects? If so, you’re not alone. Many developers face these challenges. But what if you could streamline your Odoo Development Environment Setup to boost efficiency, ensure maintainability, and accelerate your coding like never before?

This comprehensive guide, inspired by the insights shared in this valuable session (based on the content from https://www.youtube.com/watch?v=vqCl9uCzVo), will walk you through setting up a robust, organized, and replicable Odoo development environment using Python virtual environments on Linux. We’ll cover everything from tool preparation to advanced repository management, ensuring you have a clean, powerful workspace.

Our goal isn’t just to help you set up a local environment; it’s to transmit practical experience, enabling you to manage your Odoo development cycle with unparalleled organization and scalability.

Here’s what we’ll cover in detail:

  1. Preparing Your Essential Development Tools
  2. Acquiring Odoo Source Code and Essential Dependencies
  3. Setting Up a PostgreSQL Database with Docker for Odoo Development
  4. Strategizing Your Odoo Development Environment Setup Structure
  5. Configuring Visual Studio Code for Seamless Odoo Development
  6. Mastering Debugging Techniques in Your Odoo Environment
  7. Advanced Strategies for Managing Multiple Odoo Developments Across Clients

Let’s dive in and transform your Odoo development experience!


Step 1: Preparing Your Essential Development Tools

A solid foundation begins with the right tools. For a powerful Odoo Development Environment Setup, we’ll leverage several key technologies. Each plays a crucial role in ensuring isolation, efficiency, and a smooth workflow.

1.1 Python 3.10+ and Virtualenv

Odoo is primarily built with Python, making it the cornerstone of your development environment. We’ll use virtualenv to create isolated Python environments for each Odoo project. This prevents dependency conflicts between different Odoo versions or other Python projects you might be working on.

Installation Commands:

# Update package list
sudo apt update
sudo apt install software-properties-common

# Add deadsnakes PPA for newer Python versions
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt update

# Install Python 3.11 (or your preferred compatible version)
sudo apt install python3.11

# Verify Python installation
python3.11 --version

# Install pip for Python 3
sudo apt install python3-pip

# Install virtualenv
pip3 install virtualenv

Why this matters: Odoo 18, for instance, requires Python 3.10 or higher. Using a virtual environment ensures that all Odoo-specific libraries and dependencies are contained within your project, avoiding system-wide clutter and potential conflicts.

1.2 Visual Studio Code (VS Code)

VS Code is a highly popular and versatile integrated development environment (IDE) that offers excellent support for Python development, including rich extensions for Odoo. Its features like autocompletion, debugging, and integrated terminal make it indispensable for an efficient Odoo Development Environment Setup.

Installation:

sudo dpkg -i <name_of_the_deb_package>.deb
  • If you encounter dependency issues, run sudo apt install -f to fix them.

1.3 Docker and Docker Compose

Docker simplifies database management significantly by allowing you to run PostgreSQL (Odoo’s default database) in isolated containers. Docker Compose further simplifies this by letting you define and run multi-container Docker applications with a single command. This avoids complex local PostgreSQL installations and ensures your database environment is portable and reproducible.

Installation:

  • Follow the comprehensive instructions on the official Docker website for your specific Linux distribution (e.g., Ubuntu, Debian, CentOS). The steps involve adding Docker’s official GPG key, setting up the repository, and then installing Docker Engine and Docker Compose.

1.4 Git

Git is an essential version control system for managing your source code changes. It’s crucial for collaboration, tracking modifications, and rolling back to previous versions.

Installation:

  • Most Linux distributions come with Git pre-installed. You can check by typing git --version.
  • If not installed, use your package manager:
sudo apt install git

Step 2: Acquiring Odoo Source Code and Essential Dependencies

With our tools ready, the next step in establishing a robust Odoo Development Environment Setup is to acquire the necessary Odoo source code.

2.1 Odoo Community Edition

Odoo Community is the free and open-source version of Odoo. It forms the core framework upon which all Odoo applications are built.

Download:

  • You’ll typically clone the Odoo Community repository from GitHub. We’ll specify the version (e.g., 18.0) to avoid downloading the entire history, saving time and space.

2.2 Odoo Enterprise Edition (Optional)

Odoo Enterprise provides additional features and modules beyond the Community edition. Accessing its source code usually requires an official Odoo partnership or a paid subscription (like a Custom Plan with an annual user license).

Access:

  • If you have a subscription, you can access the Enterprise code from the Odoo customer portal. For the purpose of setting up your development environment, it’s not strictly necessary, but it’s good to know how to include it if your projects require it.

2.3 Odoo Stubs for Autocompletion

Odoo Stubs is a vital repository for enhancing your developer experience, especially when using an IDE like VS Code. It provides type hinting information that enables intelligent autocompletion, better error detection, and direct navigation to Odoo’s core methods and definitions. This significantly speeds up coding and debugging.

Download:

  • Clone the Odoo Stubs repository, again specifying the Odoo version you’re working with:
git clone https://github.com/odoo/odoo_stubs -b 18.0 odoo_stubs

Step 3: Setting Up a PostgreSQL Database with Docker for Odoo Development

A well-configured database is central to any Odoo Development Environment Setup. Using Docker for PostgreSQL offers unparalleled convenience and isolation.

3.1 Create Database Directory

First, create a dedicated directory for your PostgreSQL setup. This helps keep your project organized.

mkdir odoo-dev/postgres_db
cd odoo-dev/postgres_db

3.2 Define Your PostgreSQL Service with docker-compose.yml

Create a docker-compose.yml file in the odoo-dev/postgres_db directory. This file will define your PostgreSQL service, specifying the image, container name, environment variables (username, password, database name), port mapping, and a volume for data persistence. Data persistence is critical because Docker containers are ephemeral, meaning data inside them is lost when the container is removed unless explicitly saved to a volume.

version: "3"
services:
  odoodb:
    image: postgres:15 # Using PostgreSQL 15 for compatibility and latest features
    container_name: postgres_db1 # A unique name for your database container
    environment:
      POSTGRES_USER: odoo          # Database username for Odoo
      POSTGRES_PASSWORD: odoo      # Database password for Odoo (use strong passwords for production!)
      POSTGRES_DB: odoo            # Default database name
    ports:
      - "5432:5432"                # Map host port 5432 to container port 5432
    volumes:
      - db_data:/var/lib/postgresql/data # Persistent volume for database data
    shm_size: '256m'               # Allocate shared memory for PostgreSQL
volumes:
  db_data:                         # Define the named volume

Important Security Note: The POSTGRES_PASSWORD used here (“odoo”) is for local development only. Never use such a weak password in a production environment.

3.3 Launch and Verify Your Database Container

Navigate to your odoo-dev/postgres_db directory in the terminal and run Docker Compose:

docker compose up -d

The -d flag runs the container in detached mode, allowing it to run in the background.

Verify it’s Running:

docker ps

You should see postgres_db1 listed with a “healthy” or “running” status. You can also view logs for debugging:

docker compose logs odoodb

Your PostgreSQL database is now ready to serve your Odoo instances, providing a clean and isolated data environment within your Odoo Development Environment Setup.


Step 4: Strategizing Your Odoo Development Environment Setup Structure

An organized directory structure is paramount for managing multiple Odoo projects, custom modules, and ensuring long-term maintainability. This structure prevents module duplication and simplifies project switching.

Recommended Directory Structure:

odoo-dev/
├── config/        # Stores Odoo configuration files (`.conf` files for different clients/projects)
├── data/          # Where Odoo stores filestore data (attachments, images) and session files
├── odoo/          # The core Odoo Community source code (cloned from GitHub)
├── enterprise/    # (Optional) Odoo Enterprise source code, if you have access
├── odoo_stubs/    # Odoo Stubs repository for IDE autocompletion
├── src/           # Your central hub for custom modules and external (OCA) repositories
│   ├── client_a_modules/ # Custom modules for Client A
│   ├── client_b_modules/ # Custom modules for Client B
│   ├── l10n_base/        # Localization modules (e.g., l10n_pe for Peru)
│   └── oca_modules/      # Cloned OCA repositories (e.g., 'brand' from OCA/stock-logistics-workflow)
└── venv/          # Your Python virtual environment, keeping dependencies isolated

Steps to Create This Structure:

  1. Create the Main odoo-dev Directory:

    mkdir odoo-dev
    cd odoo-dev
    
  2. Create Subdirectories:

    mkdir config data enterprise src
    

    *Note: odoo/, odoo_stubs/, and venv/ will be populated in subsequent steps via cloning or virtualenv commands.*

  3. Clone Odoo Community (into odoo/):

    • Navigate into the odoo-dev directory.
    • Clone the Odoo repository for version 18.0. The --depth 1 and --branch flags ensure you only download the specific branch, saving significant space and time.
    git clone --depth 1 --branch 18.0 https://github.com/odoo/odoo.git odoo
    

    This command creates the odoo/ directory and populates it.

  4. Clone Odoo Stubs (into odoo_stubs/):

    • Still in odoo-dev:
    git clone --depth 1 --branch 18.0 https://github.com/odoo/odoo_stubs.git odoo_stubs
    

    This creates the odoo_stubs/ directory.

By adhering to this structure, you create a scalable Odoo Development Environment Setup that gracefully handles multiple projects and dependencies, minimizing chaos and maximizing efficiency.


Step 5: Configuring Visual Studio Code for Seamless Odoo Development

Visual Studio Code, when properly configured, transforms into an incredibly powerful IDE for your Odoo Development Environment Setup. This involves setting up the Python interpreter, installing Odoo’s dependencies, and ensuring all necessary system libraries are in place.

5.1 Create and Activate Virtual Environment

Within your odoo-dev directory, create your Python virtual environment. This isolates Odoo’s dependencies from your system-wide Python installations.

python3.11 -m venv venv

Once created, VS Code should automatically detect this local venv and prompt you to select it as the interpreter for your workspace. If not, you can manually select it:

  • Press Ctrl+Shift+P (Cmd+Shift+P on macOS).
  • Type “Python: Select Interpreter” and choose the venv interpreter located within your odoo-dev directory (e.g., odoo-dev/venv/bin/python).

5.2 Install Odoo Dependencies

Odoo has a list of Python packages it requires to run, defined in its requirements.txt file. You need to install these into your newly created virtual environment.

cd odoo-dev/odoo # Navigate into the cloned Odoo directory
pip install -r requirements.txt # Use pip, as it's within the activated virtual environment
cd ../ # Go back to the odoo-dev root

5.3 Install System-Level Development Dependencies

Sometimes, Python packages have underlying system dependencies. If pip install -r requirements.txt fails, it’s often due to missing development headers or libraries on your operating system. For Odoo, common ones include libpq-dev (for PostgreSQL client libraries) and python3.11-dev (for Python development headers needed to compile certain packages).

sudo apt install libpq-dev
sudo apt install python3.11-dev

5.4 Update Python Packaging Tools

Ensure your pip, setuptools, and wheel packages are up-to-date within your virtual environment. This prevents common installation issues.

pip install --upgrade pip setuptools wheel

After installing system dependencies and updating tools, try pip install -r requirements.txt again if it failed previously.

5.5 Configure odoo.conf

The odoo.conf file is Odoo’s primary configuration file. It tells Odoo where to find modules, how to connect to the database, and other operational parameters.

  1. Create odoo.conf: Inside your odoo-dev/config/ directory, create a new file named odoo.conf.

  2. Add Configuration: Populate it with essential settings.

[options]
; Specify paths where Odoo should look for modules
addons_path = /path/to/odoo-dev/odoo/addons,/path/to/odoo-dev/odoo_stubs,/path/to/odoo-dev/src/your_custom_modules

; Database connection details (referencing your Docker PostgreSQL container)
db_host = postgres_db1 ; Use the container_name defined in docker-compose.yml
db_port = 5432
db_user = odoo
db_password = odoo

; Directory for Odoo to store filestore data and sessions
data_dir = /path/to/odoo-dev/data

; Admin password for database operations (e.g., creating/duplicating databases)
admin_passwd = admin

; Port for Odoo web interface
http_port = 8069

; Increase timeout limits to prevent issues during heavy operations or debugging
limit_time_cpu = 999999
limit_time_real = 999999

; Logging configuration (optional, for development debugging)
; log_level = debug
; log_handler = :INFO
; logfile = /path/to/odoo-dev/odoo.log

Remember to replace /path/to/odoo-dev/ with the actual absolute path to your odoo-dev directory. This detailed odoo.conf is crucial for your Odoo Development Environment Setup to correctly locate resources and connect to your database.


Step 6: Mastering Debugging Techniques in Your Odoo Environment

Effective debugging is a cornerstone of efficient Odoo development. Visual Studio Code provides powerful debugging capabilities that, when properly configured, allow you to step through your Odoo code, inspect variables, and pinpoint issues with precision. This step is critical for refining your Odoo Development Environment Setup.

6.1 Install pydevd

pydevd is the Python debugger that VS Code uses. Install it in your virtual environment:

pip install pydevd

6.2 Configure .vscode/launch.json

This file tells VS Code how to run and debug your Odoo application.

  1. Create launch.json: In the root of your odoo-dev directory, create a folder named .vscode (if it doesn’t exist) and inside it, create a file named launch.json.

  2. Add Configuration: Add the following configuration to launch.json. This setup tells VS Code to execute odoo-bin with your specified configuration file.

    {
      "version": "0.2.0",
      "configurations": [
        {
          "name": "Odoo Debug",                  // Name of the debug configuration
          "type": "python",                     // Type of debugger
          "request": "launch",                  // Launch a new process
          "program": "${workspaceFolder}/odoo/odoo-bin", // Path to odoo-bin
          "args": [
            "-c", "${workspaceFolder}/config/odoo.conf", // Path to your Odoo configuration file
            "--addons-path", "${workspaceFolder}/odoo/addons,${workspaceFolder}/odoo_stubs,${workspaceFolder}/src" // Define addons path dynamically
            // "--db-filter", "your_database_name" // Uncomment and specify if you want to always open a specific database
            // "-d", "your_database_name" // Uncomment and specify default database for Odoo to load
            // "--update", "your_module_name" // Uncomment to update specific modules on start
          ],
          "console": "integratedTerminal",      // Output to VS Code's integrated terminal
          "justMyCode": false,                  // Set to false to debug into Odoo's core modules
          "env": {
            "PYTHONUNBUFFERED": "1"             // Ensure immediate output for debugging
          }
        }
      ]
    }
    

    Explanation of Key Parameters:

    • program: Points to odoo-bin, the executable for Odoo.
    • args: Passes command-line arguments to odoo-bin, including your odoo.conf file and the addons_path. Using ${workspaceFolder} makes the path dynamic and portable.
    • justMyCode: false: Crucial for Odoo development. This allows the debugger to step into Odoo’s core files, not just your custom code. This is invaluable for understanding Odoo’s internal behavior.
    • db-filter / -d / --update: Optional arguments you can uncomment and customize for specific debugging scenarios (e.g., always loading a particular database, auto-updating a module).

6.3 Using the Debugger

  1. Set Breakpoints: Click in the gutter (left margin) of your Python code next to a line number to set a red dot, indicating a breakpoint.

  2. Start Debugging: Go to the “Run and Debug” view in VS Code (Ctrl+Shift+D), select “Odoo Debug” from the dropdown, and click the green “Play” button (F5).

  3. Interact with Odoo: When your code execution hits a breakpoint, VS Code will pause. You can then:

    • Step Over (F10): Execute the current line and move to the next.
    • Step Into (F11): Enter a function call on the current line.
    • Step Out (Shift+F11): Finish the current function and return to the caller.
    • Continue (F5): Resume execution until the next breakpoint or program end.
    • Inspect Variables: The “Variables” pane will show the current values of all variables in scope. You can also hover over variables in the code.
    • Watch Expressions: Add variables or expressions to the “Watch” pane to monitor their values continuously.
    • Debug Console: Execute Python code in the “Debug Console” in the current context.

This powerful debugging setup within your Odoo Development Environment Setup will dramatically improve your ability to identify and resolve issues, understand Odoo’s framework, and build more robust applications.


Step 7: Advanced Strategies for Managing Multiple Odoo Developments Across Clients

As your Odoo development journey progresses, you’ll inevitably manage multiple client projects, each with unique requirements and module sets. A disorganized approach can quickly lead to module duplication, conflicting configurations, and maintenance headaches. This final step is key to a truly scalable and efficient Odoo Development Environment Setup.

7.1 One odoo.conf Per Client/Project

Avoid using a single odoo.conf for all your projects. Instead, create a dedicated configuration file for each client or major project within your odoo-dev/config/ directory. This allows for specific addons_path definitions, different database connections, and unique http_port assignments, preventing conflicts when running multiple instances.

Example:

  • config/farma.conf
  • config/constructora.conf
  • config/dev.conf (for general testing/development)

Benefits:

  • Isolation: Each client’s setup is self-contained.
  • Port Management: Easily run different Odoo instances on distinct ports (e.g., Farma on 8001, Constructora on 8005).
  • Targeted Module Loading: The addons_path in each .conf file will only point to the modules relevant for that client.

7.2 Organized Repositories within src/

Your odoo-dev/src/ directory should be the central hub for all your custom and external modules. This is where the magic of organization truly shines. Instead of dumping all modules into one large folder, categorize them logically:

  • src/client_name_modules/: A dedicated Git repository for modules developed specifically for a particular client. This ensures client-specific customizations are isolated and version-controlled independently.

    • Example: src/ferreteria_sac/, src/pharma_co/
  • src/l10n_base/: A repository for country-specific localization modules (e.g., l10n_pe for Peru, l10n_mx for Mexico). These modules often contain common features applicable to multiple clients in the same region.

    • Example: src/l10n_pe/
  • src/oca_modules/: Clone repositories from the Odoo Community Association (OCA) GitHub here. The OCA organizes modules by functionality (e.g., account-invoicing, stock-logistics-workflow, web). This approach promotes reusability and adherence to community standards.

    • Example: src/oca_account_invoicing/ (clone of https://github.com/OCA/account-invoicing)

Why this matters:

  • No Module Duplication: Avoid copying the same localization or common utility module across multiple client repositories. Instead, reference it from its single source within src/.
  • Clear Ownership: It’s immediately clear which modules belong to which client or serve a general purpose.
  • Simplified Updates: Update common modules (like OCA or localization) once in their respective repositories.
  • Better Collaboration: Teams can work on specific client modules without interfering with others.

7.3 Adapting launch.json for Multiple Clients

Your .vscode/launch.json can be extended to quickly launch Odoo for different clients or configurations. Simply duplicate your existing configuration and adjust the name and args parameters:

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Odoo Dev (General)",
      "type": "python",
      "request": "launch",
      "program": "${workspaceFolder}/odoo/odoo-bin",
      "args": [
        "-c", "${workspaceFolder}/config/dev.conf",
        "--addons-path", "${workspaceFolder}/odoo/addons,${workspaceFolder}/odoo_stubs,${workspaceFolder}/src/client_a_modules,${workspaceFolder}/src/l10n_base,${workspaceFolder}/src/oca_modules",
        "--http-port", "8069"
      ],
      "console": "integratedTerminal",
      "justMyCode": false
    },
    {
      "name": "Odoo Farma Project",
      "type": "python",
      "request": "launch",
      "program": "${workspaceFolder}/odoo/odoo-bin",
      "args": [
        "-c", "${workspaceFolder}/config/farma.conf",
        "--addons-path", "${workspaceFolder}/odoo/addons,${workspaceFolder}/odoo_stubs,${workspaceFolder}/src/farma_co_modules,${workspaceFolder}/src/l10n_base",
        "--http-port", "8001",
        "-d", "farma_20240620" // Automatically open specific database
      ],
      "console": "integratedTerminal",
      "justMyCode": false
    },
    {
      "name": "Odoo Constructora Project",
      "type": "python",
      "request": "launch",
      "program": "${workspaceFolder}/odoo/odoo-bin",
      "args": [
        "-c", "${workspaceFolder}/config/constructora.conf",
        "--addons-path", "${workspaceFolder}/odoo/addons,${workspaceFolder}/odoo_stubs,${workspaceFolder}/src/constructora_modules,${workspaceFolder}/src/l10n_base",
        "--http-port", "8005",
        "-d", "constructora_20240615"
      ],
      "console": "integratedTerminal",
      "justMyCode": false
    }
  ]
}

With this setup, you can easily switch between projects directly from the VS Code “Run and Debug” view without manually changing configurations or command-line arguments. This is a powerful addition to your Odoo Development Environment Setup.

7.4 Managing Database Backups and Restorations

When working with client projects, you often need to replicate their production or staging databases locally for development and testing.

Best Practices:

  • Neutralize Backups: Before restoring a client’s database locally, ensure it’s “neutralized.” This means disabling outbound email, payment gateways, and other external integrations to prevent accidental actions from your development environment.
  • Naming Convention: Use clear naming conventions for your local databases, often including the client name and the date of the backup (e.g., client_name_YYYYMMDD).
  • Temporary Restorations: Restore backups for specific development tasks. Once the task is complete, consider removing the database to free up space.

By implementing these advanced strategies, your Odoo Development Environment Setup transforms from a basic coding space into a highly organized, efficient, and scalable platform capable of handling complex multi-client Odoo projects. This ensures your productivity remains high and your code remains clean and maintainable.


Conclusion: Empowering Your Odoo Development Journey

Congratulations! You’ve just walked through the comprehensive process of establishing a powerful, organized, and debug-ready Odoo Development Environment Setup on Linux. From preparing essential tools like Python and Docker, to strategically organizing your Odoo source code and custom modules, and finally, leveraging Visual Studio Code for seamless development and debugging, you now possess the knowledge to build and manage Odoo projects with unprecedented efficiency.

This detailed guide emphasizes not just setting up a functional environment, but doing so with best practices that ensure long-term maintainability and scalability for all your Odoo endeavors. By adopting a structured approach to your Odoo Development Environment Setup, you’ll reduce common frustrations, accelerate your coding workflow, and deliver higher-quality solutions.

The journey into Odoo development is continuous, and having a robust Odoo Development Environment Setup is your most valuable asset. Now that your environment is primed, you are truly ready to dive into coding and unlock Odoo’s full potential.

Stay tuned for future sessions where we’ll explore advanced Odoo coding practices and module development. Happy coding!


Discover more from teguhteja.id

Subscribe to get the latest posts sent to your email.

Leave a Reply

WP Twitter Auto Publish Powered By : XYZScripts.com