Tracking changes to important business records is crucial in enterprise systems. Odoo offers built-in mechanisms to help with this, notably the use of the track_visibility parameter and inheritance from the mail.thread class. Together, they allow developers to build auditable models where changes are logged and visible in the chatter, improving transparency and traceability.
Enabling Field Tracking
To begin tracking field changes, your model must inherit from mail.thread. This base class allows a record to interface with Odoo's messaging system (also known as the chatter).
from odoo import models, fields class ProductTemplate(models.Model): _inherit = 'product.template' _inherit = ['product.template', 'mail.thread'] name = fields.Char(track_visibility='onchange') list_price = fields.Float(track_visibility='onchange')
In this example, changes to the name and list_price fields on the product template will be tracked. When a user modifies these fields, a log of the change will be posted in the chatter.
Understanding track_visibility
The track_visibility parameter can take two values:
- 'onchange': Tracks changes and posts them in the chatter when the record is updated.
- 'always': Tracks changes even if the record is created or modified programmatically.
If you’re unsure, use 'onchange' for user-facing updates. For broader coverage, including automated changes, use 'always'.
Chatter Display
Once tracking is enabled, any changes to tracked fields are posted in the form view's chatter. This helps internal teams keep track of who made changes, when, and what the values were before and after the update.
Example: Custom Model with Tracking
from odoo import models, fields class Equipment(models.Model): _name = 'maintenance.equipment' _inherit = ['mail.thread'] name = fields.Char(required=True, track_visibility='onchange') status = fields.Selection([ ('active', 'Active'), ('inactive', 'Inactive') ], default='active', track_visibility='onchange')
Any status change here will appear in the chatter, making it easier to trace decisions or status transitions for audits or process reviews.
Backend Considerations
For developers, it’s important to note that tracked fields must be defined in models that inherit from mail.thread. Additionally, tracked changes are stored in the messaging subsystem (mail.message model), which enables them to be used in notifications, reports, and even automated workflows.
Final Notes
Using track_visibility in combination with mail.thread is a clean and efficient way to enable field change logging in Odoo. This capability is particularly valuable in sales, inventory, HR, and finance modules where data changes need to be traceable. It requires minimal code changes and leverages Odoo’s robust messaging framework to maintain accountability and transparency across business processes.
For mission-critical applications, consider pairing this with record rules, user-specific access rights, or even audit log modules to build a comprehensive governance layer in your Odoo implementation.