Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16][FIX] helpdesk_mgmt: send confirmation mail at ticket creation from mail #616

Open
wants to merge 2 commits into
base: 16.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions helpdesk_mgmt/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
from . import res_config_settings
from . import res_partner
from . import res_users
from . import mail_thread
16 changes: 16 additions & 0 deletions helpdesk_mgmt/models/mail_thread.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright 2024 Akretion (https://www.akretion.com).
# @author Kévin Roche <kevin.roche@akretion.com>

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)
72 changes: 72 additions & 0 deletions helpdesk_mgmt/tests/test_helpdesk_ticket.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import time

from odoo.addons.test_mail.tests.test_mail_gateway import MAIL_TEMPLATE

from .common import TestHelpdeskTicketBase


Expand Down Expand Up @@ -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="<test@example.com>",
),
)

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