Copy a Chatter History from Sales to Delivery in Odoo

AJAY
December 11, 2023
chatter-in-odoo

Chatter is the main communication channel in most of the Odoo models. It allows you to talk to each other via internal comments that aren’t visible to anyone else. This allows you to easily communicate about workflow problems or progress.

Chatter also allows you to reach out to clients right away after sending an estimate or a sales order. This way, you can discuss the details right away and keep in touch.

You can also add users as followers. This means that you can start a chat with a user even if they aren’t actively interacting with you.

chatter-in-odoo

1) Send Message

This feature allows you to send a message to every user who has followed the document. This option supports template usage.

2) Reply

Any client who has read the document has the right to respond and their response will be sent to the conversation

3) Log Note

This is a conversation that takes place within the company and is kept private from the customer. It is great for tracking progress without giving the customer too many updates or starting a conversation with other employees that the customer doesn’t want to know about.

4) Schedule an Activity

This functionality allows you to schedule and assign an activity to users.

Attachments

This feature shows the total number of Attachments in the document.

Follow / Following

This feature lets you see if you are following a record or not; you can hover your cursor over a record to unfollow it.

Followers

This feature gives you a quick view of how many people are following the document; you can change the subscription status of the existing followers or add new followers.

In this blog post, I’m going to show you how to transfer Chatter History between models. Specifically, I’ll show you how to move your Chat History from your Sales module to your Inventory module. I’m using this example to make sure that both your Delivery area and your Sale module’s conversation histories are available to clients. I’m also adding a button action to this. You can also add this function via a server action, or any other appropriate method. Copy all elements from your “mail. message” model to your button action.

In the button action, set your “res id” to “sale. id” and your “model” to “sale.order.” When you copy these elements, substitute “res” with the new “delivery” id and “models” with “stock.picking.” Allow me to provide an example. Below is the code for inserting a button within 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]})

At the top of this screenshot, you can see a button labeled “Copy Chatter.” At the bottom, you can see three log histories: The first log history is the one where I created the sale order. The second log history is where I added the content to the log note. The last log history is the history of all the confirmed quotations. Now let’s look at what happens when you click on the copy chatter button on the sale form page.

We have copied the chatter from the sale module to the delivery (stock picking) form view as shown below.

The reason for the chatter copy between models is as follows:

You have the option to choose which chat messages you want to copy, and which you want to ignore, and now have access to all email and message IDs in the message_sales variable.

You can choose how you want the data to be returned, or which records you want to copy.

For example, let’s say a sale has many logs that you want to view. We got a lot of reactions to the emails that we sent to your clients. If we copy all those records to delivery, you’ll feel dizzy. Some of them should be similar to what you did in the Quote era.

You can see that there are a large number of logs in this sale order. If you just want to copy these activity log notes for delivery, you can modify the code as follows:

.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]}
chatter-in-odoo

Here, you can only see the activity log comment that has been copied from the record S00052 to deliver (stock. picking). You can also modify the code as needed.

"Unlock the Full Potential of Your Business with Odoo ERP!"

"Get a Cost Estimate for Your ERP Project, Absolutely FREE!"

Get a Free Quote

Leave a Reply

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