@@ -, +, @@ before' and 'Automatic renewal'. Both daily and hourly loans should work. before and after a renewal should be possible. * Both automatic and manual renewal with 'No renewal before' set to 0 do not happen before the due date (exact DateTime). * Manual renewal with 'No renewal before' set to undef (enter empty string) is unrestricted. * Automatic renewal with 'No renewal before' set to undef does not happen before the due date. --- C4/Circulation.pm | 18 +++++++++++++++--- admin/smart-rules.pl | 2 +- 2 files changed, 16 insertions(+), 4 deletions(-) --- a/C4/Circulation.pm +++ a/C4/Circulation.pm @@ -2737,7 +2737,7 @@ sub CanBookBeRenewed { return ( 0, "too_many" ) if $issuingrule->{renewalsallowed} <= $itemissue->{renewals}; - if ( $issuingrule->{norenewalbefore} ) { + if ( defined $issuingrule->{norenewalbefore} ) { # Get current time and add norenewalbefore. # If this is smaller than date_due, it's too soon for renewal. @@ -2750,9 +2750,21 @@ sub CanBookBeRenewed { return ( 0, "auto_too_soon" ) if $itemissue->{auto_renew}; return ( 0, "too_soon" ); } + else { + return ( 0, "auto_renew" ) if $itemissue->{auto_renew}; + return ( 1, undef ); + } + } + + # Fallback for automatic renewals: + # If norenewalbefore is undef, don't renew before due date. + elsif ( $itemissue->{auto_renew} ) { + return ( 0, "auto_renew" ) + if DateTime->now( time_zone => C4::Context->tz() ) >= + $itemissue->{date_due}; + return ( 0, "auto_too_soon" ); } - return ( 0, "auto_renew" ) if $itemissue->{auto_renew}; return ( 1, undef ); } @@ -2966,7 +2978,7 @@ sub GetSoonestRenewDate { my $now = DateTime->now( time_zone => C4::Context->tz() ); - if ( $issuingrule->{norenewalbefore} ) { + if ( defined $issuingrule->{norenewalbefore} ) { my $soonestrenewal = $itemissue->{date_due}->subtract( $issuingrule->{lengthunit} => $issuingrule->{norenewalbefore} ); --- a/admin/smart-rules.pl +++ a/admin/smart-rules.pl @@ -114,7 +114,7 @@ elsif ($op eq 'add') { my $renewalsallowed = $input->param('renewalsallowed'); my $renewalperiod = $input->param('renewalperiod'); my $norenewalbefore = $input->param('norenewalbefore'); - $norenewalbefore = undef if $norenewalbefore eq '0' or $norenewalbefore =~ /^\s*$/; + $norenewalbefore = undef if $norenewalbefore =~ /^\s*$/; my $auto_renew = $input->param('auto_renew') eq 'yes' ? 1 : 0; my $reservesallowed = $input->param('reservesallowed'); my $onshelfholds = $input->param('onshelfholds') || 0; --