How to Inherit and Add Chatter to Existing Models in Odoo

Abid Patel
01-Nov-2024 Updated : 01-Nov-2024

Learn how to add the chatter to existing Odoo models with inheritance, enhancing communication and tracking through messages, activity scheduling, and record history.

How to Inherit and Add Chatter to Existing Models in Odoo

In Odoo chatter feature is invaluable. It offers logging of notes messages and tracking field changes. Often, we may want to add chatter functionality to an existing model. But some models don't include it by default. This guide will show the process of inheriting an existing model and adding chatter. Let's dive in!

What is Chatter in Odoo?

Chatter is activity log in forms. Here users can log messages, schedule activities track changes. More they communicate within a model's record. This is commonly found in core models like sale.order and res.partner. It's useful for keeping records organized and transparent.

Step 1: Inherit Model

To incorporate chatter to existing model we will inherit it. First step for this is adding inheritance. Next, we will add chatter. The model name is my.custom.model. Let's proceed to the explanation.

python

from odoo import models

class MyCustomModel(models.Model):
    _inherit = 'my.custom.model'
    _inherit = ['mail.thread', 'mail.activity.mixin']

In the example we inherit mail.thread. Also, inherit mail.activity.mixin. The purpose of these mixins is enabling chatter and activity tracking. mail.thread furnishes message and communication functionalities. On the other hand, mail.activity.mixin serves the function of allowing activity scheduling and activity tracking.

Step 2: Incorporate Chatter Section into the View

When we inherit model and add mandatory mixins, we also must update the view file. This update is to display the chatter. We add the <field name="message_ids" /> and <field name="activity_ids" /> fields in the XML.

xml

<record id="view_my_custom_model_form" model="ir.ui.view">
    <field name="name">my.custom.model.form</field>
    <field name="model">my.custom.model</field>
    <field name="arch" type="xml">
        <form string="My Custom Model">
            <!-- Form fields go here -->
            
            <!-- Adding the chatter -->
            <sheet>
                <div class="oe_chatter">
                    <field name="message_ids" widget="mail_thread"/>
                    <field name="activity_ids" widget="mail_activity"/>
                </div>
            </sheet>
        </form>
    </field>
</record>

The message_ids field lets you see the message thread in the form view. The activity_ids field displays the activities linked to the record. This XML code crafts section in form view. It allows user interaction with the chatter.

  • ▹ Next step. Update the module. Apply changes by running.
  • ▹ Head to form view of my.custom.model. Chatter is at the bottom of form.
  • ▹ Try adding a message. Or schedule activity. This confirms everything works well.

Why Integrate Chatter in Custom Models?

Chatter tool is really beneficial for collaboration in Odoo. When you add it to your custom models you are contributing to: Activity tracking: Teams have ability to craft and monitor tasks for progress. Record history: It keeps track of changes ensuring transparency. Improved communication: Users can add notes and communicate. This is done without leaving the record.

Conclusion

Adding chatter is straightforward in existing model of Odoo. It greatly enhances user experience. It provides improved tracking and communication. By following the steps above you can enable chatter in any model. Start using this powerful feature for custom requirements. Happy customizing!

Make a Comment

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