[FIX] odex_web_app: get all notifications (activity, message, followers)

This commit is contained in:
Samir Ladoui 2024-09-08 10:20:17 +01:00
parent 4b0f064343
commit c77053d27e
3 changed files with 70 additions and 0 deletions

View File

@ -3,3 +3,5 @@ from . import attendence_zone_config
from . import mail_thread
from . import access_token
from . import res_users
from . import mail_message
from . import mail_activity

View File

@ -0,0 +1,24 @@
from odoo import models, api
import re
class MailActivity(models.Model):
_inherit = 'mail.activity'
@api.model
def create(self, values):
activity_ids = super(MailActivity, self).create(values)
for activity_id in activity_ids:
# Build message content
notification_body = re.sub(r'<[^>]+>', '', activity_id.note.replace('<br>', '\n'))
# Send notifications
employee_id = self.env['hr.employee'].sudo().search([('user_id', '=', activity_id.user_id.id)])
if employee_id:
push_notify = employee_id.user_push_notification_web({
"title": activity_id.summary or activity_id.create_uid.name,
"body": notification_body,
"sound": "default"
})
return activity_ids

View File

@ -0,0 +1,44 @@
from odoo import models, api
import re
class Message(models.Model):
_inherit = 'mail.message'
@api.model_create_multi
def create(self, values_list):
mt_comment = self.env.ref('mail.mt_comment')
mt_note = self.env.ref('mail.mt_note')
messages = super(Message, self).create(values_list)
for message in messages.filtered(lambda r: r.subtype_id.id in (mt_comment.id, mt_note.id) and r.model != 'mail.channel'):
# Get partners that should receive the message
if message.subtype_id.id == mt_comment.id:
partner_ids = self.env['mail.followers'].sudo().search([
('res_model', '=', message.model),
('res_id', '=', message.res_id),
('partner_id', '!=', message.author_id.partner_id.id)
]).partner_id
elif message.subtype_id.id == mt_note.id:
partner_ids = message.partner_ids
else:
partner_ids = []
if len(partner_ids):
# Build message content
notification_body = re.sub(r'<[^>]+>', '', message.body.replace('<br>', '\n'))
attachments = len(message.attachment_ids)
if notification_body and attachments:
notification_body += '\n{} File(s)'.format(attachments)
elif attachments:
notification_body = '{} File(s)'.format(attachments)
# Send notifications
for employee_id in self.env['hr.employee'].sudo().search([('user_id', 'in', partner_ids.user_ids.ids)]):
push_notify = employee_id.user_push_notification_web({
"title": message.author_id.name,
"body": notification_body,
"sound": "default"
})
return messages