You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

58 lines
2.4 KiB

# -*- coding: utf-8 -*-
#############################################################################
#
# Cybrosys Technologies Pvt. Ltd.
#
# Copyright (C) 2024-TODAY Cybrosys Technologies(<https://www.cybrosys.com>)
# Author: Cybrosys Techno Solutions(<https://www.cybrosys.com>)
#
# You can modify it under the terms of the GNU LESSER
# GENERAL PUBLIC LICENSE (LGPL v3), Version 3.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details.
#
# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE
# (LGPL v3) along with this program.
# If not, see <http://www.gnu.org/licenses/>.
#
#############################################################################
from odoo import fields, models
class ResUsers(models.Model):
""" Inheriting the res users model to read all messages"""
_inherit = 'res.users'
def action_read_messages(self):
"""Read all Messages"""
partner_id = self.env.user.partner_id.id
# Cancel exception notifications
exception_notifications = self.env['mail.notification'].sudo().search([
('notification_status', '=', 'exception'),
])
exception_notifications.write({'notification_status': 'canceled'})
# Mark unread notifications as read
unread_notifications = self.env['mail.notification'].sudo().search([
('res_partner_id', '=', partner_id),
('is_read', '=', False)
])
unread_notifications.write({'is_read': True})
# Reading the messages from the channels.
channel_members = self.env['mail.channel.member'].search([
('partner_id', '=', self.env.user.partner_id.id)
])
# Fetch the latest message
latest_message = self.env['mail.message'].search([
('model', '=', 'mail.channel'),
('message_type', 'not in', ['notification', 'user_notification']),
('id', '>', max(channel_members.mapped('seen_message_id.id') or [0]))
], limit=1, order='id desc')
if latest_message:
channel_members.write({
'seen_message_id': latest_message.id,
'fetched_message_id': latest_message.id,
'last_seen_dt': fields.Datetime.now(),
})