How to Post a Message to Chatter in Odoo 15?

How to Post a Message to Chatter in Odoo 15?

3 minutes, 26 seconds Read

One of the key features of all modules in Odoo, such as Sales, Purchase, Inventory, or any other, is chatter. We can see chatter in all of these modules, which helps users know more about the process, like invoices, sale orders, purchase orders, etc.

Usually, chatter helps for internal communication with users. For example, when a sale order is created, it will be shown in the chatter. In the same way, if the stages of operation are changed, the status will also automatically be changed. For example, if the quotation is converted into a sale order, the state will change to the “quotation sent to sale” state. So the user can easily identify the current state of the sale order.

how-to-post-a-message-to-chatter-in-odoo-15-cybrosys

In odoo, there is a default method “message_post”  which is used to post a new message in the chatter and mail sending.There are many arguments used along with this function such as attachment_ids,message_type,partner_ids,author_id,email_from,body etc.

This blog will show how we can post a message to the chatter. Apart from these normal cases, we can post a message when a product quantity is zero in the sale order form. Here we are using the ‘body’ argument to post messages in chatter.

Let’s see an example to post a message when a product is missing while it’s picked.

Here I am creating a sale order. And I’m using the delivery step as two steps as follows. So, when products are picked from the warehouse, whenever it is missing, they will be shown in the chatter by using the method “message_post”.

class StockPicking(models.Model):
   _inherit = "stock.picking"
   def button_validate(self):
       res = super(StockPicking, self).button_validate()
       for pick in self:
           warehouse_id = pick.picking_type_id.warehouse_id
           if warehouse_id and warehouse_id.delivery_steps:
               for move in pick.move_ids_without_package:
                   if move.product_uom_qty != move.quantity_done:
                       sale_order = self.env[
                           'sale.order'].search([])
                       for sl_order in sale_order:
                           if sl_order.name == pick.origin:
                               sale_order = sl_order
                               responsible_person = sale_order.user_id.name
                               break
                       display_msg = """ Dear """ + responsible_person + """,
                                      <br/>
                                      Please find the delivery deviation from
                                      the """ + sale_order.name + """
                                      <br/>
                                      <b>Missing Products:</b>
                                      <br/>
                                  """
                       for prod in move:
                           if prod.quantity_done == 0:
                               prod_id = self.env[
                                   'product.product'].browse(
                                   prod['product_id'])
                               display_msg += """ - """
                               display_msg += str(prod_id.id.name)
                               display_msg += """ <br/> """
                       sale_order.message_post(body=display_msg)
       return res

By using these codes, we can post the message in the chatter. Here the message_post and their arguments are used to show the message, as specified in the below piece of code.

display_msg = """ Dear """ + responsible_person + """,
              <br/>
              Please find the delivery deviation from
              the """ + sale_order.name + """
              <br/>
              <b>Missing Products:</b>
              <br/>
          """
for prod in move:
   if prod.quantity_done == 0:
       prod_id = self.env[
           'product.product'].browse(
           prod['product_id'])
       display_msg += """ - """
       display_msg += str(prod_id.id.name)
       display_msg += """ <br/> """
sale_order.message_post(body=display_msg)

Inside the ‘display_msg,” we can specify the message that we want to post the chatter and also specify the corresponding details. Here in the message, “responsible_person” and “sale_order.name” is specified, which are the corresponding responsible user and the sale order name.

Here we can see the delivery status. And we make products done quantity as zero. Validating the transfer without backorder. So the below screenshot is depicted as shown below.

how-to-post-a-message-to-chatter-in-odoo-15-cybrosys

After that, we can check our sale order status on the chatter. We can see the message that was posted on the chatter.

how-to-post-a-message-to-chatter-in-odoo-15-cybrosys

So this is how we post messages in chatter. To learn more about adding chatter in Odoo 15, you can move on to the video.

[wpcc-iframe src=”https://iframely.net/bYYORSl?_cc_load_policy=true&click_to_play=1″ style=”top: 0; left: 0; width: 100%; height: 100%; position: absolute; border: 0;” allowfullscreen=”” scrolling=”no” allow=”autoplay *; accelerometer *; clipboard-write *; encrypted-media *; gyroscope *; picture-in-picture *;”]

Similar Posts

Leave a Reply

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