summaryrefslogtreecommitdiff
path: root/addons/test_mail/tests/test_mail_message.py
diff options
context:
space:
mode:
authorDidier (did) <did@odoo.com>2021-03-04 15:37:16 +0000
committerDidier (did) <did@odoo.com>2021-03-08 12:01:06 +0000
commit732e581f38e8f93f26892ac445493694933ff61a (patch)
tree621b93c3080457e4511f1802ba729a996f3c9b42 /addons/test_mail/tests/test_mail_message.py
parent50139783d6524ea5359d5d8e05ed7471fefc2def (diff)
[FIX] mail, test_mail: ensure thread name is up to date on message
When formatting a message, a message could be with an empty or obsolete record_name field. It's better to rely on the relation between the message and the thread and fetch the current thread name. task-2411715 closes odoo/odoo#63000 Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
Diffstat (limited to 'addons/test_mail/tests/test_mail_message.py')
-rw-r--r--addons/test_mail/tests/test_mail_message.py34
1 files changed, 34 insertions, 0 deletions
diff --git a/addons/test_mail/tests/test_mail_message.py b/addons/test_mail/tests/test_mail_message.py
index 74f8c358b11..8d384f7215b 100644
--- a/addons/test_mail/tests/test_mail_message.py
+++ b/addons/test_mail/tests/test_mail_message.py
@@ -27,6 +27,40 @@ class TestMessageValues(TestMailCommon):
cls.Message = cls.env['mail.message'].with_user(cls.user_employee)
@mute_logger('odoo.models.unlink')
+ def test_mail_message_format(self):
+ record1 = self.env['mail.test.simple'].create({'name': 'Test1'})
+ message = self.env['mail.message'].create([{
+ 'model': 'mail.test.simple',
+ 'res_id': record1.id,
+ }])
+ res = message.message_format()
+ self.assertEqual(res[0].get('record_name'), 'Test1')
+
+ record1.write({"name": "Test2"})
+ res = message.message_format()
+ self.assertEqual(res[0].get('record_name'), 'Test2')
+
+ @mute_logger('odoo.models.unlink')
+ def test_mail_message_format_access(self):
+ """
+ User that doesn't have access to a record should still be able to fetch
+ the record_name inside message_format.
+ """
+ company_2 = self.env['res.company'].create({'name': 'Second Test Company'})
+ record1 = self.env['mail.test.multi.company'].create({
+ 'name': 'Test1',
+ 'company_id': company_2.id,
+ })
+ message = record1.message_post(body='', partner_ids=[self.user_employee.partner_id.id])
+ # We need to flush and invalidate the ORM cache since the record_name
+ # is already cached from the creation. Otherwise it will leak inside
+ # message_format.
+ message.flush()
+ message.invalidate_cache()
+ res = message.with_user(self.user_employee).message_format()
+ self.assertEqual(res[0].get('record_name'), 'Test1')
+
+ @mute_logger('odoo.models.unlink')
def test_mail_message_values_no_document_values(self):
msg = self.Message.create({
'reply_to': 'test.reply@example.com',