Debug Odoo Like a Pro with VS Code

Debug Odoo Like a Pro with VS Code

Tired of print() Statements? VS Code Makes Odoo Debugging Effortless

If you’ve ever found yourself drowning in print("HERE") statements while debugging Odoo, you’re not alone. Traditional debugging methods are slow, messy, and inefficient—especially when tracking complex business logic or inheritance chains.

But what if you could:
Pause execution at any line of code?
Inspect variables in real time?
Step through code without restarting Odoo?

With VS Code, Odoo debugging becomes smooth, fast, and intuitive. Let’s set up your environment for professional-grade debugging—no more guesswork!


Why VS Code for Odoo Debugging?

VS Code is a favorite among developers for its:

  • Lightweight performance (no heavy IDEs slowing you down)
  • Rich extensions (Python, Odoo-specific tools, and more)
  • Built-in debugger (breakpoints, variable inspection, call stacks)

Instead of relying on log files or manual prints, you can interactively debug while Odoo runs.


Step 1: Set Up VS Code for Odoo

Prerequisites

  • VS Code installed (Download here)
  • Odoo source code (community/enterprise)
  • Python extension for VS Code

Install Required Extensions

  1. Python (Microsoft) – For debugging support
  2. XML (Red Hat) – Better Odoo view debugging
  3. (Optional) Odoo Snippets – Faster code generation

(Open Extensions with Ctrl+Shift+X and search for these.)


Step 2: Configure the Debugger

Create a launch.json File

  1. Open your Odoo project in VS Code.
  2. Go to the Run and Debug tab (Ctrl+Shift+D).
  3. Click "create a launch.json file" and select Python.

Replace the content with:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Odoo Debug",
            "type": "python",
            "request": "attach",
            "connect": {
                "host": "localhost",
                "port": 5678
            },
            "pathMappings": [
                {
                    "localRoot": "${workspaceFolder}",
                    "remoteRoot": "/path/to/your/odoo"
                }
            ]
        }
    ]
}

(Adjust remoteRoot to your Odoo installation path.)


Step 3: Run Odoo in Debug Mode

Start Odoo with the --debug flag to enable the Python debugger (debugpy):

python3 odoo-bin --debug=5678 --addons-path=addons

(5678 is the default port; match it in launch.json.)


Step 4: Attach the Debugger & Set Breakpoints

  1. Set a breakpoint – Click next to any line number in your Odoo module.
  2. Start debugging – Press F5 or click the green "play" button in the Debug tab.
  3. Trigger the code – Perform an action in Odoo (e.g., button click, CRUD operation).

VS Code will pause execution at your breakpoint, letting you:

  • Inspect variables (hover or check the Variables panel)
  • Step through code (F10 for step over, F11 for step into)
  • Evaluate expressions (Debug Console)

Pro Tips for Faster Debugging

🔹 Use Conditional Breakpoints – Right-click a breakpoint → Set condition (e.g., record.name == "Test").

🔹 Debug QWeb/JS – Use Chrome DevTools + VS Code’s JavaScript debugger.

🔹 Logpoints – Print values without pausing execution (right-click → "Add Logpoint").

🔹 Remote Debugging – Attach to a live Odoo instance on a server.


Conclusion: Ditch print() & Debug Like a Pro

VS Code turns Odoo debugging from a frustrating chore into a streamlined process. With breakpoints, variable inspection, and step-through execution, you’ll find and fix bugs in minutes, not hours.

🚀 Your Turn!

  • Already using VS Code for Odoo? Share your favorite extensions below!
  • Stuck somewhere? Drop a comment—we’ll help debug!

Happy coding! 🛠️

Logging in Odoo: Stop Guessing, Start Tracking!