[FIX] mail: prevent to call _message_compute_subject outside of a thread model
While we run cron `Data Merge: Find Duplicate Records` an issue raises because `data_merge.model` has no method `_message_compute_subject`. Indeed it is possible to notify on non-thread models but that method is a thread-only method. In this commit, we only call `_message_compute_subject` when it's available in model. sentry-3947126655 Task-3254379 Part-of: odoo/odoo#117763
This commit is contained in:
committed by
Thibault Delavallée
parent
7d9035c79a
commit
2cc2690c8f
@@ -3347,7 +3347,7 @@ class MailThread(models.AbstractModel):
|
||||
:return: dictionary of values suitable for a <mail.mail> 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
|
||||
|
||||
@@ -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='<p>Hello Paulo</p>',
|
||||
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='<p>Hello Paulo</p>',
|
||||
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):
|
||||
|
||||
Reference in New Issue
Block a user