Types of models in Odoo are Python classes that represent business objects and interact with the database. These models inherit from Odoo's Model class, which provides the framework to define fields, relationships, methods, and access controls.
How Many Types of Models in Odoo
Odoo has several types of models, each serving different purposes. Lets start it.
Regular Models
These are standard models used to represent persistent business data. They correspond to database tables, where each record is a row and each field is a column.
Features:
- Purpose: Represents standard business objects and corresponds to a persistent database table. It is used for storing data that needs to be retained permanently.
- Persistence: Data is stored permanently in a database table until explicitly deleted.
- Database Table: Yes, a corresponding database table is created.
- Use Case: When you need to store and manage persistent data such as customers, products, sales orders, invoices, etc.
- Inheritance: Can be inherited by other models.
Example:
class Product(models.Model):
_name = 'product.product'
name = fields.Char(string='Product Name')
Transient Models
These are models for temporary data that doesn't need to be persisted in the database permanently. Records are typically deleted after a short period or a specific action.
The transient models are commonly used for wizards, which are interactive forms for temporary user input.
Features:
- Purpose: Used for temporary data that is only needed for a short duration, typically during the current session or task (e.g., wizards). Data is meant to be ephemeral and automatically cleaned up.
- Persistence: Data is temporary and is deleted after a short period or upon completion of the session/task.
- Database Table: Yes, a database table is created, but records are usually deleted after a certain time (handled by the system garbage collector).
- Use Case: Used when temporary data is needed, such as for wizards (multi-step forms), temporary calculations, or batch processing.
- Inheritance: Can be inherited, but typically used for standalone temporary models.
Example:
class ProductWizard(models.TransientModel):
_name = 'product.wizard'
name = fields.Char(string='Product Name')
Abstract Models
These are base models used to define reusable logic but don't correspond to a database table. They are intended to be inherited by other models.
They allow shared functionality without directly creating records.
Features:
- Purpose: Defines reusable logic (methods, fields) to be shared across other models. It doesn't create its own database table and cannot store data.
- Persistence: No persistence, as it's not linked to a database table.
- Database Table: No, an abstract model does not create its own table.
- Use Case: Used when you want to define reusable logic, such as common methods or fields, that can be inherited by multiple models without creating an independent model.
- Inheritance: Abstract models are designed to be inherited by other models that need to reuse the common functionality.
Example:
class CommonInfo(models.AbstractModel):
_name = 'common.info'
name = fields.Char(string='Common Name')
These models provide a wide range of functionality to support different types of operations in Odoo, whether for temporary processing, abstract logic sharing, or interacting with actual database tables.
| Aspect | Regular Model |
Abstract Model |
Transient Model |
|---|---|---|---|
| Purpose | Persistent data storage for business entities. | Reusable logic (methods, fields), no data storage. | Temporary data handling (e.g., wizards). |
| Persistence | Data is stored permanently in the database. | No persistence (no table). | Data is temporary, short-lived. |
| Database Table | Yes, creates a table in the database. | No, does not create a database table. | Yes, but data is auto-deleted after a period. |
| Use Case | Storing persistent business data (e.g., products, customers). | Sharing common logic, methods, fields across models. | Handling temporary data during user sessions. |
| Inheritance | Can be inherited. | Designed to be inherited by other models. | Can be inherited but mostly used as standalone. |
| Example | Sales Orders, Products, Customers. | Common methods or fields shared between models. | Wizards for multi-step forms, temporary input. |