Enable Dark Mode!
a-complete-guide-to-transient-model-wizards-in-odoo-19.jpg
By: Safa KB

A Complete Guide to Transient Model Wizards in Odoo 19

Technical Odoo 19 Odoo Enterprises Odoo Community

In Odoo development, there are many situations where you need to gather temporary input from users, process it, and discard it afterward. Whether you are validating operations, applying discounts, importing data, checking privacy records, or sending emails, the process often relies on temporary data that shouldn't stay in the database forever. This is where Transient Models come into play.

Transient models are specifically created for temporary input and are a lightweight and faster option than regular models. Odoo will also automatically clean up transient models, so they are excellent for use in wizard forms and short-term user interaction.

What is a Transient Model?

A Transient Model is a temporary model that Odoo uses for temporary data storage. Transient models are frequently found in wizard forms—small pop-up windows that allow the user to enter information to be acted on.

Transient Model Key Characteristics:

  • Temporary data: Transient model records do not remain in the database for very long.
  • Automatic cleanup: Odoo uses an autovacuum function to delete old records.
  • Mainly used in wizards: They are an excellent choice for temporary user interactions.
  • Lightweight and fast: Transient models will enhance performance when used on temporary tasks.

How do you define a transient model:

from odoo import models
class PrivacyLookupWizardLine(models.TransientModel):

This tells Odoo: “This model is not permanent. Clean it up automatically.”

Why Odoo Cleans Transient Models

When a model is only intended for temporary use, Odoo will prevent the build-up of old data associated with wizards by clearing old data on a periodic basis through an automated process called "autovacuum."

Each transient model can define:

  • _transient_max_hours > How long a record is allowed to stay
  • _transient_max_count > Maximum number of records allowed

If too many records exist or a record is too old, Odoo removes it.

from odoo import models, fields
class PrivacyLookupWizardLine(models.TransientModel):
   _name = 'privacy.lookup.wizard.line'
   _description = 'Privacy Lookup Wizard Line'
   _transient_max_count = 0
   _transient_max_hours = 24
   res_id = fields.Integer(string="Resource ID", required=True)
   res_name = fields.Char(string='Resource', compute='_compute_res_name', store=True)

This configuration means:

  • Records are kept for up to 24 hours.
  • There is no limit on the number of records.
  • Anything older than 24 hours is automatically deleted.

How Odoo Automatically Deletes Wizard Records

The cleanup process uses Odoo’s internal method:

@api.autovacuum
def _transient_vacuum(self):

In Odoo, @api.autovacuum is a special decorator used to mark methods that should be executed automatically by Odoo’s autovacuum cleanup system.

In transient models, Odoo defines an internal method named:_transient_vacuum() This method is responsible for cleaning up old transient records.

You do not need to manage this — Odoo handles it automatically.

When Should You Use Transient Models?

Use a transient model when:

  1. Data is temporary
  2. You only need it for a user action
  3. You don’t want to store it permanently
  4. You are building a wizard

Conclusion

Transient models in Odoo are used to store temporary data during a user action, do not require long-term storage, and are used to present information in wizards. This temporary data collection allows developers to focus on creating efficient workflows & smooth experiences in building wizards, as the removal of the data will occur automatically by the Odoo autovacuum cleanup system. Understanding the purpose of transient models will help developers to create lean, user-centric, and easy-to-maintain features that will improve the overall Odoo experience.

To read more about How Transient Models Work in Odoo 19, refer to our blog, How Transient Models Work in Odoo 19.


If you need any assistance in odoo, we are online, please chat with us.



0
Comments



Leave a comment



whatsapp_icon
location

Calicut

Cybrosys Technologies Pvt. Ltd.
Neospace, Kinfra Techno Park
Kakkancherry, Calicut
Kerala, India - 673635

location

Kochi

Cybrosys Technologies Pvt. Ltd.
1st Floor, Thapasya Building,
Infopark, Kakkanad,
Kochi, India - 682030.

location

Bangalore

Cybrosys Techno Solutions
The Estate, 8th Floor,
Dickenson Road,
Bangalore, India - 560042

Send Us A Message