How To Add Chatter To Form View And Enable Tracking For Fields In Odoo 16

How To Add  Chatter To Form View And Enable Tracking For Fields In Odoo 16

 

How To Add  Chatter To Form View And Enable Tracking For Fields In Odoo 16

  1. Add the ‘mail’ module to the dependencies list in your module’s manifest file (e.g. manifest.py).
{
‘name’: ‘Hospital Management’,
‘version’: ‘1.2’,
‘category’: ‘Hospital Management System’,
‘author’: ‘pythonpowers’,
‘sequence’: –100,
‘summary’: ‘HMS’,
‘description’: “””
This module contains all the common features of Hospital Managent System.
“””,
‘depends’: [‘mail’],
‘data’: [
],
‘demo’: [],
‘application’:True,
‘installable’: True,
‘assets’: {
},
‘license’: ‘LGPL-3’,


}



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’

  1. 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.


from odoo import api, fields, models

class HospitalPatient(models.Model):
_name = ‘hospital.patient’
_inherit = [‘mail.thread’,‘mail.activity.mixin’]
_description= ‘Hospital Management System’
name = fields.Char(string=‘Name’, tracking=True)
age = fields.Integer(string=‘Age’, tracking=True)

          


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.

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *