Understanding the Log Access Model Attribute in Odoo

Abid Patel
23-Oct-2024 Updated : 23-Oct-2024

Learn about the log_access model attribute in Odoo, its purpose, and how to manage logging metadata for records, like creation and modification details.

Understanding the Log Access Model Attribute in Odoo

Odoo models come with several attributes that control their behavior. One of these important attributes is log_access, which plays a crucial role in tracking and logging user activity related to records. In this blog, we will explore what the log_access attribute is, how it works, and when to use it in Odoo development.

What is the log_access Attribute in Odoo?

By default, all Odoo models have the log_access attribute set to True. This attribute enables Odoo to automatically track and store essential metadata about each record, such as:

  • ▹ Creation date
  • ▹ Last modification date
  • ▹ Who created the record (user ID)
  • ▹ Who last updated the record (user ID)

These fields are known as “log access fields,” and they include create_uid, create_date, write_uid, and write_date.

When to Disable Log Access in Odoo

In some cases, tracking log access might not be necessary or desired. For instance, in models that involve temporary data, such as transient models or models used for specific computations or caching, you might not need to store this information.

To disable the log access feature in your custom model, simply set the log_access attribute to False in the model definition:

python

    from odoo import models, fields
    class YourCustomModel(models.Model):
        _name = 'your.custom.model'
        _description = 'Your Custom Model'
        _log_access = False
    

With log_access set to False, Odoo will no longer automatically add or manage the log access fields for this model. This helps optimize the performance for models where tracking these details is not necessary.

Impact of Disabling Log Access

Disabling log_access prevents the creation of the create_uid, create_date, write_uid, and write_date fields in the database for the model. Therefore, developers must consider whether they still need this information for auditing or reporting purposes before turning it off.

Use Cases for log_access

Here are some scenarios where disabling log_access might be helpful:

  • ▹ Temporary data that doesn't require auditing
  • ▹ Performance optimization for large datasets that don't need access logs
  • ▹ Custom models where the system doesn't need to track the creator or last editor

Conclusion

The log_access attribute in Odoo provides a simple way to manage automatic logging of important record metadata like creation and modification timestamps. While it is enabled by default, you can disable it for models where logging isn't necessary. Understanding when and how to control this attribute will help you optimize your Odoo modules for both performance and functionality.

Make a Comment

Your email address will not be published. Required fields are marked *