diff --git a/addons/mail/models/mail_thread.py b/addons/mail/models/mail_thread.py index 4390c6fc82b..a28122f38cc 100644 --- a/addons/mail/models/mail_thread.py +++ b/addons/mail/models/mail_thread.py @@ -312,7 +312,7 @@ class MailThread(models.AbstractModel): return True # discard pending tracking self._track_discard() - self.env['mail.message'].search([('model', '=', self._name), ('res_id', 'in', self.ids)]).sudo().unlink() + self.env['mail.message'].sudo().search([('model', '=', self._name), ('res_id', 'in', self.ids)]).unlink() res = super(MailThread, self).unlink() self.env['mail.followers'].sudo().search( [('res_model', '=', self._name), ('res_id', 'in', self.ids)] diff --git a/addons/test_mail/tests/test_mail_thread_internals.py b/addons/test_mail/tests/test_mail_thread_internals.py index 56b9258070a..8a28bfbe37a 100644 --- a/addons/test_mail/tests/test_mail_thread_internals.py +++ b/addons/test_mail/tests/test_mail_thread_internals.py @@ -8,7 +8,7 @@ from werkzeug.urls import url_parse, url_decode from odoo import exceptions from odoo.addons.test_mail.models.test_mail_models import MailTestSimple from odoo.addons.test_mail.tests.common import TestMailCommon, TestRecipients -from odoo.tests.common import tagged, HttpCase +from odoo.tests.common import tagged, HttpCase, users from odoo.tools import mute_logger @@ -260,6 +260,23 @@ class TestDiscuss(TestMailCommon, TestRecipients): threads_admin = self.test_record.with_user(self.user_admin).search([('message_has_error', '=', True)]) self.assertEqual(len(threads_admin), 0) + @users("employee") + def test_unlink_notification_message(self): + channel = self.env['mail.channel'].create({'name': 'testChannel'}) + channel.message_notify( + body='test', + message_type='user_notification', + partner_ids=[self.partner_2.id], + author_id=2 + ) + + channel_message = self.env['mail.message'].sudo().search([('model', '=', 'mail.channel'), ('res_id', 'in', channel.ids)]) + self.assertEqual(len(channel_message), 1, "Test message should have been posted") + + channel.unlink() + remaining_message = channel_message.exists() + self.assertEqual(len(remaining_message), 0, "Test message should have been deleted") + @tagged('-at_install', 'post_install') class TestMultiCompany(HttpCase):