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

(-)a/C4/Circulation.pm (-10 / +16 lines)
Lines 2685-2695 already renewed the loan. $error will contain the reason the renewal can not pro Link Here
2685
=cut
2685
=cut
2686
2686
2687
sub CanBookBeRenewed {
2687
sub CanBookBeRenewed {
2688
    my ( $borrowernumber, $itemnumber, $override_limit ) = @_;
2688
    my ( $borrowernumber, $itemnumber, $override_limit, $cron ) = @_;
2689
2689
2690
    my $dbh    = C4::Context->dbh;
2690
    my $dbh    = C4::Context->dbh;
2691
    my $renews = 1;
2691
    my $renews = 1;
2692
    my $auto_renew = 0;
2692
    my $auto_renew = "no";
2693
2693
2694
    my $item      = Koha::Items->find($itemnumber)      or return ( 0, 'no_item' );
2694
    my $item      = Koha::Items->find($itemnumber)      or return ( 0, 'no_item' );
2695
    my $issue = $item->checkout or return ( 0, 'no_checkout' );
2695
    my $issue = $item->checkout or return ( 0, 'no_checkout' );
Lines 2780-2801 sub CanBookBeRenewed { Link Here
2780
2780
2781
            if ( $soonestrenewal > dt_from_string() )
2781
            if ( $soonestrenewal > dt_from_string() )
2782
            {
2782
            {
2783
                return ( 0, "auto_too_soon" ) if $issue->auto_renew;
2783
                $auto_renew = ($issue->auto_renew) ? "auto_too_soon" : "too_soon";
2784
                return ( 0, "too_soon" );
2785
            }
2784
            }
2786
            elsif ( $issue->auto_renew ) {
2785
            elsif ( $issue->auto_renew ) {
2787
                $auto_renew = 1;
2786
                $auto_renew = 'ok';
2788
            }
2787
            }
2789
        }
2788
        }
2790
2789
2791
        # Fallback for automatic renewals:
2790
        # Fallback for automatic renewals:
2792
        # If norenewalbefore is undef, don't renew before due date.
2791
        # If norenewalbefore is undef, don't renew before due date.
2793
        if ( $issue->auto_renew && !$auto_renew ) {
2792
        if ( $issue->auto_renew && $auto_renew eq "no" ) {
2794
            my $now = dt_from_string;
2793
            my $now = dt_from_string;
2795
            if ( $now >= dt_from_string( $issue->date_due, 'sql' ) ){
2794
            if ( $now >= dt_from_string( $issue->date_due, 'sql' ) ){
2796
                $auto_renew = 1;
2795
                $auto_renew = "ok";
2797
            } else {
2796
            } else {
2798
                return ( 0, "auto_too_soon" );
2797
                $auto_renew = "auto_too_soon";
2799
            }
2798
            }
2800
        }
2799
        }
2801
    }
2800
    }
Lines 2865-2872 sub CanBookBeRenewed { Link Here
2865
            }
2864
            }
2866
        }
2865
        }
2867
    }
2866
    }
2868
    return ( 0, "on_reserve" ) if $resfound;    # '' when no hold was found
2867
    if( $cron ) { #The cron wants to return 'too_soon' over 'on_reserve'
2869
    return ( 0, "auto_renew" ) if $auto_renew && !$override_limit; # 0 if auto-renewal should not succeed
2868
        return ( 0, $auto_renew  ) if $auto_renew =~ 'too_soon';#$auto_renew ne "no" && $auto_renew ne "ok";
2869
        return ( 0, "on_reserve" ) if $resfound;    # '' when no hold was found
2870
    } else { # For other purposes we want 'on_reserve' before 'too_soon'
2871
        return ( 0, "on_reserve" ) if $resfound;    # '' when no hold was found
2872
        return ( 0, $auto_renew  ) if $auto_renew =~ 'too_soon';#$auto_renew ne "no" && $auto_renew ne "ok";
2873
    }
2874
2875
    return ( 0, "auto_renew" ) if $auto_renew eq "ok" && !$override_limit; # 0 if auto-renewal should not succeed
2870
2876
2871
    return ( 1, undef );
2877
    return ( 1, undef );
2872
}
2878
}
(-)a/misc/cronjobs/automatic_renewals.pl (-1 / +1 lines)
Lines 76-82 my %report; Link Here
76
while ( my $auto_renew = $auto_renews->next ) {
76
while ( my $auto_renew = $auto_renews->next ) {
77
77
78
    # CanBookBeRenewed returns 'auto_renew' when the renewal should be done by this script
78
    # CanBookBeRenewed returns 'auto_renew' when the renewal should be done by this script
79
    my ( $ok, $error ) = CanBookBeRenewed( $auto_renew->borrowernumber, $auto_renew->itemnumber );
79
    my ( $ok, $error ) = CanBookBeRenewed( $auto_renew->borrowernumber, $auto_renew->itemnumber, undef, 1 );
80
    if ( $error eq 'auto_renew' ) {
80
    if ( $error eq 'auto_renew' ) {
81
        my $date_due = AddRenewal( $auto_renew->borrowernumber, $auto_renew->itemnumber, $auto_renew->branchcode );
81
        my $date_due = AddRenewal( $auto_renew->borrowernumber, $auto_renew->itemnumber, $auto_renew->branchcode );
82
        $auto_renew->auto_renew_error(undef)->store;
82
        $auto_renew->auto_renew_error(undef)->store;
(-)a/t/db_dependent/Circulation.t (-3 / +8 lines)
Lines 279-285 $dbh->do( Link Here
279
279
280
my ( $reused_itemnumber_1, $reused_itemnumber_2 );
280
my ( $reused_itemnumber_1, $reused_itemnumber_2 );
281
subtest "CanBookBeRenewed tests" => sub {
281
subtest "CanBookBeRenewed tests" => sub {
282
    plan tests => 77;
282
    plan tests => 81;
283
283
284
    C4::Context->set_preference('ItemsDeniedRenewal','');
284
    C4::Context->set_preference('ItemsDeniedRenewal','');
285
    # Generate test biblio
285
    # Generate test biblio
Lines 615-624 subtest "CanBookBeRenewed tests" => sub { Link Here
615
    );
615
    );
616
    ( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrowernumber, $item_4->itemnumber );
616
    ( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrowernumber, $item_4->itemnumber );
617
    is( $renewokay, 0, 'Still should not be able to renew' );
617
    is( $renewokay, 0, 'Still should not be able to renew' );
618
    is( $error, 'auto_too_soon', 'returned code is auto_too_soon, reserve not checked' );
618
    is( $error, 'on_reserve', 'returned code is on_reserve, reserve checked when not checking for cron' );
619
    ( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrowernumber, $item_4->itemnumber, undef, 1 );
620
    is( $renewokay, 0, 'Still should not be able to renew' );
621
    is( $error, 'auto_too_soon', 'returned code is auto_too_soon, reserve not checked when checking for cron' );
619
    ( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrowernumber, $item_4->itemnumber, 1 );
622
    ( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrowernumber, $item_4->itemnumber, 1 );
620
    is( $renewokay, 0, 'Still should not be able to renew' );
623
    is( $renewokay, 0, 'Still should not be able to renew' );
621
    is( $error, 'on_reserve', 'returned code is on_reserve, auto_too_soon limit is overridden' );
624
    is( $error, 'on_reserve', 'returned code is on_reserve, auto_too_soon limit is overridden' );
625
    ( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrowernumber, $item_4->itemnumber, 1, 1 );
626
    is( $renewokay, 0, 'Still should not be able to renew' );
627
    is( $error, 'on_reserve', 'returned code is on_reserve, auto_too_soon limit is overridden' );
622
    $dbh->do('UPDATE circulation_rules SET rule_value = 0 where rule_name = "norenewalbefore"');
628
    $dbh->do('UPDATE circulation_rules SET rule_value = 0 where rule_name = "norenewalbefore"');
623
    ( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrowernumber, $item_4->itemnumber, 1 );
629
    ( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrowernumber, $item_4->itemnumber, 1 );
624
    is( $renewokay, 0, 'Still should not be able to renew' );
630
    is( $renewokay, 0, 'Still should not be able to renew' );
625
- 

Return to bug 25758