Odoo Development Essentials, Article #1: Introduction to Odoo Development Using the Developer Mode

March 6, 2022
20 min read
Odoo Development Essentials, Article #1: Introduction to Odoo Development Using the Developer Mode

The first of four installments on using the Odoo developer mode

Odoo 15 Development Essentials, Fifth Editionis now available. As a gesture of celebration, the first chapter of the book, “Introduction to Odoo Development using the Developer Mode,” is being reconfigured into a series of four articles, made available here on the Open Source Integrators site. Enjoy!

Odoo 15 Development Essentials

Introduced in this article:

  • Using the developer mode for the Odoo to-do app project
  • Basic Odoo development concepts
  • How to enable the Odoo developer tools

Sharpening Odoo development expertise

Conducting business at the pace and complexity of today’s world often comes with some amount of logistical strain across the gamut of your operations. From sales and marketing to services and manufacturing, an inability to mold your business software according to your needs can have drastic effects on how your organization gets work done.

Odoo is able to relieve some of this strain by providing a rapid application framework well-suited for building approachable and efficient business applications. Odoo’s business drive includes special focus on helping you keep track of business records and enhance visibility throughout workflows, with rich components to create compelling user interfaces (UI) such as kanban boards, calendars, and graph views for an optimized user experience.

 

We’re publishing this series of four articles based on content from Odoo 15 Development Essentials in order to explore Odoo internals from the web UI, giving you a hands-on understanding of Odoo app components and tools while using the developer mode (sometimes referred to as the debug mode). As a teaching tool, the developer mode features act as a way to introduce how the application configuration data is organized in the Odoo framework, and how the developer mode can be leveraged for simple customizations or prototyping solutions.

Implementing a simple to-do app in Odoo

So, with that in mind, we’d like to cater to your convenience by including you in a project aimed at demonstrating developer mode directly. For the span of these four articles, we’ve put together an interactive project to help you get acquainted with Odoo development: Implementing a simple to-do list app in Odoo.

All you need is an Odoo database to get started. Using either a self-hosted instance of Odoo or an Odoo Online instance at odoo.com, we’ll begin digging into the to-do list project and related Odoo practices.

Ready? Let’s go.

Introducing the to-do app project and Odoo architecture

Starting our Odoo to-do app project

The to-do list project works as the bedrock for illustrating Odoo concepts as each article demonstrates various developer mode techniques. And yes, the project is as sweet and simple as it sounds: We’re going to build a to-do app in Odoo.

One point of focus here will be to enable adding new to-do items to the list and mark them as complete. For example, add a Buy Eggs item to the list and check the Is Done? box when complete. Additionally, we’ll make the to-do items private to each user, meaning that the current owner of the to-list is able to only access their own to-do items. Then, to throw some spice to the project, we’ll get to work incorporating a list of people involved with the task, i.e., a Work Team.

But first, we need to start thinking about the layers involved in our application.

Odoo architecture: 3 essential application tiers

 

Before doubling back to the to-do project, let’s quickly move through a pragmatic overview of the layers involved in Odoo architecture and the role of each component we’ll use.

 

Odoo applications can be divided into three tiers:

DataLogic, and Presentation
Odoo applications tiers

Data tier

At the lowest level, the data tier is responsible for data storage and persistence. Odoo relies on a PostgreSQL server for this. Note that PostgreSQL is the only supported database server for Odoo—a design choice made over the database backend. Binary files, such as attachments of documents or images, are stored in the filesystem in a directory referred to as the filestore. This means that a full backup of an Odoo instance needs both a database dump and a copy of the filestore.

While we will rarely use SQL to interact directly with the database engine, it’s important to note that it is possible to do so and might be necessary in particular cases.

Odoo relies on its object relational mapping (ORM) engine as the interface between the apps and the database. The ORM provides the application programming interface (API) used by the addon modules to interact with the data. We implement the data tier using ORM models. For example, the Partner data entity, used for data records like customers or suppliers, is represented by a model.

As a general rule, the low level database should only be accessed by this layer since it ensures security access control and data consistency. The ORM models are a Python object class supporting several interaction methods, such as the create, read, update and delete (CRUD) basic operations. In particular, these CRUD operations are implemented by the create(), search(), write() and unlink() model methods.

Logic tier

The logic tier is responsible for all the interactions with the data tier and is handled by the Odoo server. The basic CRUD operations can be extended to implement specific business logic. For example, the create() and write() model methods might implement default values or some other automation. Other code methods can be added to enforce validation rules or automatically compute field values.

Presentation tier

The presentation tier is responsible for presenting data and interacting with the user. It is implemented by the client section of the software, and is responsible for end user interaction. The client software uses remote procedure calls (RPCs) to the Odoo service, running the ORM and the business logic. ORM API calls are sent to the Odoo server for processing, to read, write, verify, or perform any other action. Then the results are sent back to the client for further handling.

One special aspect under the presentation tier is that Odoo provides a web client out of the box. The web client supports all the features needed by a business application, such as login sessions, navigation menus, data lists, and forms.

A website framework is also available to use as a public front end for external users. Equipped with CMS features, a framework allows us to create both static and dynamic web pages. The website framework uses controller components for the code implementing the presentation-specific logic, keeping it separate from the model’s intrinsic logic. The page rendering uses QWeb as the templating engine, which are XML documents that contain HTML markup plus specific XML QWeb tags for operations like loops, conditions, or calls to include other templates.

A quick word on Odoo open API

 

The Odoo server API is open, with all server functions available through it. The server API used by the official web client is the same as the one available to any other application. This means that other client implementations are possible, and can be built in almost any platform or programming language. Desktop and smartphone applications can be built to provide specific user interfaces, leveraging the Odoo data and logic tiers for business logic and data persistence.

 

 

Thinking about the Odoo to-do app project through the application tiers

Now that we’ve briefly explored the application tiers, let’s take a look at how each tier will be used in the Odoo to-do app project. It’s useful to approach these tiers as the primary structure for how to think about our application.

To-do project and the data tier

Mode of implementation: Models

For the data tier, we will create a To-do Item model. For the Work Team feature, we’ll leverage the built-in Contacts model (also called a Partner model).

A note to jot down and check twice: Do not forget to configure the access control security for our new model.

To-do project and the business logic tier

Mode of implementation: Python automation code

The business logic tier will be the basic create, read, update, delete (CRUD) operations handled by the web framework, with no additional automation requirements to support. We’ll use Python code in developer modules to access the full power of the framework.

To-do project and the presentation tier

Mode of implementation: Views

 

Finally, for the presentation tier, we will add the Menu option for our application, as well as the Views for the To-do Item model. The essential views for a business application are the List view (to browse the existing records), and the Form view (to zoom in to a record and see all the details). For user convenience, we can also add predefined filters to the List view’s search box. The search box options are configured through a Search view component.

To-do list steps

These are the steps we’ll follow for the to-do list app:
  1. Create the new model for To-do Items.
  2. Create the Menu Items to make it available to users.
  3. Configure the Access Control security.
  4. Create the List and Form views for the To-do Items.
The new To-do Item model should have these fields:
  • Description, which is a Char field.
  • Is Done? flag, which is a Boolean field.

As previously noted, our specification for the app includes a Work Team feature, i.e., the ability to select a list of people that will be working on the task. So, we need a model to represent specific people and/or entities. This is where Odoo’s Partner model, technical name res.partner, comes into play for individual people, companies, and addresses.

The To-do Items model should include the Work Team field to select a list of people. Part of the project will be to limit the people that can be selected to be part of Work Teams, which can be executed by modifying the Partner model to add an Is Work Team? flag. Only people with this flag enabled can be added to a Work Team.

For the Work Team feature, we need to add to our work plan:

 

  • Add a field to the Partner model and Form view

At this stage, we’ve effectively parsed out our Odoo To-do App, which means we need to dive into the ins and outs of the Odoo developer tools before hitting the gas on the actual implementation.

 

 

How to enable developer mode in Odoo

To get the implementation rolling, we need to access the developer tools by enabling the developer mode.

The developer mode is useful to inspect and modify current Odoo configurations. It allows us to customize Odoo apps directly from the UI, making for a convenient way to implement changes and add features. Developer mode can be used for both small modifications (such as adding a custom field) and larger customizations (such as creating an application with its own menus, views and underlying data model).

Caution

The developer mode exposes internal configuration for Odoo apps and allows them to be changed. Compared to the programming tools covered throughout Odoo Development Essentials, a person without the experience or proper guidance on how to use the developer mode could potentially harm the integrity of the system.

As a best practice, always test changes on a copy database before doing them in a live system. If things go wrong, there is a chance that an upgrade of the affected app, or the base module, can resolve them, but this is not an assured solution.

 

Enabling the developer mode across Odoo version updates

Developer mode after Odoo 13

For Odoo 13 and later, the developer mode is enabled on the Settings | General Settings page. As shown in the figure below, near the bottom of the page you will find the Developer Tools section with the Activate the developer mode link. Click to enable developer mode features for the current browser window.

Enabling the developer mode across Odoo version updates

Note that the General Settings menu option is only visible when there is at least one app installed. In such a case, simply install one app, like ContactsCRM, or any other of your preference in order to activate the menu.

Developer mode before Odoo 13

 

For Odoo 10 to 12, the developer mode is enabled in Settings | Dashboard page, in the lower right corner. For Odoo 9 and before, the developer mode is activated in the About dialog window, available from the User menu, in the upper right corner of the web client.

Odoo developer mode enabled menus

Once the developer mode is enabled, the following menus become available:

 

  • On the Settings app, the Technical and Translations menu items.
  • On the top menu bar, the Developer Tools bug icon, on the right-hand side, next to the Conversations and Activities icons.

 

Odoo developer mode enabled menus

The developer mode also enables additional information on the web client views. Hover your cursor over a selection to display that field’s technical information.

Enable developer mode manually with the URL

The developer mode can also be enabled by directly editing the current URL, without having to leave the current page to open Settings. Edit the URL to change the .../web#... part to insert .../web?debug=1#... . For example, http://localhost:8069/web#home would become http://localhost_8069/web?debug=1#home.

Odoo developer mode (with assets) and minification

For faster load times, the web client minifies the JavaScript and CSS assets into compact files. Unfortunately, that makes web client debugging nearly impossible.

Luckily, the Activate the developer mode (with assets) option prevents this minification and loads the web assets in individual, non-minified files. This is useful to debug the web client itself, at the expense of making the web client navigation slower.

Tip: Both Firefox and Chrome browsers have extensions available for conveniently enabling and disabling the developer mode. Search for “Odoo Debug” in the corresponding extension stores.

Explaining Odoo developer customization limitations

Doing customizations in developer mode has some limitations. For example, the developer tools can’t add or extend the default ORM methods.

The customizations done with the developer mode (and with the Odoo Studio app, for that matter) can’t be easily integrated into a structured development workflow, with version control, automated tests, and QA/ staging / production code promotion workflows.

About Odoo Studio

Both the Odoo Enterprise Edition and the Odoo SaaS offer the Odoo Studio App, an interactive application builder. We won’t be using it here, since it is not available for the Odoo Community Edition used as reference for this series of articles. However, it might be beneficial for less development-savvy users to note Odoo Studio as an effective alternative to developer mode, as it provides a user-friendly UI for the same interactive development features introduced in this chapter, along with a few extra features such as the ability to export our customizations to a file.

 

For our purposes here, we will be using the developer mode and the technical menu, both available in all Odoo editions. Most of what can be built using Odoo Studio can also be built with these tools, but it is important to keep in mind that developer mode is a much more technical approach to building, which might not be so friendly to non-developers.

Why Odoo development?

This set of articles intends to spread basic knowledge about Odoo development in hopes of providing the Odoo community with more autonomy when it comes to building better business applications. Even though customer freedom and flexibility comes baked into the choice to partner with OSI for all your Odoo open source ERP needs, fostering technical knowledge such as that provided can drastically improve control over the success of your business applications.

We hope these articles act as a jumping-off point for teachers, trainers, developers with a basic knowledge of Python programming, Odoo development managers, and even experienced Odoo developers. In short, we believe that these articles and their source text, Odoo 15 Development Essentials, are excellent resources for the Odoo community to either dive into essential Odoo building blocks or acquire an on-hand reference guide for when the Odoo development expert needs to double check Odoo updates.

Thank you for celebrating the release of the fifth edition of Odoo Development Essentials by following along with us here. Be on the lookout for article #2, “Adding a Custom Field Using the Odoo Developer Mode.” Coming soon!

 

 

Daniel

 

About the author

Daniel is a seasoned IT professional with extensive experience implementing business applications across a broad range of sectors. He’s worked with Odoo since 2010, back when it was known as Open ERP, and serves as a board member for the Odoo Community Association (OCA). Daniel is the managing director of Open Source Integrators.

 

Share this post