Enable Dark Mode!
how-to-transfer-chatter-history-from-sales-to-delivery-in-odoo-17.jpg
By: Prathyunnan R

How to Transfer Chatter History from Sales to Delivery in Odoo 17

Technical

Introduction

Chatter is a powerful communication tool embedded within Odoo, offering an integrated way to keep conversations organized within various business documents. Whether it’s tracking internal notes, customer communications, or scheduling tasks, Chatter enhances collaboration across teams. But what happens when you need to carry this conversation across different stages of a business process? For example, how can you ensure that the valuable context from a Sales Order is available when handling the associated Delivery Order?

This guide walks you through the process of copying Chatter history from the Sales module to the Delivery module in Odoo 17. This ensures that the flow of information is consistent and transparent, helping your team stay aligned throughout the sales and delivery processes.

How to Transfer Chatter History from Sales to Delivery in Odoo 17-cybrosys

Key Features of Chatter

1. Send Message: This feature lets you send an email to all followers of the document. It supports templates, and any replies from customers will be automatically added to the Chatter conversation.

2. Log Note: This option allows for internal discussions that remain hidden from customers. It's perfect for tracking progress without overwhelming customers with too many updates.

3. Schedule Activity: You can use this feature to schedule and assign tasks to different users.

4. Attachments: This section shows the number of attachments related to the document.

5. Follow / Following: This option indicates whether you're following a document. You can unfollow it by hovering over the option.

6. Followers: Displays the number of people following the document. You can also manage subscriptions for these followers.

Transferring Chatter History Between Models

Imagine a scenario where a Sales Order in Odoo progresses through various stages, eventually requiring a Delivery Order to be fulfilled. During the sales process, multiple internal notes, customer communications, and tasks are logged within Chatter. When the Sales Order reaches the delivery stage, it’s crucial for the warehouse or logistics team to have access to this history to understand any special instructions or customer preferences.

In this scenario, copying the Chatter history from the Sales module to the Delivery module ensures that no information is lost in transition, and the delivery team can execute their tasks with full context.

In this example, we'll add this functionality via a button action. However, it can also be implemented through a server action or any other method that suits your needs.

Step 1: Create a Button in the Sale Form View.

You will need to add a button in the Sales form view to trigger the action of copying the Chatter history. Below is the code snippet for adding the button:

<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
   <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>
</odoo>

Here’s how the button appears on the Sales Order page.

How to Transfer Chatter History from Sales to Delivery in Odoo 17-cybrosys

Step 2: Implement the Button Action in Python

The following Python code will execute the Chatter history transfer when the button is clicked:

from odoo import models

class SaleOrder(models.Model):
   """
       Inherits SaleOrder to add a method for copying Chatter messages
       to associated delivery orders.
       """
   _inherit = 'sale.order'
   def action_chatter_copy(self):
       """
       Copies Chatter messages from the sale order to the first
       non-cancelled delivery order.
       """
       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]})

When you click the "Copy Chatter" button, the Chatter history from the Sales module will be copied to the corresponding Delivery form view.

The image below displays the Chatter history from Sales Orders.

How to Transfer Chatter History from Sales to Delivery in Odoo 17-cybrosys

The image below displays the Chatter history that has been transferred from Sales to Delivery.

How to Transfer Chatter History from Sales to Delivery in Odoo 17-cybrosys

Customizing the Copy Logic

The above implementation copies all Chatter history from the Sales Order to the Delivery Order. However, there might be cases where you only want to transfer specific types of messages, such as internal notes or customer communications.

To achieve this, you can modify the Python code to filter the messages before copying them. For example, if you only want to copy the activity log notes to the Delivery module, you can modify the Python code as follows:

def action_chatter_copy(self):
   """Copies Chatter messages of subtype 'Activities' from the Sales Order to the first non-canceled Delivery Order.
  
       The method retrieves and copies messages from the Sales Order to the associated Delivery Order (`stock.picking`).
       Only messages of subtype 'Activities' are transferred.
   """
   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]})

* Filtering Messages: The .filtered method is used to select only the messages that match the specified criteria, in this case, messages categorized as "Activities".

This code will ensure that only activity log notes are copied over to the Delivery section, allowing you to maintain a clean and relevant history.

The image below displays the log messages in the Sales module.

How to Transfer Chatter History from Sales to Delivery in Odoo 17-cybrosys

The transferred activity log note in the Delivery Order is shown below.

How to Transfer Chatter History from Sales to Delivery in Odoo 17-cybrosys

This customization allows you to tailor the Chatter history transfer process to meet the specific needs of your business.

Copying Chatter history from Sales to Delivery in Odoo can streamline communication and ensure consistency across different modules. By implementing the above steps, you can easily replicate this functionality in your Odoo 17 environment and customize it to fit your business needs.

To read more about How to Copy a Chatter History From Sales to Delivery in Odoo 16, refer to our blog How to Copy a Chatter History From Sales to Delivery in Odoo 16.


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



0
Comments



Leave a comment



whatsapp
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