Skip to content

Commit

Permalink
[UPD] Remove an unnecessary condition that may lead to overcomplexity…
Browse files Browse the repository at this point in the history
… in real use cases
  • Loading branch information
nayatec committed Aug 22, 2024
1 parent 8f7b602 commit 229b7f7
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 39 deletions.
1 change: 1 addition & 0 deletions helpdesk_mgmt_reopen/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"summary": "Auto Helpdesk Reopen",
"license": "AGPL-3",
"author": "Odoo Community Association (OCA), OERP, Coop IT Easy SCRLfs, Akretion",
"maintainers": ["nayatec"],
"website": "https://github.com/OCA/helpdesk",
"depends": ["helpdesk_mgmt"],
"installable": True,
Expand Down
10 changes: 0 additions & 10 deletions helpdesk_mgmt_reopen/models/mail_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,12 @@
class MailMessage(models.Model):
_inherit = "mail.message"

def is_production_env(self):
"""Used to determine how we will treat comments.
It is useful because we can't (easily) mock
incoming emails in testing environnements
It needs to be implemented"""
return True

@api.model
def is_reopener_message(self, vals):
if not vals.get("model") == "helpdesk.ticket":
return False
if vals.get("message_type") == "notification":
return False
# We need to use comments in non-prod env for testing purposes
if self.is_production_env() and vals.get("message_type") == "comment":
return False
return True

@api.model
Expand Down
5 changes: 4 additions & 1 deletion helpdesk_mgmt_reopen/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
* `Akretion <https://www.akretion.com>`_:

* Olivier Nibart

* `Coop IT Easy <https://coopiteasy.be/>`_:

* Pierrick Brun


* JSC Boolit

* Andrius Laukavičius
11 changes: 1 addition & 10 deletions helpdesk_mgmt_reopen/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -1,10 +1 @@
This modules allows to get a ticket back to its first state when a message is
received about it.


When you are in a non-production environment, you can reopen the ticket with
a simple message as well. It is useful to test the module's function without
preparing a fake mail environment.

There is a function MailMessage.is_production_env() allowing to define how you
select if you are in production or not. (With a check on the URL for instance)
This module allows getting a ticket back to its initial state when a message is received about it, except if it is a notification.
20 changes: 2 additions & 18 deletions helpdesk_mgmt_reopen/tests/test_ticket_reopen.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# @author Olivier Nibart <[email protected]>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from unittest import mock

from odoo.tests.common import SavepointCase

Expand All @@ -29,7 +28,7 @@ def setUpClass(cls):
def test_is_reopener_message(self):
vals = {
"model": "not helpdesk.ticket",
"message_type": "not comment or notification",
"message_type": "not notification",
}
self.assertFalse(self.MailMessage.is_reopener_message(vals))
vals = {
Expand All @@ -39,22 +38,7 @@ def test_is_reopener_message(self):
self.assertFalse(self.MailMessage.is_reopener_message(vals))
vals = {
"model": "helpdesk.ticket",
"message_type": "comment",
}
# type comment in production is not a reopener
self.assertTrue(self.MailMessage.is_production_env())
self.assertFalse(self.MailMessage.is_reopener_message(vals))
# type comment not in production is a reopener
with mock.patch.object(
type(self.MailMessage),
"is_production_env",
return_value=False,
):
self.assertFalse(self.MailMessage.is_production_env())
self.assertTrue(self.MailMessage.is_reopener_message(vals))
vals = {
"model": "helpdesk.ticket",
"message_type": "not comment or notification",
"message_type": "not notification",
}
self.assertTrue(self.MailMessage.is_reopener_message(vals))

Expand Down

0 comments on commit 229b7f7

Please sign in to comment.