View | Details | Raw Unified | Return to bug 30167
Collapse All | Expand All

(-)a/C4/Circulation.pm (-4 / +5 lines)
Lines 2838-2844 item must currently be on loan to the specified borrower; renewals Link Here
2838
must be allowed for the item's type; and the borrower must not have
2838
must be allowed for the item's type; and the borrower must not have
2839
already renewed the loan.
2839
already renewed the loan.
2840
    $error will contain the reason the renewal can not proceed
2840
    $error will contain the reason the renewal can not proceed
2841
    $info will contain the soonest renewal date if the error is 'too soon'
2841
    $info will contain a hash of additional info
2842
      currently 'soonest_renew_date' if error is 'too soon'
2842
2843
2843
=cut
2844
=cut
2844
2845
Lines 2897-2903 sub CanBookBeRenewed { Link Here
2897
            branchcode => $branchcode,
2898
            branchcode => $branchcode,
2898
            issue      => $issue
2899
            issue      => $issue
2899
        });
2900
        });
2900
        return ( 0, $auto_renew, $soonest ) if $auto_renew =~ 'auto_too_soon' && $cron;
2901
        return ( 0, $auto_renew, { soonest_renew_date => $soonest } ) if $auto_renew =~ 'auto_too_soon' && $cron;
2901
        # cron wants 'too_soon' over 'on_reserve' for performance and to avoid
2902
        # cron wants 'too_soon' over 'on_reserve' for performance and to avoid
2902
        # extra notices being sent. Cron also implies no override
2903
        # extra notices being sent. Cron also implies no override
2903
        return ( 0, $auto_renew  ) if $auto_renew =~ 'auto_account_expired';
2904
        return ( 0, $auto_renew  ) if $auto_renew =~ 'auto_account_expired';
Lines 3000-3009 sub CanBookBeRenewed { Link Here
3000
    }
3001
    }
3001
3002
3002
    return ( 0, "on_reserve" ) if $resfound;    # '' when no hold was found
3003
    return ( 0, "on_reserve" ) if $resfound;    # '' when no hold was found
3003
    return ( 0, $auto_renew, $soonest ) if $auto_renew =~ 'too_soon';#$auto_renew ne "no" && $auto_renew ne "ok";
3004
    return ( 0, $auto_renew, { soonest_renew_date => $soonest } ) if $auto_renew =~ 'too_soon';#$auto_renew ne "no" && $auto_renew ne "ok";
3004
    $soonest = GetSoonestRenewDate($borrowernumber, $itemnumber);
3005
    $soonest = GetSoonestRenewDate($borrowernumber, $itemnumber);
3005
    if ( $soonest > dt_from_string() ){
3006
    if ( $soonest > dt_from_string() ){
3006
        return (0, "too_soon", $soonest ) unless $override_limit;
3007
        return (0, "too_soon", { soonest_renew_date => $soonest } ) unless $override_limit;
3007
    }
3008
    }
3008
3009
3009
    return ( 0, "auto_renew" ) if $auto_renew eq "ok" && !$override_limit; # 0 if auto-renewal should not succeed
3010
    return ( 0, "auto_renew" ) if $auto_renew eq "ok" && !$override_limit; # 0 if auto-renewal should not succeed
(-)a/circ/renew.pl (-1 / +1 lines)
Lines 83-89 if ($barcode) { Link Here
83
                }
83
                }
84
84
85
                if ( $error && ($error eq 'too_soon' or $error eq 'auto_too_soon') ) {
85
                if ( $error && ($error eq 'too_soon' or $error eq 'auto_too_soon') ) {
86
                    $soonest_renew_date = $info;
86
                    $soonest_renew_date = $info->{soonest_renew_date};
87
                }
87
                }
88
                if ( $error && ( $error eq 'auto_too_late' ) ) {
88
                if ( $error && ( $error eq 'auto_too_late' ) ) {
89
                    $latest_auto_renew_date = C4::Circulation::GetLatestAutoRenewDate(
89
                    $latest_auto_renew_date = C4::Circulation::GetLatestAutoRenewDate(
(-)a/opac/opac-user.pl (-1 / +1 lines)
Lines 254-260 if ( $pending_checkouts->count ) { # Useless test Link Here
254
254
255
            if ( $renewerror eq 'too_soon' ) {
255
            if ( $renewerror eq 'too_soon' ) {
256
                $issue->{'too_soon'}         = 1;
256
                $issue->{'too_soon'}         = 1;
257
                $issue->{'soonestrenewdate'} = $info;
257
                $issue->{'soonestrenewdate'} = $info->{soonest_renew_date};
258
            }
258
            }
259
        }
259
        }
260
260
(-)a/svc/checkouts (-1 / +1 lines)
Lines 160-166 while ( my $c = $sth->fetchrow_hashref() ) { Link Here
160
      $can_renew_error && $can_renew_error eq 'too_soon'
160
      $can_renew_error && $can_renew_error eq 'too_soon'
161
      ? output_pref(
161
      ? output_pref(
162
        {
162
        {
163
            dt => $info,
163
            dt => $info->{soonest_renew_date},
164
            as_due_date => 1
164
            as_due_date => 1
165
        }
165
        }
166
      )
166
      )
(-)a/t/db_dependent/Circulation.t (-8 / +7 lines)
Lines 800-806 subtest "CanBookBeRenewed tests" => sub { Link Here
800
    is( $renewokay, 0, 'Bug 14101: Cannot renew, renewal is automatic and premature' );
800
    is( $renewokay, 0, 'Bug 14101: Cannot renew, renewal is automatic and premature' );
801
    is( $error, 'auto_too_soon',
801
    is( $error, 'auto_too_soon',
802
        'Bug 14101: Cannot renew, renewal is automatic and premature, "No renewal before" = undef (returned code is auto_too_soon)' );
802
        'Bug 14101: Cannot renew, renewal is automatic and premature, "No renewal before" = undef (returned code is auto_too_soon)' );
803
    is( $info, $issue->date_due, "Due date is returned as earliest renewal date when error is 'auto_too_soon'" );
803
    is( $info->{soonest_renew_date} , $issue->date_due, "Due date is returned as earliest renewal date when error is 'auto_too_soon'" );
804
    AddReserve(
804
    AddReserve(
805
        {
805
        {
806
            branchcode       => $branch,
806
            branchcode       => $branch,
Lines 822-828 subtest "CanBookBeRenewed tests" => sub { Link Here
822
    ( $renewokay, $error, $info ) = CanBookBeRenewed( $renewing_borrowernumber, $item_4->itemnumber, undef, 1 );
822
    ( $renewokay, $error, $info ) = CanBookBeRenewed( $renewing_borrowernumber, $item_4->itemnumber, undef, 1 );
823
    is( $renewokay, 0, 'Still should not be able to renew' );
823
    is( $renewokay, 0, 'Still should not be able to renew' );
824
    is( $error, 'auto_too_soon', 'returned code is auto_too_soon, reserve not checked when checking for cron' );
824
    is( $error, 'auto_too_soon', 'returned code is auto_too_soon, reserve not checked when checking for cron' );
825
    is( $info, $issue->date_due, "Due date is returned as earliest renewal date when error is 'auto_too_soon'" );
825
    is( $info->{soonest_renew_date}, $issue->date_due, "Due date is returned as earliest renewal date when error is 'auto_too_soon'" );
826
    ( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrowernumber, $item_4->itemnumber, 1 );
826
    ( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrowernumber, $item_4->itemnumber, 1 );
827
    is( $renewokay, 0, 'Still should not be able to renew' );
827
    is( $renewokay, 0, 'Still should not be able to renew' );
828
    is( $error, 'on_reserve', 'returned code is on_reserve, auto_too_soon limit is overridden' );
828
    is( $error, 'on_reserve', 'returned code is on_reserve, auto_too_soon limit is overridden' );
Lines 858-864 subtest "CanBookBeRenewed tests" => sub { Link Here
858
    ( $renewokay, $error, $info ) = CanBookBeRenewed($renewing_borrowernumber, $item_1->itemnumber);
858
    ( $renewokay, $error, $info ) = CanBookBeRenewed($renewing_borrowernumber, $item_1->itemnumber);
859
    is( $renewokay, 0, 'Bug 7413: Cannot renew, renewal is premature');
859
    is( $renewokay, 0, 'Bug 7413: Cannot renew, renewal is premature');
860
    is( $error, 'too_soon', 'Bug 7413: Cannot renew, renewal is premature (returned code is too_soon)');
860
    is( $error, 'too_soon', 'Bug 7413: Cannot renew, renewal is premature (returned code is too_soon)');
861
    is( $info, dt_from_string($issue->date_due)->subtract( days => 7 ), "Soonest renew date returned when error is 'too_soon'");
861
    is( $info->{soonest_renew_date}, dt_from_string($issue->date_due)->subtract( days => 7 ), "Soonest renew date returned when error is 'too_soon'");
862
862
863
    # Bug 14101
863
    # Bug 14101
864
    # Test premature automatic renewal
864
    # Test premature automatic renewal
Lines 868-880 subtest "CanBookBeRenewed tests" => sub { Link Here
868
    is( $error, 'auto_too_soon',
868
    is( $error, 'auto_too_soon',
869
        'Bug 14101: Cannot renew, renewal is automatic and premature (returned code is auto_too_soon)'
869
        'Bug 14101: Cannot renew, renewal is automatic and premature (returned code is auto_too_soon)'
870
    );
870
    );
871
    is( $info, dt_from_string($issue->date_due)->subtract( days => 7 ), "Soonest renew date returned when error is 'auto_too_soon'");
871
    is( $info->{soonest_renew_date}, dt_from_string($issue->date_due)->subtract( days => 7 ), "Soonest renew date returned when error is 'auto_too_soon'");
872
872
873
    $renewing_borrower_obj->autorenew_checkouts(0)->store;
873
    $renewing_borrower_obj->autorenew_checkouts(0)->store;
874
    ( $renewokay, $error, $info ) = CanBookBeRenewed( $renewing_borrowernumber, $item_4->itemnumber );
874
    ( $renewokay, $error, $info ) = CanBookBeRenewed( $renewing_borrowernumber, $item_4->itemnumber );
875
    is( $renewokay, 0, 'No renewal before is 7, patron opted out of auto_renewal still cannot renew early' );
875
    is( $renewokay, 0, 'No renewal before is 7, patron opted out of auto_renewal still cannot renew early' );
876
    is( $error, 'too_soon', 'Error is too_soon, no auto' );
876
    is( $error, 'too_soon', 'Error is too_soon, no auto' );
877
    is( $info, dt_from_string($issue->date_due)->subtract( days => 7 ), "Soonest renew date returned when error is 'too_soon'");
877
    is( $info->{soonest_renew_date}, dt_from_string($issue->date_due)->subtract( days => 7 ), "Soonest renew date returned when error is 'too_soon'");
878
    $renewing_borrower_obj->autorenew_checkouts(1)->store;
878
    $renewing_borrower_obj->autorenew_checkouts(1)->store;
879
879
880
    # Change policy so that loans can only be renewed exactly on due date (0 days prior to due date)
880
    # Change policy so that loans can only be renewed exactly on due date (0 days prior to due date)
Lines 886-898 subtest "CanBookBeRenewed tests" => sub { Link Here
886
    is( $error, 'auto_too_soon',
886
    is( $error, 'auto_too_soon',
887
        'Bug 14101: Cannot renew, renewal is automatic and premature, "No renewal before" = 0 (returned code is auto_too_soon)'
887
        'Bug 14101: Cannot renew, renewal is automatic and premature, "No renewal before" = 0 (returned code is auto_too_soon)'
888
    );
888
    );
889
    is( $info, dt_from_string($issue->date_due), "Soonest renew date returned when error is 'auto_too_soon'");
889
    is( $info->{soonest_renew_date}, dt_from_string($issue->date_due), "Soonest renew date returned when error is 'auto_too_soon'");
890
890
891
    $renewing_borrower_obj->autorenew_checkouts(0)->store;
891
    $renewing_borrower_obj->autorenew_checkouts(0)->store;
892
    ( $renewokay, $error, $info ) = CanBookBeRenewed( $renewing_borrowernumber, $item_4->itemnumber );
892
    ( $renewokay, $error, $info ) = CanBookBeRenewed( $renewing_borrowernumber, $item_4->itemnumber );
893
    is( $renewokay, 0, 'No renewal before is 0, patron opted out of auto_renewal still cannot renew early' );
893
    is( $renewokay, 0, 'No renewal before is 0, patron opted out of auto_renewal still cannot renew early' );
894
    is( $error, 'too_soon', 'Error is too_soon, no auto' );
894
    is( $error, 'too_soon', 'Error is too_soon, no auto' );
895
    is( $info, dt_from_string($issue->date_due), "Soonest renew date returned when error is 'auto_too_soon'");
895
    is( $info->{soonest_renew_date}, dt_from_string($issue->date_due), "Soonest renew date returned when error is 'auto_too_soon'");
896
    $renewing_borrower_obj->autorenew_checkouts(1)->store;
896
    $renewing_borrower_obj->autorenew_checkouts(1)->store;
897
897
898
    # Change policy so that loans can be renewed 99 days prior to the due date
898
    # Change policy so that loans can be renewed 99 days prior to the due date
899
- 

Return to bug 30167