From ed7a1644e13ffca00af86dcf2c64dac59ee2dbdb Mon Sep 17 00:00:00 2001 From: Kev-Roche Date: Sat, 31 Aug 2024 19:24:37 +0200 Subject: [PATCH 1/2] [FIX] add tests send confirmation mail at ticket creation from mail --- helpdesk_mgmt/tests/test_helpdesk_ticket.py | 72 +++++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/helpdesk_mgmt/tests/test_helpdesk_ticket.py b/helpdesk_mgmt/tests/test_helpdesk_ticket.py index abc4ced815..b1e14e400c 100644 --- a/helpdesk_mgmt/tests/test_helpdesk_ticket.py +++ b/helpdesk_mgmt/tests/test_helpdesk_ticket.py @@ -1,5 +1,7 @@ import time +from odoo.addons.test_mail.tests.test_mail_gateway import MAIL_TEMPLATE + from .common import TestHelpdeskTicketBase @@ -131,3 +133,73 @@ def test_ticket_without_team(self): } ) self.assertEqual(self.new_stage, new_ticket.stage_id) + + def test_create_ticket_with_mail_template(self): + new_stage = self.env.ref("helpdesk_mgmt.helpdesk_ticket_stage_new") + new_stage.team_ids = [(6, 0, [self.team_a.id])] + new_stage.mail_template_id = self.env.ref( + "helpdesk_mgmt.closed_ticket_template" + ) + ticket = self.env["helpdesk.ticket"].create( + { + "name": "I'm a robot, hello", + "team_id": self.team_a.id, + "stage_id": new_stage.id, + "description": "Description", + } + ) + ticket_good_reception = ticket.message_ids.filtered( + lambda m: m.message_type == "email" + ) + self.assertIn("closed", ticket_good_reception.subject) + + def test_create_ticket_from_alias_mail(self): + server = self.env["fetchmail.server"].create( + { + "name": "Demo server", + "server_type": "pop", + "server": "pop3.example.com", + } + ) + self.env["mail.alias"].create( + { + "alias_name": "team_a_alias", + "alias_model_id": self.env.ref( + "helpdesk_mgmt.model_helpdesk_ticket" + ).id, + "alias_contact": "everyone", + "alias_defaults": {"team_id": self.team_a.id}, + "alias_parent_model_id": self.env.ref( + "helpdesk_mgmt.model_helpdesk_ticket_team" + ).id, + } + ) + new_stage = self.env.ref("helpdesk_mgmt.helpdesk_ticket_stage_new") + new_stage.team_ids = [(6, 0, [self.team_a.id])] + new_stage.mail_template_id = self.env.ref( + "helpdesk_mgmt.closed_ticket_template" + ) + email = "from@me.com" + + self.env["mail.thread"].with_context( + default_fetchmail_server_id=server.id + ).message_process( + server.object_id.model, + MAIL_TEMPLATE.format( + return_path=email, + email_from=email, + to="team_a_alias@example.com", + cc="team_aa_alias@example.com", + subject="Hello Ticket", + extra="", + msg_id="", + ), + ) + + ticket = self.env["helpdesk.ticket"].search([("name", "=", "Hello Ticket")]) + self.assertEqual(len(ticket.message_ids), 2) + ticket_good_reception = ticket.message_ids.filtered( + lambda m: m.message_type == "email" and m.email_from != email + ) + self.assertEqual(len(ticket_good_reception), 1) + self.assertIn("closed", ticket_good_reception.subject) From 9231818e55c39cfe3738e88a164ecdaddb3a01fc Mon Sep 17 00:00:00 2001 From: Kev-Roche Date: Sat, 31 Aug 2024 19:34:40 +0200 Subject: [PATCH 2/2] [16.0][FIX] send confirmation mail at ticket creation from mail --- helpdesk_mgmt/models/__init__.py | 1 + helpdesk_mgmt/models/mail_thread.py | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 helpdesk_mgmt/models/mail_thread.py diff --git a/helpdesk_mgmt/models/__init__.py b/helpdesk_mgmt/models/__init__.py index 3b424dca17..082642c599 100644 --- a/helpdesk_mgmt/models/__init__.py +++ b/helpdesk_mgmt/models/__init__.py @@ -9,3 +9,4 @@ from . import res_config_settings from . import res_partner from . import res_users +from . import mail_thread diff --git a/helpdesk_mgmt/models/mail_thread.py b/helpdesk_mgmt/models/mail_thread.py new file mode 100644 index 0000000000..d86c7f62f8 --- /dev/null +++ b/helpdesk_mgmt/models/mail_thread.py @@ -0,0 +1,16 @@ +# Copyright 2024 Akretion (https://www.akretion.com). +# @author Kévin Roche + +from odoo import models + + +class MailThread(models.AbstractModel): + _inherit = "mail.thread" + + def _message_track_post_template(self, changes): + if ( + self._context.get("default_fetchmail_server_id") + and self._name == "helpdesk.ticket" + ): + changes.append("stage_id") + return super()._message_track_post_template(changes)