From 7d558e55893820df1176eb9b5ec813632518fa14 Mon Sep 17 00:00:00 2001 From: David Cook Date: Mon, 25 Mar 2019 13:38:21 +1100 Subject: [PATCH] Bug 19014: Do not try to autorenew an item too early There are a number of conditions which can cause autorenewals to send out confusing notifications to patrons far before the due date of an item. These may be exceeding the max number of renewals or checkouts, a hold on the item, etc. If an item has a hold, we don't want to tell the patron they can't autorenew the item until the earliest renewal date or the due date of the item. Test plan: 1) Check out an item with a due date 2 business days in the future 2) Place a hold on this item 3) Execute the cronjob - Without the patch, an email notification is generated for the patron - With the patch, no email notification is generated 4) Set norenewalbefore in the Circulation and Fines rules to 2 5) Execute the cronjob - Without the patch, an email notification is generated for the person - With the patch, an email notification is generated for the person 6) Set norenewalbefore in the Circulation and Fines rules to 3 7) Execute the cronjob - Without the patch, an email notification is generated for the patron - With the patch, no email notification is generated 8) Clear norenewalbefore in the Circulation and Fines rules 9) Change item due date (in database) to a date/time prior to now 10) Execute the cronjob - Without the patch, an email notification is generated for the person - With the patch, an email notification is generated for the person --- misc/cronjobs/automatic_renewals.pl | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/misc/cronjobs/automatic_renewals.pl b/misc/cronjobs/automatic_renewals.pl index b50a6d565a..9000d64961 100755 --- a/misc/cronjobs/automatic_renewals.pl +++ b/misc/cronjobs/automatic_renewals.pl @@ -75,6 +75,21 @@ my $auto_renews = Koha::Checkouts->search({ auto_renew => 1 }); my %report; while ( my $auto_renew = $auto_renews->next ) { + #If norenewalbefore is undef, $NoRenewalBeforeThisDate will equal $now. + my $NoRenewalBeforeThisDate = C4::Circulation::GetSoonestRenewDate($auto_renew->borrowernumber, $auto_renew->itemnumber); + my $now = Koha::DateUtils::dt_from_string; + if ( $NoRenewalBeforeThisDate && $now ){ + if ( $NoRenewalBeforeThisDate > $now ){ + next; + } + else { + #Fallback: if norenewalbefore is undef, don't renew before due date + if ( Koha::DateUtils::dt_from_string( $auto_renew->date_due, 'sql' ) > $now ){ + next; + } + } + } + # CanBookBeRenewed returns 'auto_renew' when the renewal should be done by this script my ( $ok, $error ) = CanBookBeRenewed( $auto_renew->borrowernumber, $auto_renew->itemnumber ); if ( $error eq 'auto_renew' ) { -- 2.16.4