diff --git a/helpdesk_ticket_close_inactive/models/helpdesk_ticket_team.py b/helpdesk_ticket_close_inactive/models/helpdesk_ticket_team.py index bda2b1f22a..78d914211c 100644 --- a/helpdesk_ticket_close_inactive/models/helpdesk_ticket_team.py +++ b/helpdesk_ticket_close_inactive/models/helpdesk_ticket_team.py @@ -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 @@ -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 ) @@ -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 = [] diff --git a/helpdesk_ticket_close_inactive/tests/test_ticket_autoclose.py b/helpdesk_ticket_close_inactive/tests/test_ticket_autoclose.py index 03e8287eb4..9d38801466 100644 --- a/helpdesk_ticket_close_inactive/tests/test_ticket_autoclose.py +++ b/helpdesk_ticket_close_inactive/tests/test_ticket_autoclose.py @@ -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"])] @@ -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