Chatter is the communication tool found in most of the models in Odoo. This enables you to communicate with customers immediately from a quote or sales order, for example, to negotiate details and stay in touch; employees can log in with invisible internal notes to alert each other about progress or issues in the workflow. Additionally, you can ping other users into a conversation by adding them as a follower, even if they are not actually involved.
1) Send Message: This function sends an email to all users who are currently following the document. This option supports the use of templates. Any customer who reads the document can respond, and their responses will be routed to the chatter.
2) Log Note: It is an activity for internal discussion that the customer does not see. This is great for keeping track of progress without giving too many updates to the customer or initiating a conversation with other employees that you don't want the customer to know about.
3) Schedule Activity: You can schedule and assign activities to users using this feature.
4) ??#: The number of attachments on this document is displayed.
5) Follow / Following: It reveals if you are following the document at a glance; if you do not wish to follow a record, hover over it and click Unfollow.
6) ??#: The number of followers on the document is displayed at a glance. You can add new Followers or change their subscription status for the item.
In this blog, I’ll show you how to copy a Chatter History from one model to another. Here I’m using it to copy the Chat History from the Sale module to the Delivery module. So your clients can see all the chat histories made in the Sale module, also in the Delivery area too.
Here I’m adding this feature from a button action. You may add this from a server action or the way that suits you.
To do so, copy all items from the "mail.message" model where the "res id" = sale.id and the "model" = "sale.order" to your button action. Change the "res id" to your new Delivery id and the "model" to "stock.picking" when duplicating these.
I’ll show you the Example:
Here is the code for adding a Button Inside the Sale Form View
.XML
<record id="view_order_form_inherit_chatter_copy_in_sale" model="ir.ui.view">
<field name="name">sale.order.form.inherit.copy.chatter.sale</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="arch" type="xml">
<xpath expr="//button[@name='action_draft']" position="after">
<button name="action_chatter_copy"
string="Copy Chatter" class="btn-primary" type="object"/>
</xpath>
</field>
</record>
Button action in Python is shown below.
.py
def action_chatter_copy(self):
messages_sale = self.env["mail.message"].search(["&", ("res_id", "=", self.id),
("model", "=", "sale.order")], order='create_date asc')
for chat in messages_sale:
delivery_id = [x.id for x in self.picking_ids.filtered(lambda l: l.state != 'cancel')]
chat.copy({"model": "stock.picking", "res_id": delivery_id[0]})
In the above screenshot you can see there is a button at the top named Copy Chatter. At the Bottom there are three log histories, First one is the Sale Order Created, and the Second One I added a log note text. And the last one is the Quotation Confirmed history.
So Let’s check what happens when we click on the Copy Chatter Button from the Sale form view.
Here you can see the Chatter from Sale module copied to Delivery(stock.picking) form view.
This is the basic logic behind the chatter copying from one model to another. You can also customize which chat messages need to copy or which are not want to copy. Every mail and message ids are now available in the message_sale variable. You can decide how the data is to return or which records need to be copied.
For example, If there are many logs available in a Sale for view. We got many replies to the mail that we sent to our customers. If we copy all the records to delivery, this will make you dizzy. So you want some of them to be like the activities you did during the Quote period.
In this sale order, you can see there are many logs in it. If you only want to copy the activity log notes to the Delivery area, You can change the code like this.
.PY
def action_chatter_copy(self):
messages_sale = self.env["mail.message"].search(["&", ("res_id", "=", self.id),("model", "=", "sale.order")], order='create_date asc')
delivery_id = [x.id for x in self.picking_ids.filtered(lambda l: l.state != 'cancel')]
for chat in messages_sale.filtered(lambda m: m.subtype_id.name == 'Activities'):
chat.copy({"model": "stock.picking", "res_id": delivery_id[0]})
Here you can see only the activity log note copied from S00026 record to delivery (stock.picking). You can also change the code as per your requirement. Here I have changed the line of this code. For chat on messages_sale.filtered (lambda m: m.subtype_id.name == 'Activities')
I have filtered the values in the “message_sale” variable here using the subtype_id of the mail.message model. Using the name ‘Activities,’ the filtered messages will iterate in the ‘chat’ variable. So we can copy the chat variable.