Odoo Models: The Backbone of Your App

Odoo Models: The Backbone of Your App

Imagine you’re building a house. Before you lay the first brick, you need a blueprint—a detailed plan that defines the structure, rooms, and connections. In the world of Odoo, that blueprint is called a model.

Whether you're a beginner developer or a business owner exploring Odoo’s potential, understanding models is crucial. They define how your data is stored, organized, and manipulated. No models? No app. It’s that simple.

In this guide, we’ll break down:

What Odoo models are (and why they matter)
How to create them (with Python classes)
Real-world examples (CRM, Inventory, etc.)
Best practices for smooth development

Let’s dive in!


1. What Are Odoo Models?

Think of an Odoo model as a database table with superpowers. It defines:

  • Fields (columns in a table, like customer_name, email, order_date)
  • Relationships (links between tables, e.g., one customer → many orders)
  • Business logic (automated actions, validations, calculations)

Every Odoo app (CRM, Sales, Inventory) is built on models. For example:

Feature Model Example Fields
CRM res.partner name, phone, email
Sales sale.order customer_id, date, amount
Inventory stock.move product_id, quantity

Without models, Odoo wouldn’t know where to store or retrieve your data.


2. How to Create an Odoo Model (Step-by-Step)

Creating a model is as easy as writing a Python class. Here’s how:

Step 1: Define the Model

from odoo import models, fields

class CustomerFeedback(models.Model):
    _name = 'customer.feedback'  # Unique model identifier
    _description = 'Records customer feedback'  # Human-readable label

    customer_name = fields.Char(string="Name", required=True)
    email = fields.Char(string="Email")
    rating = fields.Integer(string="Rating (1-5)")
    comments = fields.Text(string="Feedback")

Step 2: Add Fields

Odoo supports multiple field types:

Field Type Example Use Case
Char Short text (name, email)
Integer Numbers (rating, age)
Float Decimals (price, weight)
Boolean Yes/No (is_active)
Date Order date
Text Long comments

Step 3: Add Relationships

Link models like this:

feedback_id = fields.Many2one('res.partner', string="Customer")
  • Many2one (One customer → Many feedback entries)
  • One2many (One order → Many products)
  • Many2many (Multiple tags → Multiple products)

3. Real-World Example: Building a CRM Model

Let’s say you want a custom CRM feature to track high-priority leads.

class PriorityLead(models.Model):
    _name = 'priority.lead'
    _description = 'High-priority sales leads'

    name = fields.Char(string="Lead Name", required=True)
    company = fields.Char(string="Company")
    email = fields.Char(string="Email")
    priority = fields.Selection(
        selection=[('low', 'Low'), ('medium', 'Medium'), ('high', 'High')],
        default='medium'
    )
    assigned_to = fields.Many2one('res.users', string="Salesperson")

Now:
✔ Leads are stored in the database
✔ Sales teams can filter by priority
✔ Managers assign leads to team members


4. Best Practices for Odoo Models

To avoid headaches later:

🔹 Use clear naming (sale.order instead of order123)
🔹 Add descriptions (_description = "Stores customer orders")
🔹 Index frequently searched fields (index=True on customer_id)
🔹 Avoid too many fields in one model (Split into related models)
🔹 Use compute fields for dynamic calculations (e.g., total_price)


5. Conclusion: Why Models Matter

Odoo models are the foundation of any app. They:

Structure your data (like a database table)
Define business rules (automations, validations)
Enable scalability (add new features without breaking old ones)

Now it’s your turn!

👉 Try creating a simple model (e.g., event.registration for a workshop).
👉 Tag a developer friend who’s learning Odoo—they’ll thank you later!

Got questions? Drop them below! 🚀


💡 Pro Tip

Explore Odoo’s built-in models (res.partner, product.template) to see how experts structure data.

Happy modeling! 🛠️

Your First Odoo Module in 5 Steps