[FIX] mass_mailing: Fix when reply_model is Null

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) <std@odoo.com>
This commit is contained in:
dane@odoo.com
2023-06-05 11:49:47 +02:00
parent bafc5610b0
commit a954eb3196
2 changed files with 31 additions and 1 deletions
+1 -1
View File
@@ -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),
@@ -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': '<p>test</p>',
'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):