@@ -, +, @@ column --- C4/Circulation.pm | 105 ++++++++++++++++++++++------------------------ 1 file changed, 51 insertions(+), 54 deletions(-) --- a/C4/Circulation.pm +++ a/C4/Circulation.pm @@ -2753,53 +2753,6 @@ sub CanBookBeRenewed { my $patron = $issue->patron or return; - # override_limit will override anything else except on_reserve - unless ( $override_limit ){ - my $branchcode = _GetCircControlBranch( $item->unblessed, $patron->unblessed ); - my $issuing_rule = Koha::CirculationRules->get_effective_rules( - { - categorycode => $patron->categorycode, - itemtype => $item->effective_itemtype, - branchcode => $branchcode, - rules => [ - 'renewalsallowed', - 'lengthunit', - 'unseen_renewals_allowed' - ] - } - ); - - return ( 0, "too_many" ) - if not $issuing_rule->{renewalsallowed} or $issuing_rule->{renewalsallowed} <= $issue->renewals; - - return ( 0, "too_unseen" ) - if C4::Context->preference('UnseenRenewals') && - $issuing_rule->{unseen_renewals_allowed} && - $issuing_rule->{unseen_renewals_allowed} <= $issue->unseen_renewals; - - my $overduesblockrenewing = C4::Context->preference('OverduesBlockRenewing'); - my $restrictionblockrenewing = C4::Context->preference('RestrictionBlockRenewing'); - $patron = Koha::Patrons->find($borrowernumber); # FIXME Is this really useful? - my $restricted = $patron->is_debarred; - my $hasoverdues = $patron->has_overdues; - - if ( $restricted and $restrictionblockrenewing ) { - return ( 0, 'restriction'); - } elsif ( ($hasoverdues and $overduesblockrenewing eq 'block') || ($issue->is_overdue and $overduesblockrenewing eq 'blockitem') ) { - return ( 0, 'overdue'); - } - - $auto_renew = _CanBookBeAutoRenewed({ - patron => $patron, - item => $item, - branchcode => $branchcode, - issue => $issue - }); - return ( 0, $auto_renew ) if $auto_renew =~ 'auto_account_expired'; - return ( 0, $auto_renew ) if $auto_renew =~ 'auto_too_late'; - return ( 0, $auto_renew ) if $auto_renew =~ 'auto_too_much_oweing'; - } - my ( $resfound, $resrec, $possible_reserves ) = C4::Reserves::CheckReserves($itemnumber); # If next hold is non priority, then check if any hold with priority (non_priority = 0) exists for the same biblionumber. @@ -2858,15 +2811,59 @@ sub CanBookBeRenewed { } } } - if( $cron ) { #The cron wants to return 'too_soon' over 'on_reserve' - return ( 0, $auto_renew ) if $auto_renew =~ 'too_soon';#$auto_renew ne "no" && $auto_renew ne "ok"; - return ( 0, "on_reserve" ) if $resfound; # '' when no hold was found - } else { # For other purposes we want 'on_reserve' before 'too_soon' - return ( 0, "on_reserve" ) if $resfound; # '' when no hold was found - return ( 0, $auto_renew ) if $auto_renew =~ 'too_soon';#$auto_renew ne "no" && $auto_renew ne "ok"; + #The cron wants to return 'too_soon' over 'on_reserve' + return ( 0, "on_reserve" ) if $resfound && !$cron; + + # override_limit will override anything else except on_reserve + unless ( $override_limit ){ + my $branchcode = _GetCircControlBranch( $item->unblessed, $patron->unblessed ); + my $issuing_rule = Koha::CirculationRules->get_effective_rules( + { + categorycode => $patron->categorycode, + itemtype => $item->effective_itemtype, + branchcode => $branchcode, + rules => [ + 'renewalsallowed', + 'lengthunit', + 'unseen_renewals_allowed' + ] + } + ); + + return ( 0, "too_many" ) + if not $issuing_rule->{renewalsallowed} or $issuing_rule->{renewalsallowed} <= $issue->renewals; + + return ( 0, "too_unseen" ) + if C4::Context->preference('UnseenRenewals') && + $issuing_rule->{unseen_renewals_allowed} && + $issuing_rule->{unseen_renewals_allowed} <= $issue->unseen_renewals; + + my $overduesblockrenewing = C4::Context->preference('OverduesBlockRenewing'); + my $restrictionblockrenewing = C4::Context->preference('RestrictionBlockRenewing'); + $patron = Koha::Patrons->find($borrowernumber); # FIXME Is this really useful? + my $restricted = $patron->is_debarred; + my $hasoverdues = $patron->has_overdues; + + if ( $restricted and $restrictionblockrenewing ) { + return ( 0, 'restriction'); + } elsif ( ($hasoverdues and $overduesblockrenewing eq 'block') || ($issue->is_overdue and $overduesblockrenewing eq 'blockitem') ) { + return ( 0, 'overdue'); + } + + $auto_renew = _CanBookBeAutoRenewed({ + patron => $patron, + item => $item, + branchcode => $branchcode, + issue => $issue + }); + return ( 0, $auto_renew ) if $auto_renew =~ 'auto_account_expired'; + return ( 0, $auto_renew ) if $auto_renew =~ 'auto_too_late'; + return ( 0, $auto_renew ) if $auto_renew =~ 'auto_too_much_oweing'; } - return ( 0, "auto_renew" ) if $auto_renew eq "ok" && !$override_limit; # 0 if auto-renewal should not succeed + return ( 0, $auto_renew ) if $auto_renew =~ 'too_soon';#$auto_renew ne "no" && $auto_renew ne "ok"; + return ( 0, "on_reserve" ) if $resfound; # '' when no hold was found + return ( 0, "auto_renew" ) if $auto_renew eq "ok"; # 0 if auto-renewal should not succeed return ( 1, undef ); } --