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) msg = 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 ) return msg.id