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.0] [FIX] helpdesk_ticket_close_inactive: Send warning notification only once #672

Merged
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
8 changes: 5 additions & 3 deletions helpdesk_ticket_close_inactive/models/helpdesk_ticket_team.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Copyright 2024 APSL-Nagarro - Miquel Alzanillas
import logging
from datetime import datetime, timedelta
from datetime import datetime, time, timedelta

from odoo import fields, models

Expand Down Expand Up @@ -83,6 +83,8 @@ def close_team_inactive_tickets(self):
warning_limit = datetime.today() - timedelta(
days=team_id.inactive_tickets_day_limit_warning
)
warning_limit_day_first_hour = datetime.combine(warning_limit, time.min)
warning_limit_day_last_hour = datetime.combine(warning_limit, time.max)
closing_limit = datetime.today() - timedelta(
days=team_id.inactive_tickets_day_limit_closing
)
Expand All @@ -96,8 +98,8 @@ def close_team_inactive_tickets(self):
("team_id", "=", team_id.id),
("stage_id", "in", ticket_stage_ids),
("category_id", "in", ticket_category_ids),
("last_stage_update", "<=", warning_limit),
("last_stage_update", ">", closing_limit),
("last_stage_update", ">=", warning_limit_day_first_hour),
("last_stage_update", "<=", warning_limit_day_last_hour),
]
)
warning_email_ids = []
Expand Down
6 changes: 3 additions & 3 deletions helpdesk_ticket_close_inactive/tests/test_ticket_autoclose.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ def setUp(self):
"stage_id": self.stage_warning.id,
"category_id": self.type_warning.id,
"description": "Please help me",
"last_stage_update": datetime.today() - timedelta(days=8),
"last_stage_update": datetime.today() - timedelta(days=7),
}
)

def test_warning_email_sent(self):
"""Test that a warning email is sent after the warning day limit is reached."""
self.ticket.write({"last_stage_update": datetime.today() - timedelta(days=8)})
self.ticket.write({"last_stage_update": datetime.today() - timedelta(days=7)})
result = self.team.close_team_inactive_tickets()
sent_mails = self.env["mail.mail"].search(
[("id", "in", result["warning_email_ids"])]
Expand Down Expand Up @@ -72,7 +72,7 @@ def test_closing_email_sent(self):

def test_remaining_days_in_context(self):
"""Test that the correct remaining days are set in the context for the warning email."""
self.ticket.write({"last_stage_update": datetime.today() - timedelta(days=8)})
self.ticket.write({"last_stage_update": datetime.today() - timedelta(days=7)})
result = self.team.close_team_inactive_tickets()
sent_mail = self.env["mail.mail"].search(
[("id", "in", result["warning_email_ids"])], limit=1
Expand Down
Loading