
Learn about the log_access model attribute in Odoo, its purpose, and how to manage logging metadata for records, like creation and modification details.
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.
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:
These fields are known as “log access fields,” and they include create_uid, create_date, write_uid, and write_date.
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:
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.
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.
Here are some scenarios where disabling log_access might be helpful:
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.
Your email address will not be published. Required fields are marked *