Skip to content

Commit

Permalink
notifications: fix overdue without library open days
Browse files Browse the repository at this point in the history
* Does not send overdue notification if the library is closed between
  the end date and the processing date.
* Closes: rero#2303.

Co-Authored-by: Johnny Mariéthoz <Johnny.Mariethoz@rero.ch>
  • Loading branch information
jma committed Sep 1, 2021
1 parent b10e0cf commit a089f82
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
4 changes: 3 additions & 1 deletion rero_ils/modules/circ_policies/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"""API for manipulating Circulation policies."""
from __future__ import absolute_import, print_function

import math
import sys
from functools import partial

Expand Down Expand Up @@ -353,7 +354,8 @@ def get_reminders(self, reminder_type=DUE_SOON_REMINDER_TYPE, limit=None):
:param limit: the number of day limit. All reminders defined after
these limit will not be returned
"""
limit = limit or sys.maxsize
if limit is None:
limit = math.inf
for reminder in self.get('reminders', []):
if reminder.get('type') == reminder_type \
and reminder.get('days_delay') <= limit:
Expand Down
26 changes: 25 additions & 1 deletion tests/api/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,31 @@ def test_notifications_task(
notif_date = ciso8601.parse_datetime(notif.get('creation_date'))
assert notif_date.date() == datetime.today().date()

# test overdue notification
# -- test overdue notification --

# For this test, we simulate an overdue on Friday and the library is closed
# during the weekend. No notification should be generated.

# Friday
end_date = datetime(year=2021, month=1, day=22, tzinfo=timezone.utc)
loan['end_date'] = end_date.isoformat()
loan.update(loan, dbcommit=True, reindex=True)

# Process the notification during the weekend (Saturday)
process_date = datetime(year=2021, month=1, day=23, tzinfo=timezone.utc)
overdue_loans = list(get_overdue_loans(tstamp=process_date))
assert overdue_loans[0].get('pid') == loan_pid
create_notifications(types=[
NotificationType.OVERDUE
], tstamp=process_date)
flush_index(NotificationsSearch.Meta.index)
flush_index(LoansSearch.Meta.index)
# Should not be created
assert not loan.is_notified(NotificationType.OVERDUE, 1)
# Should not be sent
assert number_of_reminders_sent(
loan, notification_type=NotificationType.OVERDUE) == 0

# For this test, we will update the loan to simulate an overdue of 12
# days. With this delay, regarding the cipo configuration, only the first
# overdue reminder should be sent.
Expand Down

0 comments on commit a089f82

Please sign in to comment.