From a954eb319658de7d75ff177986c074cc96616604 Mon Sep 17 00:00:00 2001 From: "dane@odoo.com" Date: Fri, 14 Apr 2023 16:57:35 +0000 Subject: [PATCH] [FIX] mass_mailing: Fix when reply_model is Null MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There exists edge case on `reply_model`. when value of `mail_messages.model` in database is empty then `mail_messages.model` returns False, hence `reply_model` becomes False which raises an error because _get_id does not accept a falsy values. (because query: `SELECT id FROM ir_model WHERE model=false` has to be run and model is char). Because of the fact that this query never runs and fails opportunity is lost. task-3248489 closes odoo/odoo#123488 X-original-commit: 6c0d2d7a9d44459f3e09a38bd80ef9b018e8c946 Signed-off-by: Stéphane Debauche (std) --- addons/mail/models/mail_thread.py | 2 +- addons/test_mail/tests/test_mail_gateway.py | 30 +++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/addons/mail/models/mail_thread.py b/addons/mail/models/mail_thread.py index 369b6803b21..3e388bcece2 100644 --- a/addons/mail/models/mail_thread.py +++ b/addons/mail/models/mail_thread.py @@ -1065,7 +1065,7 @@ class MailThread(models.AbstractModel): is_a_reply = False rcpt_tos_valid_localparts = [to for to in rcpt_tos_valid_localparts if to in other_model_aliases.mapped('alias_name')] - if is_a_reply: + if is_a_reply and reply_model: reply_model_id = self.env['ir.model']._get_id(reply_model) dest_aliases = self.env['mail.alias'].search([ ('alias_name', 'in', rcpt_tos_localparts), diff --git a/addons/test_mail/tests/test_mail_gateway.py b/addons/test_mail/tests/test_mail_gateway.py index 534dccef77c..32cfbdaed7c 100644 --- a/addons/test_mail/tests/test_mail_gateway.py +++ b/addons/test_mail/tests/test_mail_gateway.py @@ -1763,6 +1763,36 @@ class TestMailgateway(MailCommon): # This explains the multiple "�" in the attachment. self.assertIn("Chauss������e de Bruxelles", record.message_ids.attachment_ids.raw.decode()) + def test_message_route_reply_model_none(self): + """ + Test the message routing and reply functionality when the model is None. + + This test case verifies the behavior of the message routing and reply process + when the 'model' field of a mail.message is set to None. It checks that the + message is correctly processed and associated with the appropriate record. + The code invokes function `format_and_process` to automatically test rounting + and then makes checks on created record. + + """ + message = self.env['mail.message'].create({ + 'body': '

test

', + 'email_from': self.email_from, + 'message_type': 'email', + 'model': None, + 'res_id': None, + }) + + self.env['mail.alias'].create({'alias_name': 'test', 'alias_model_id': self.env['ir.model']._get('mail.test.gateway').id}) + record = self.format_and_process( + MAIL_TEMPLATE, self.email_from, 'test@test.com', + subject=message.message_id, extra=f'In-Reply-To:\r\n\t{message.message_id}\n', + model=None) + + self.assertTrue(record) + self.assertEqual(record._name, 'mail.test.gateway') + self.assertEqual(record.message_ids.subject, message.message_id) + self.assertFalse(record.message_ids.parent_id) + @tagged('mail_gateway') class TestMailThreadCC(MailCommon):