Enable Dark Mode!
By: Saneen K

How to Copy a Chatter History From Sales to Delivery in Odoo 16

Technical Odoo 16 Sales

Chatter is the main form of communication in the majority of Odoo models. Invisible internal comments allow users to log in and communicate with one another regarding workflow issues or progress. This makes it possible for you to contact clients right away after sending them an estimate or sales order, for instance, to work out the specifics and stay in touch. Users can also be added as followers, so you can ping them into a chat even if they aren't participating.

How to Copy a Chatter History From Sales to Delivery in Odoo 16-cybrosys

1) Send Message: Using this feature, you can email every user following the document. Template usage is supported by this option. Any client who reads the document has the option to respond, and their comments will be forwarded to the conversation.

2) Log Note: It's a conversation that only takes place internally and is hidden from the customer. This is fantastic for tracking progress without providing the customer with excessive updates or starting a dialogue with other employees that you don't want the customer to hear about.

3) Schedule an Activity: Using this functionality, you may schedule and assign activities to users. 

4) Attachments: Displays the total number of attachments in this document.

5) Follow / Following: This feature lets you quickly see whether you are following a certain record; to unfollow a record, hover your cursor over it.

6) Followers: A quick view reveals how many people have followed the document. You can modify the subscription status of existing Followers or add new ones.

How to Copy a Chatter History From Sales to Delivery in Odoo 16-cybrosys

This blog post will show you how to replicate a Chatter History from one model to another. To move the Chat History from the Sale module to the Inventory module, in this case, I'm using it. So that both the Delivery area and the Sale module's conversation histories are visible to your clients.

In this case, I'm adding this function via a button action. This can be added using a server action or any other method that works for you.

To do this, copy every element from the "mail.message" model to the button action where the "res id" is sale.id and the "model" = "sale.order." Replace "res id" with your new Delivery id and "model" with "stock.picking" when copying these.

I'll provide an example.

Here is the code for inserting a button inside the sale form view.


<record id="view_order_form_inherit_chatter_copy_in_sale"
        <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"

Button action in Python is shown below.


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]})

How to Copy a Chatter History From Sales to Delivery in Odoo 16-cybrosys

You can notice a button labeled Copy Chatter at the top of the screenshot over there. There are three log histories at the bottom; the first is the creation of the sale order, and the second is where I put the log note content. The history of the confirmed quotations comes last.

Let's examine what occurs when the Copy Chatter button is clicked on the Sale form page.

How to Copy a Chatter History From Sales to Delivery in Odoo 16-cybrosys

The Chatter from the Sale module has been copied to the Delivery (stock.picking) form view, as seen here.

Following is the basic reasoning for the chatter copying between models.

Additionally, you can decide which chat messages to copy and which to ignore. The message_sale variable now has access to all mail and message IDs. You can choose how the data should be returned or which records need to be copied. 

For instance, imagine that a sale has a lot of logs that may be viewed. We received a lot of responses to the emails we sent to our clients. This will make you feel dizzy if we copy all the records to delivery. Consequently, some of them ought to be similar to the things you did during the Quote era.

How to Copy a Chatter History From Sales to Delivery in Odoo 16-cybrosys

As you can see, this sale order contains a sizable number of logs. If you only want to copy the activity log notes to the delivery area, you can change the code in this way.


 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]}

How to Copy a Chatter History From Sales to Delivery in Odoo 16-cybrosys

Only the activity log remark that was copied from the S00052 record to delivery (stock.picking) is visible here. You can also alter the code to suit your needs. I've modified this code's line here. With regard to chat on messages_sale.filtered (lambda m: m.subtype_id.name == 'Activities'),

I have filtered the values in the "message_sale" variable using the subtype_id of the mail.message model. The "chat" variable will iterate the filtered messages under the heading "Activities." So we can duplicate the chat variable.

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


Leave a comment




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



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



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

Send Us A Message