Enable Dark Mode!
how-to-post-a-message-to-chatter-in-odoo-17.jpg
By: Ahammed Harshad P

How to Post a Message to Chatter in Odoo 17

Technical Odoo 17

The chatter feature in Odoo is crucial for communication and obtaining information about various processes. It facilitates easy interaction and enhances overall collaboration. In Odoo 17, the versatile chatter feature in Sales, Projects, Tasks, Invoicing, and more is a powerful tool for seamless communication and staying informed about various processes.

Here you can see the process details that were shared in the chatter.

how-to-post-a-message-to-chatter-in-odoo-17-1-cybrosys

You can observe that the appointment is being created and confirmed, as well as internal communication with the user, including the time details.

In our work with Odoo customization, we often need to add messages that suit our needs. You will discover in this blog how to easily post messages in the Odoo 17 chatter for a customized module.

For example, we have the custom module Laboratory. In the appointment, we have a lab test, 'Covid-19', and we need to receive a message when the lab test is completed. Let’s check how we can do this.

Similarly to previous Odoo versions, you can use "message_post()" to share a message in the chatter in Odoo 17. We can use the message posting function in the lab test completion function.

def action_set_to_test_completed(self):
   """
   Set the lab request's state to 'Completed'
   """
   body = _("Lab Test %s is Completed", self.name)
   self.app_id.message_post(body=body)
   return self.write({'state': 'completed'})

As you can see, we added a function to post a message in the corresponding appointment,'self.app_id.message_post(body=body)', where 'app_id' is the appointment object. This code makes the lab test complete. In the ‘body’ attribute of the function, we can add the content that will appear in the message.

how-to-post-a-message-to-chatter-in-odoo-17-2-cybrosys

The message will be posted at the associated appointment once the lab test is completed.

So, this is how we simply add a message to the chatter. Now we can see what changes we can make to the message appearances provided by Odoo 17.

For example, if we have the name of the lab test in the message, we can make it a link that redirects to the specific record.

body = _("Lab Test %s is Completed", self._get_html_link(title=self.name))

Now the name in the message will become a link. The function ‘_get_html_link’ returns the HTML link content.

We can now add a subject and change the message's style. In addition, we can add an author to the message to specify who is sending the message.

self.app_id.message_post(body=body,
            author_id=self.env.ref('base.partner_root').id,
            subject='Test Completed',
            message_type='comment',
            subtype_xmlid='mail.mt_comment')

Here we can see the message posted by the user we configured, and we have the subject with style from the template we gave.

how-to-post-a-message-to-chatter-in-odoo-17-3-cybrosys

This function can be applied to any type of record linked to the chatter. This method accepts several arguments, including 'email_from' for specifying the author's email address, 'attachments' for adding a list of attachments as tuples, 'attachment_ids' for specifying existing attachment ids, and 'body_is_html' to indicate that the body should be treated as HTML contents only. 

We have the flexibility to modify the message according to our specific requirements, enabling us to tailor the content to better suit our needs and preferences.

In conclusion, this method demonstrates the straightforward process of posting a message to the chatter in Odoo 17.

To read more about adding a button in Chatter in Odoo 17, refer to our blog How to Add a Button in Chatter in Odoo 17


If you need any assistance in odoo, we are online, please chat with us.



0
Comments



Leave a comment



whatsapp_icon
location

Calicut

Cybrosys Technologies Pvt. Ltd.
Neospace, Kinfra Techno Park
Kakkancherry, Calicut
Kerala, India - 673635

location

Kochi

Cybrosys Technologies Pvt. Ltd.
1st Floor, Thapasya Building,
Infopark, Kakkanad,
Kochi, India - 682030.

location

Bangalore

Cybrosys Techno Solutions
The Estate, 8th Floor,
Dickenson Road,
Bangalore, India - 560042

Send Us A Message