Discuss Messages

This commit is contained in:
Pranay 2025-05-20 10:02:59 +05:30
parent 07aaf675be
commit d69ca61bc9
2 changed files with 37 additions and 1 deletions

View File

@ -1,2 +1,3 @@
from . import hr_employee
from . import hr_leave
from . import hr_leave
from . import discuss

View File

@ -0,0 +1,35 @@
from logging import exception
from odoo import api, models, _, fields
from odoo.exceptions import ValidationError
from odoo.tools.misc import format_date
from datetime import datetime
from markupsafe import Markup
class DiscussChannel(models.Model):
_inherit = "discuss.channel"
def send_message_from_flutter_odoo(self,leave_request_data,message_type='notification'):
for rec in self:
attachments = leave_request_data.pop('attachments', [])
files = []
leave_request_data['body'] = Markup(leave_request_data['body'])
# rec.message_post(message_type,leave_request_data)
if attachments:
for att in attachments:
file = self.env['ir.attachment'].create({
'name': att['name'],
'type': 'binary',
'datas': att['datas'], # base64 string
'res_model': 'discuss.channel',
'res_id': rec.id,
})
files.append(file.id)
rec.message_post(
body=leave_request_data['body'],
message_type="comment",
subtype_xmlid="mail.mt_comment",
attachment_ids=files # ✅ correct way to pass existing attachments
)