2021-04-27 16:44:12 +02:00
|
|
|
# Copyright 2021 Creu Blanca
|
|
|
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
2022-06-03 20:11:15 +02:00
|
|
|
|
2022-10-04 17:33:01 +02:00
|
|
|
import re
|
|
|
|
|
2021-04-27 16:44:12 +02:00
|
|
|
from odoo.tests import TransactionCase
|
|
|
|
|
|
|
|
|
|
|
|
class TestMessageReply(TransactionCase):
|
|
|
|
def test_reply(self):
|
2022-06-03 20:10:54 +02:00
|
|
|
partner = self.env["res.partner"].create({"name": "demo partner"})
|
2021-04-27 16:44:12 +02:00
|
|
|
self.assertFalse(
|
2022-06-03 20:10:54 +02:00
|
|
|
partner.message_ids.filtered(lambda r: r.message_type != "notification")
|
2021-04-27 16:44:12 +02:00
|
|
|
)
|
2022-06-03 20:11:15 +02:00
|
|
|
# pylint: disable=C8107
|
2022-06-03 20:10:54 +02:00
|
|
|
message = partner.message_post(body="demo message", message_type="email")
|
2021-04-27 16:44:12 +02:00
|
|
|
partner.refresh()
|
|
|
|
self.assertIn(
|
|
|
|
message,
|
2022-06-03 20:10:54 +02:00
|
|
|
partner.message_ids.filtered(lambda r: r.message_type != "notification"),
|
|
|
|
)
|
|
|
|
self.assertFalse(
|
2021-04-27 16:44:12 +02:00
|
|
|
partner.message_ids.filtered(
|
2022-06-03 20:10:54 +02:00
|
|
|
lambda r: r.message_type != "notification" and r != message
|
|
|
|
)
|
2021-04-27 16:44:12 +02:00
|
|
|
)
|
|
|
|
action = message.reply_message()
|
2022-06-03 20:10:54 +02:00
|
|
|
wizard = (
|
2022-10-04 17:33:01 +02:00
|
|
|
self.env[action["res_model"]].with_context(**action["context"]).create({})
|
2022-06-03 20:10:54 +02:00
|
|
|
)
|
2022-10-04 17:33:01 +02:00
|
|
|
# the onchange in the composer isn't triggered in tests, so we check for the
|
|
|
|
# correct quote in the context
|
|
|
|
email_quote = re.search("<p>.*?</p>", wizard._context["quote_body"]).group()
|
|
|
|
self.assertEqual("<p>demo message</p>", email_quote)
|
2021-04-27 16:44:12 +02:00
|
|
|
wizard.action_send_mail()
|
|
|
|
new_message = partner.message_ids.filtered(
|
2022-06-03 20:10:54 +02:00
|
|
|
lambda r: r.message_type != "notification" and r != message
|
2021-04-27 16:44:12 +02:00
|
|
|
)
|
|
|
|
self.assertTrue(new_message)
|
|
|
|
self.assertEqual(1, len(new_message))
|