How to add a Chatter to Form View in Odoo 13, 12
How to add a Chatter to form view in Odoo. Here is the quick solution to adding a chatter in Odoo form view. Odoo Chatter is a special functionality to store conversation messages, track changes, as well as store attachments. Moreover, you can write an internal note. To extend this functionality, you can add follow/unfollow to receive any new update directly in your mailbox.
We have already seen this chatter in many Odoo forms. In this tutorial, we walk through the complete process of how to add a chatter to form a view in Odoo. It requires basic technical knowledge of Odoo. This article specially for beginner Odoo developer.
Add a Chatter to Odoo Form View
First of all, let’s have a look at the python file. We have a user.profile model as per below fields defined. As well as, we have to add the chatter to this model. Hence, we have to inherit mail.thread in order to access chatter functionality. You can see below the highlighted line 8, which we added in our python file.
# -*- coding: utf-8 -*-
from odoo import models, fields
class UserProfile(models.Model):
_name = "user.profile"
_inherit = ['mail.thread']
_description = "User Information"
name = fields.Char(string='Name', required=True)
image = fields.Binary(string='Photo')
designation = fields.Char(string='Designation', track_visibility='onchange')
gender = fields.Selection([
('male', 'Male'),
('female', 'Female'),
], string='Gender')
higher_qualification = fields.Selection([
('graduate', 'Graduate'),
('post_graduate', 'Post Graduate'),
('phd', 'PHD'),
], string='Higher Qualification')
dob = fields.Date('Birth Date')
nationality = fields.Many2one('res.country', string='Nationality')
Furthermore, we have a form view of the above model. We have to add chatter code in our XML file in order to use chatter functionality.
<div class="oe_chatter">
<field name="message_follower_ids" widget="mail_followers"/>
<field name="message_ids" widget="mail_thread"/>
</div>
You can see below highlight lines, which we added to access chatter.
<record id="user_profile_view_form" model="ir.ui.view">
<field name="name">user.profile.form</field>
<field name="model">user.profile</field>
<field name="arch" type="xml">
<form string="User Profile">
<sheet>
<field name="image" widget='image' class="oe_avatar"/>
<div class="oe_title">
<h1>
<field name="name"/>
</h1>
</div>
<group>
<group>
<field name="designation"/>
<field name="gender"/>
<field name="higher_qualification"/>
</group>
<group>
<field name="dob"/>
<field name="nationality"/>
</group>
</group>
</sheet>
<div class="oe_chatter">
<field name="message_follower_ids" widget="mail_followers"/>
<field name="message_ids" widget="mail_thread"/>
</div>
</form>
</field>
</record>
After adding the above code in a python file and XML form view you need to upgrade the module. As you see chatter is now available for use. We have created one record and it will look like below screen.
![Added a Chatter to Form View in Odoo](https://speedysense.com/wp-content/uploads/2019/12/Added-a-Chatter-to-Form-View-in-Odoo.png)
Track Visibility
Track visibility is used to track whatever changes made in the fields. You have to define track_visibility
in the field definition. Odoo is a multi-user platform and sometimes the same record might be accessing and change any of the users. For these cases, we have to keep track of who is charged the field values, what is old and new values of the fields. This information is kept tracking on Odoo chatter automatically. Let’s see the following field we added track_visibility
.
designation = fields.Char(string='Designation', track_visibility='onchange')
You can set track_visibility
value either onchange
or always
.
always: As the name suggests, changes are logged always even if the value is changed on any of the fields within the model.
onchange: changes are logged only if the value is change specified track_visibility=’onchange’ field only.
You must have to upgrade your module, whenever you change/update in your model file (.py) or view file (XML).
You can see the following screen, we have change designation from “English actor” to “English actor & director”.
![Enable track visibility in field](https://speedysense.com/wp-content/uploads/2019/12/Enable-track-visibility-in-field.png)
Send Message
You can write a message, and notify to followers. Also, you can attach an attachment file. It is a good idea to track and keep all conversation messages.
![Send message - Odoo Chatter](https://speedysense.com/wp-content/uploads/2019/12/Send-message-in-Odoo-chatter.png)
Log Note
Moreover, you can write an internal note. Which is not notifies to followers but it is kept in Odoo chatter.
![](https://speedysense.com/wp-content/uploads/2019/12/Internal-note-Odoo-Chatter.png)
Finally, Odoo chatter we added in our form view. We discussed a few benefits of Odoo chatter. We can send a message, internal note, add an attachment, and track field value changes.
![Track Visibility Message and Internal note added to Chatter in form view](https://speedysense.com/wp-content/uploads/2019/12/Track-Visibility-Message-and-Internal-note-added-to-Chatter-in-form-view.png)
We hope you have found this article helpful. Let us know your questions or feedback if any through the comment section in below. You can subscribe our newsletter and get notified when we publish new WordPress articles for free. Moreover, you can explore here other Odoo related articles.
Icon made by Webalys
If you like our article, please consider buying a coffee for us.
Thanks for your support!
Buy me a coffee!
Join the Discussion.