How To Add Chatter To Form View And Enable Tracking For Fields In Odoo 16
- Add the ‘mail’ module to the dependencies list in your module’s manifest file (e.g. manifest.py).
Add the ‘mail.thread’ model to the _inherit list in your custom model’s class definition in the models.py file
from odoo import api, fields, models
class HospitalPatient(models.Model):
_name = ‘hospital.patient’
_inherit = [‘mail.thread’,’mail.activity.mixin’]
_description= ‘Hospital Management System’
- Add the ‘message_follower_ids’ and ‘message_ids’ fields to your custom model’s view definition in the views.py file. For example:
<record id=”view_hospital_patient_form” model=”ir.ui.view”>
<field name=”model”>hospital.patient.form</field>
<field name=”model”>hospital.patient</field>
<field name=”arch” type=”xml”>
<form>
<sheet>
<group>
<group>
<field name=’name’></field>
<field name=’age’></field>
</group>
<group>
<field name=’gender’></field>
<field name=’active’ invisible=”1″></field>
</group>
</group>
</sheet>
<div class=”oe_chatter”>
<field name=”message_follower_ids” groups=”base.group_user”/>
<field name=”activity_ids”/>
<field name=”message_ids”/>
</div>
</form>
</field>
</record>
Override the ‘create’ and ‘write’ methods in your custom model’s class definition to enable tracking of changes.
For any inquiries, suggestions, or feedback, you can reach out to us through the provided contact form on our blog. We make an effort to respond to all queries in a timely manner and appreciate your engagement with our content.