From ece10e6a2ed1d95338b78ddbb03538fb6fb58f9e Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 7 Aug 2017 13:55:11 -0300 Subject: [PATCH] Bug 19014: Do not sent on_reserve notification if the checkout is due in the future If holds exist on an item that have been checked out and marked as auto renewal, we do not want to notify patrons with a on_reserve notification if the checkout is due in the future. These on_reserve notifications must only be sent if the checkout is due today or in the past. Test plan: - Check an item in and mark it as auto renewal, use a due date in the past to ease the testing - Place a hold in this item - Execute the cronjob => Without this patch, the patron will get notified even if the checkout is due in the future => With this patch applied the patron will only get notified the day the checkout is due or if the due date is passed --- misc/cronjobs/automatic_renewals.pl | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/misc/cronjobs/automatic_renewals.pl b/misc/cronjobs/automatic_renewals.pl index 190630149f..3f5d480c12 100755 --- a/misc/cronjobs/automatic_renewals.pl +++ b/misc/cronjobs/automatic_renewals.pl @@ -56,6 +56,7 @@ use C4::Circulation; use C4::Context; use C4::Log; use C4::Letters; +use Koha::DateUtils qw( dt_from_string ); use Koha::Checkouts; use Koha::Libraries; use Koha::Patrons; @@ -71,6 +72,7 @@ pod2usage(0) if $help; cronlogaction(); my $auto_renews = Koha::Checkouts->search({ auto_renew => 1 }); +my $today = dt_from_string; my %report; while ( my $auto_renew = $auto_renews->next ) { @@ -89,6 +91,10 @@ while ( my $auto_renew = $auto_renews->next ) { or $error eq 'auto_too_much_oweing' or $error eq 'auto_too_soon' ) { if ( not $auto_renew->auto_renew_error or $error ne $auto_renew->auto_renew_error ) { + next # Do not notify 'on_reserve' if the due date is later than today + if $error eq 'on_reserve' + and $today->truncate( to => 'day' ) < dt_from_string( $auto_renew->date_due, 'sql' )->truncate( to => 'day' ); + $auto_renew->auto_renew_error($error)->store; push @{ $report{ $auto_renew->borrowernumber } }, $auto_renew if $error ne 'auto_too_soon'; # Do not notify if it's too soon -- 2.11.0