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):