Enable Dark Mode!
how-to-create-send-messages-to-channels-on-the-odoo-15-discuss-module.jpg
By: Aswathi C

How to Create & Send Messages to Channels on the Odoo 15 Discuss Module

Technical Odoo 15 Odoo Apps

Odoo Discuss module provides an effective communication mechanism for its users to send messages. The Discuss module has features to manage private messages and group messages. Since the Discuss module is integrated with other modules in Odoo, we can send messages or chat from any other module in Odoo. In this blog, we are discussing how we can create discuss channels in Odoo and how we can create and send messages to discuss channels programmatically.

1. How to create Discuss channels in Odoo

To create a discuss channel, at first we need to create an XML file custom_channels.xml inside the data folder in our custom module. After creating the XML file, add the following code to create channels to custom_channels.xml.

<record model="mail.channel" id="channel_id">
   <field name="name">Channel name</field>
   <field name="description">Description for channel.</field>
   <field name="public">Privacy for channel</field>
   <field name="group_public_id" ref="Group - Authorized to add members to channel"/>
   <field name="group_ids" eval="Group - members automatically added to channel"/>
</record>

Here is an example of creating a channel on the Discuss module to notify the users when they are assigned a task.

<record model="mail.channel" id="channel_task_assignees">
   <field name="name">Task Announcements</field>
   <field name="description">General announcements for all tasks.</field>
   <field name="public">groups</field>
  <field name="group_public_id" ref="project.group_project_manager"/>
<field name="group_ids" eval="[Command.link(ref('project.group_project_manager'))]"/>
</record>

The result of the above code is shown below:

how-to-create-send-messages-to-channels-on-the-odoo-15-discuss-module-cybrosys

description The description for the channel.

public To manage the people who can send and receive messages to the channels. The possible values for the public are public, private, and groups.

public: Everyone can see the messages and send messages to this channel.

private: Only the invited users can see and send messages to this channel

groups: By giving groups you can set a group of users who get the authorization to add members to this channel.

group_ids Members of this group are added automatically to the channel.

group_public_id Set a group of users who has access to add the members to the channel.

2. How to create and send group messages.

After creating a channel, we can send messages programmatically to the channel from any module.

notification_ids = [((0, 0, {
   'res_partner_id': user.partner_id.id,
   'notification_type': 'inbox'}))]

res_partner_id - The receiver of the message.

notification_type - The type of notification, ‘inbox’’ for notification in the discuss module.

The above code is used to show the number of incoming messages in the Inbox of the discuss module. The result of the above code will be as shown below:

how-to-create-send-messages-to-channels-on-the-odoo-15-discuss-module-cybrosys

By using message_post() method you can send messages to discuss the module. For example, if we need to send messages to the created channel when a user is assigned to the task (at the time of task creation on Project). Below is the code for the same.

notification_ids = [((0, 0, {
   'res_partner_id': user.partner_id.id,
   'notification_type': 'inbox'}))]
user_id = self.env.user.id
message = ("You have a assigned a task %s") % (vals_list[0]["name"])
channel_id.message_post(author_id=user_id,
                       body=(message),
                       message_type='notification',
                       subtype_xmlid="mail.mt_comment",
                       notification_ids=notification_ids,
                       partner_ids=[user.id],
                       notify_by_email=False,
                       )

The result of the above code is as follows:

how-to-create-send-messages-to-channels-on-the-odoo-15-discuss-module-cybrosyshow-to-create-send-messages-to-channels-on-the-odoo-15-discuss-module-cybrosys

author_id - User who created the message.

Body - Body of the message.

Message_type - Message type can be ‘notification’ or ‘comment’.

Partner_ids - List of users who want to be sent the message.

notify_by_email - If it is True, the message will be sent as an email to the user, or if it is False,  the message will not be sent as an email to the user. The default value of notify_by_email is True.

3. How to create and send private messages.

We can create and send private messages by using the below code.

channel = self.env['mail.channel'].channel_get(
   [user.partner_id.id])
channel_id = self.env['mail.channel'].browse(channel["id"])
channel_id.message_post(
   body=(message),
   message_type='comment',
   subtype_xmlid='mail.mt_comment',
)

The above code will show a result as shown below.

how-to-create-send-messages-to-channels-on-the-odoo-15-discuss-module-cybrosys

how-to-create-send-messages-to-channels-on-the-odoo-15-discuss-module-cybrosys

Hope that you guys get the basic idea of creating channels and sending messages to the discuss channels.


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



0
Comments



Leave a comment

 


whatsapp_icon
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