Skip to content

Commit

Permalink
circulation: Made loan request start date to be configurable and vali…
Browse files Browse the repository at this point in the history
…dated at the backend
  • Loading branch information
sakshamarora1 authored and kpsherva committed Feb 19, 2024
1 parent 80b3f97 commit 5cdca97
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions invenio_app_ils/circulation/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@
ILS_CIRCULATION_NOTIFICATION_OVERDUE_REMINDER_INTERVAL = 3
#: The maximum duration of a loan request
ILS_CIRCULATION_LOAN_REQUEST_DURATION_DAYS = 60
#: Loan Request Offset Value
ILS_CIRCULATION_LOAD_REQUEST_OFFSET = 0
#: Period of time in days, before loans expire, for notifications etc.
ILS_CIRCULATION_LOAN_WILL_EXPIRE_DAYS = 7
#: Optional delivery methods when requesting a new loan. Set to empty object to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ def postload_checks(self, data, **kwargs):
start = arrow.get(data["request_start_date"]).date()
end = arrow.get(data["request_expire_date"]).date()
duration_days = current_app.config["ILS_CIRCULATION_LOAN_REQUEST_DURATION_DAYS"]
loan_request_offset = timedelta(days=current_app.config["ILS_CIRCULATION_LOAD_REQUEST_OFFSET"])
duration = timedelta(days=duration_days)

if end < start:
Expand All @@ -106,4 +107,12 @@ def postload_checks(self, data, **kwargs):
"request_expire_date": [message],
}
)
elif end - start < loan_request_offset:
message = "The request end date can only be {} days after the request start date.".format(loan_request_offset.days)
raise ValidationError(
{
"request_start_date": [message],
"request_expire_date": [message],
}
)
return data

0 comments on commit 5cdca97

Please sign in to comment.