How to Add a Custom Button to the Chatter in Odoo 18
Introduction
The Odoo chatter is a powerful tool that centralizes communications and updates for specific records, making it essential for day-to-day operations. Enhancing the chatter by adding custom buttons allows users to trigger specific actions directly within the interface. In this blog, we’ll walk you through how to add a custom button to the chatter in Odoo 18. This guide includes creating the button, defining its functionality, and implementing the server-side logic to ensure a seamless user experience.
Steps to Add a Custom Button to the Chatter
1. Define the Button in the Chatter (XML)
To begin, extend the existing chatter template in your custom module.
This snippet adds a "Mark as Verified" button before the chatter activity section. The button includes a keyboard shortcut (Shift+i) and a JavaScript event handler to trigger its functionality.
2. Implement Button Functionality (JavaScript)
Define the functionality triggered when the button is clicked by patching the chatter component.
This code extends the chatter component by adding a markAsVerified method, which calls a server-side action named action_mark_as_verified.
3. Server-Side Logic (Python)
Inherit the necessary model (e.g., sale.order) and define the server-side action.
This code introduces a verified field and the action_mark_as_verified method, which updates the field and posts a message in the chatter.
4. Add the Field to the Form View
Ensure the new field is available in the form view, even if hidden.
This XML snippet ensures the verified field is part of the view definition but hidden from the UI.
5. Update the Module Manifest
Don't Forget to Include the new files in the __manifest__.py file of your custom module.
After following these steps, you will have successfully added a button to the chatter in Odoo 18. Upon clicking the "Mark as Verified" button, the verified field will be updated, and a message will be posted in the chatter.