[FIX] mail: take all messages into account on unlink
Current behavior : When you delete a record (for example project.task), all the messages related to this record aren't deleted. This, in case a user has his notifications managed in Odoo, may prevent him from accessing the History tab in the Discuss app because these messages are linked to a record that doesn't exist anymore and it will raise a Missing Record error Steps : *with demo data* - Install Project - Make Marc Demo notifications managed in Odoo - Delete a task project to which Marc Demo is assigned (*with Marc Demo*) - Go to Discuss and try to access History tab OPW-2764855 closes odoo/odoo#87732 X-original-commit: ee8feeb73c920827090b1a5ecf78e8b1d21bbae4 Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com> Signed-off-by: Claude Thibault (thcl) <thcl@odoo.com>
This commit is contained in:
@@ -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)]
|
||||
|
||||
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user