
Learn how to add the chatter feature in form views and enable field tracking in Odoo. This guide will help you improve communication and track changes effectively within Odoo.
Odoo 17 introduces enhancements and features that make it even more powerful for managing business processes. Two of these features—chatter in form views and field tracking—are essential tools for improving collaboration, communication, and record-keeping. This blog will guide you step by step on how to add chatter to a form view and enable field tracking in Odoo 17.
1. Adding Chatter to a Form View in Odoo 17
2. Enabling Field Tracking in Odoo 17
3. Combining Chatter and Field Tracking for Enhanced Functionality
4. Conclusion
Chatter and field tracking are two key features that can significantly enhance the user experience in Odoo. Here’s a brief overview:
Chatter: The chatter is a communication tool embedded within a form view. It allows users to exchange messages, log notes, and schedule activities directly related to the record being viewed. Chatter also displays the history of changes made to the record, providing a comprehensive audit trail.
Field Tracking: Field tracking is a feature that logs changes to specific fields in a model. Whenever a tracked field is updated, the changes are recorded in the chatter, providing visibility into what was changed, by whom, and when.
The first step is to integrate the chatter into a form view. This process involves modifying the XML definition of the form view to include the chatter component.
Form views in Odoo are defined in XML files and are associated with specific models. A form view describes how the fields of a model are displayed to the user. The chatter is typically added at the bottom of the form view, allowing users to see and interact with the record's communication history.
To add the chatter, you need to include the '
' tag with the 'class' attribute set to 'oe_chatter' within the form view’s XML definition.
Here’s an example of how to add chatter to a form view for the 'res.partner' model, which represents customers:
<record id="view_res_partner_form_with_chatter" model="ir.ui.view">
<field name="name">res.partner.form.with.chatter</field>
<field name="model">res.partner</field>
<field name="arch" type="xml">
<form string="Partner">
<sheet>
<group>
<field name="name"/>
<field name="email"/>
<field name="phone"/>
</group>
</sheet>
<!-- Adding Chatter -->
<div class="oe_chatter">
<field name="message_follower_ids" widget="mail_followers"/>
<field name="message_ids" widget="mail_thread"/>
</div>
</form>
</field>
</record>
Explanation:
'oe_chatter': This class activates the chatter functionality within the form.
'message_follower_ids': This field manages the followers of the record, allowing users to subscribe to updates and changes.
'message_ids': This field displays the messages, notes, and activities associated with the record.
To enable chatter in the form view, the corresponding model must be set up to handle messages, followers, and activities. This is done by inheriting the 'mail.thread' and 'mail.activity.mixin' models.
Here’s how to modify the 'res.partner' model to include chatter:
from odoo import models, fields
class ResPartner(models.Model):
_inherit = 'res.partner'
_inherit = ['mail.thread', 'mail.activity.mixin']
name = fields.Char(track_visibility='onchange')
Explanation:
'mail.thread': This mixin adds messaging and follower functionality to the model.
'mail.activity.mixin': This mixin adds support for managing activities like tasks, meetings, and calls.
After implementing the chatter, it’s crucial to test it to ensure it’s functioning as expected:
Navigate to the Form View: Access the form view of the model where you added the chatter.
Interact with Chatter: Send a message, log a note, or schedule an activity using the chatter.
Verify the Integration: Check that the chatter displays the messages, notes, and activities correctly, and that followers can be added or removed.
Field tracking allows you to monitor changes to specific fields in a model. When a tracked field is updated, the changes are automatically logged in the chatter, providing an audit trail.
Field tracking in Odoo is activated by setting the tracking attribute on a field. When this attribute is set, any change to the field is recorded in the chatter, showing both the old and new values along with the user who made the change.
To enable tracking on a field, you need to modify the model’s Python file and set the tracking attribute for the fields you want to monitor.
Here’s an example of how to enable tracking for the 'email' and 'phone' fields in the 'res.partner' model:
from odoo import models, fields
class ResPartner(models.Model):
_inherit = 'res.partner'
email = fields.Char(tracking=True)
phone = fields.Char(tracking=True)
Explanation:
'tracking=True': This attribute enables tracking for the field, causing any changes to the field to be logged in the chatter.
If you are working with custom models, you can enable tracking in the same way. Define your fields and set the 'tracking' attribute where needed.
Here’s an example of a custom model with tracking enabled for a 'status' field:
from odoo import models, fields
class CustomModel(models.Model):
_name = 'custom.model'
_inherit = ['mail.thread']
name = fields.Char(required=True)
status = fields.Selection([
('new', 'New'),
('in_progress', 'In Progress'),
('done', 'Done')
], tracking=True)
After enabling field tracking, it’s important to test the functionality:
Update a Tracked Field: Change the value of a tracked field in the form view.
Check the Chatter: Ensure that the change is recorded in the chatter, showing the old and new values.
Review the Log: Verify that the log entry includes the date, time, and user who made the change.
In more complex scenarios, you may want to track changes based on specific conditions or customize the tracking messages. Odoo allows you to implement this through Python methods.
Example: Conditional Tracking of a Field
from odoo import models, fields
class ResPartner(models.Model):
_inherit = 'res.partner'
def write(self, vals):
if 'email' in vals and vals['email'] != self.email:
self.message_post(body="Email address changed from %s to %s" % (self.email, vals['email']))
return super(ResPartner, self).write(vals)
Explanation:
'Custom Log Message': This code posts a custom message to the chatter if the email field is changed, specifying the old and new values.
Combining chatter and field tracking can significantly enhance collaboration and transparency in your Odoo environment. By using these features together, you can create a robust system for communication, auditing, and tracking changes.
Let’s consider a practical example where you want to track changes to a status field in a project task and notify followers when the status changes.
Define the Model with Tracking Enabled
from odoo import models, fields
class ProjectTask(models.Model):
_inherit = 'project.task'
status = fields.Selection([
('new', 'New'),
('in_progress', 'In Progress'),
('done', 'Done')
], tracking=True)
Customizing the Chatter Notification
from odoo import models, fields
class ProjectTask(models.Model):
_inherit = 'project.task'
def write(self, vals):
if 'status' in vals:
status_dict = dict(self.fields_get(allfields=['status'])['status']['selection'])
self.message_post(body="Task status changed to %s" % status_dict[vals['status']])
return super(ProjectTask, self).write(vals)
Explanation:
'Custom Notification': This script customizes the chatter message to notify followers whenever the task status changes.
Test the combined functionality of chatter and field tracking to ensure everything works correctly:
'Update the Tracked Field': Change the status of a task in the form view.
'Verify the Chatter Log': Check that the status change is logged in the chatter, with a notification sent to followers.
'Confirm Notifications': Ensure that followers receive a notification about the status change.
To maximize the benefits of chatter and field tracking, consider the following best practices:
Selective Tracking: Only enable tracking for fields that are critical to your business processes to avoid cluttering the chatter with unnecessary logs.
Clear Communication: Use custom messages in the chatter to make notifications clear and actionable for users.
Regular Reviews: Periodically review the tracked fields and chatter logs to ensure they align with your current business needs.
Adding chatter to form views and enabling field tracking in Odoo 17 are straightforward yet powerful steps to enhance communication, collaboration, and auditing. These features allow you to create a more interactive and transparent experience for your users, while also maintaining an accurate record of changes.
By following the steps outlined in this blog, you can seamlessly integrate these functionalities into your Odoo instance, whether you’re customizing existing models or building new ones. These tools are invaluable for any business looking to leverage Odoo’s full potential for managing their processes and data effectively.
Your email address will not be published. Required fields are marked *