Skip to content

Commit

Permalink
notifications: fix overdue with no lib open days
Browse files Browse the repository at this point in the history
* 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 b5098e3
Show file tree
Hide file tree
Showing 2 changed files with 20 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
18 changes: 17 additions & 1 deletion tests/api/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,23 @@ 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

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_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)
assert not loan.is_notified(NotificationType.OVERDUE, 1)
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 b5098e3

Please sign in to comment.