The Startup
Published in

The Startup

Debugging Odoo

No more print()

Rubber Duck Debugging. Photo by Timothy Dykes on Unsplash

For you that have been work in a computer-related field, certainly feel familiar with debugging term. It is the process of finding where and how bugs ‘accidentally’ created in the system so then we can resolve it. We can use the manual way or the automatic way. For the latter, there are so many tools to do it, usually be distinguished by its programming language base.

In Odoo (that uses Python as its base), there are few tricks we can use.

Odoo Debug

Odoo has provided us a series of tools like: check metadata of a record, view UI (form, list) id, showing field name while hovering until it can show some part of the XML code that responsible for viewing. All of that can be accessed by activating debugging mode. Go to Setting -> Activate the developer mode.

Or we can just type ‘debug’ at the end of the URL like localhost:8069/web?debug

After activating, in the right-top corner, we can see the database that we use and there is a bug logo that shows now. There are a lot of features inside it.

Differences after activating a debugging mode

From this image, we can see that there are testing features, superuser, and etc. But I only use 2 most useful features: View Metadata and Edit View. I use View Metadata when I need to find record id and when its created or updated.

List of features

And I use Edit View when I need to find a model (database name), External id (XML), and I can edit UI (form, tree, or kanban) directly from it. But for a longer period, I suggest you shouldn’t use this method. Instead, inherit its External id, and then write your custom view. How? I write it in my past story.

Example of ‘Edit View’ Feature

The last existing feature I often use is the hovering field. When I do, I can see its name, object, type, context, domain, modifiers, and its relation. Fyi, the field name is the name we used in the column of the object database. And modifiers is its behavior, like when it should how and when it’s not.

Hovering on field

PyCharm Debug

When I code Odoo, I use PyCharm IDE because of its complete pack. I can manage my git from there, I can watch my files, and the last, I can debug and console my code in particular lines of file! So, how can I debug in this IDE? Just click the bug button in the header.

Debug button (third item from left)

Then, for example, I want to debug my create method, so I place my breakpoint (red circle left annotation) in line 495 of stock_picking.py. Trigger it by click Create and Save button in stock picking form.

Breakpoint in stock_picking

When Odoo reads that line, it will pause the program for a moment until you click Resume.

Pause when debugging

When it paused, PyCharm will show this Debug Window and you can inspect the variables that have been computed just before it breaks.

Debug window

Last, I can watch only some variables when they meet my conditions.

Watching variables

The Last

As said of Filipe Fortes on Twitter: “Debugging is like being the detective in a crime movie where you are also the murderer.”

So I suggest you know fully about the code you write first. Or if it is other people’s code, at least you know the flow and then you will know where you should place the breakpoint. Happy debugging! (Although you’re crying inside, lol)

Get smarter at building your thing. Follow to join The Startup’s +8 million monthly readers & +756K followers.

Recommended from Medium

5 Mistakes To Avoid When Choosing a PSD to HTML Service Provider

Autofill Job Locations

Data at Pennylane: what it entails, and how we do it

DP….. 🤔…. Rob….. 💸…..

Cloud-Native Journey Part 1: Defining Goals and Responsibilities

Picture of a light blue sky with clouds

Choosing a node.js database

How to Secure K8S Nginx Ingress With “Let’s Encrypt” and “Cert Manager”

MVC Architecture

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Amirul M.

Amirul M.

Private Odoo Consultant. Reach me on linkedin.com/in/amirulm

More from Medium

Why You Should Learn How to Code — Regardless of Age

Medium Tester Post

The Art Of Programming #1

Python Object Oriented Programming Overview