diff --git a/addons/mail/models/mail_thread.py b/addons/mail/models/mail_thread.py index 279631b4403..6f0fab85923 100644 --- a/addons/mail/models/mail_thread.py +++ b/addons/mail/models/mail_thread.py @@ -3347,7 +3347,7 @@ class MailThread(models.AbstractModel): :return: dictionary of values suitable for a create; """ mail_subject = message.subject - if not mail_subject and self: + if not mail_subject and self and hasattr(self, '_message_compute_subject'): mail_subject = self._message_compute_subject() if not mail_subject: mail_subject = message.record_name diff --git a/addons/test_mail/tests/test_mail_thread_internals.py b/addons/test_mail/tests/test_mail_thread_internals.py index de325bdfcb3..26b1b9b7166 100644 --- a/addons/test_mail/tests/test_mail_thread_internals.py +++ b/addons/test_mail/tests/test_mail_thread_internals.py @@ -405,35 +405,39 @@ class TestNoThread(MailCommon, TestRecipients): @users('employee') def test_message_notify(self): - """ Test notifying using model / res_id linking to a model not being - mail.thread enabled. """ + """ Test notifying on non-thread models, using MailThread as an abstract + class with model and res_id giving the record used for notification. + + Test default subject computation is also tested. """ test_record = self.env['mail.test.nothread'].create({ 'customer_id': self.partner_1.id, 'name': 'Not A Thread', }) - with self.assertPostNotifications([{ - 'content': 'Hello Paulo', - 'email_values': { - 'reply_to': self.company_admin.catchall_formatted, - 'subject': 'Test Notify', - }, - 'message_type': 'user_notification', - 'notif': [{ - 'check_send': True, - 'is_read': True, - 'partner': self.partner_2, - 'status': 'sent', - 'type': 'email', - }], - 'subtype': 'mail.mt_note', - }]): - _message = self.env['mail.thread'].message_notify( - body='

Hello Paulo

', - model=test_record._name, - partner_ids=self.partner_2.ids, - res_id=test_record.id, - subject='Test Notify', - ) + + for subject in ["Test Notify", False]: + with self.subTest(): + with self.assertPostNotifications([{ + 'content': 'Hello Paulo', + 'email_values': { + 'reply_to': self.company_admin.catchall_formatted, + }, + 'message_type': 'user_notification', + 'notif': [{ + 'check_send': True, + 'is_read': True, + 'partner': self.partner_2, + 'status': 'sent', + 'type': 'email', + }], + 'subtype': 'mail.mt_note', + }]): + _message = self.env['mail.thread'].message_notify( + body='

Hello Paulo

', + model=test_record._name, + partner_ids=self.partner_2.ids, + res_id=test_record.id, + subject=subject, + ) @users('employee') def test_message_notify_composer(self):