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

(-)a/C4/Circulation.pm (-2 / +10 lines)
Lines 2985-2991 sub CanBookBeRenewed { Link Here
2985
    return ( 0, 'item_issued_to_other_patron') if $issue->borrowernumber != $patron->borrowernumber;
2985
    return ( 0, 'item_issued_to_other_patron') if $issue->borrowernumber != $patron->borrowernumber;
2986
    return ( 0, 'item_denied_renewal') if $item->is_denied_renewal;
2986
    return ( 0, 'item_denied_renewal') if $item->is_denied_renewal;
2987
2987
2988
       # override_limit will override anything else except on_reserve
2988
    my $final_renewal        = 0;
2989
    my $final_unseen_renewal = 0;
2990
2991
    # override_limit will override anything else except on_reserve
2989
    unless ( $override_limit ){
2992
    unless ( $override_limit ){
2990
        my $branchcode = _GetCircControlBranch( $item, $patron );
2993
        my $branchcode = _GetCircControlBranch( $item, $patron );
2991
        my $issuing_rule = Koha::CirculationRules->get_effective_rules(
2994
        my $issuing_rule = Koha::CirculationRules->get_effective_rules(
Lines 3009-3014 sub CanBookBeRenewed { Link Here
3009
            looks_like_number($issuing_rule->{unseen_renewals_allowed}) &&
3012
            looks_like_number($issuing_rule->{unseen_renewals_allowed}) &&
3010
            $issuing_rule->{unseen_renewals_allowed} <= $issue->unseen_renewals;
3013
            $issuing_rule->{unseen_renewals_allowed} <= $issue->unseen_renewals;
3011
3014
3015
        $final_renewal        = $issuing_rule->{renewalsallowed} == ( $issue->renewals_count + 1 ) ? 1 : 0;
3016
        $final_unseen_renewal = ( C4::Context->preference('UnseenRenewals')
3017
                && $issuing_rule->{unseen_renewals_allowed} == ( $issue->unseen_renewals + 1 ) ) ? 1 : 0;
3018
3012
        my $overduesblockrenewing = C4::Context->preference('OverduesBlockRenewing');
3019
        my $overduesblockrenewing = C4::Context->preference('OverduesBlockRenewing');
3013
        my $restrictionblockrenewing = C4::Context->preference('RestrictionBlockRenewing');
3020
        my $restrictionblockrenewing = C4::Context->preference('RestrictionBlockRenewing');
3014
        my $restricted  = $patron->is_debarred;
3021
        my $restricted  = $patron->is_debarred;
Lines 3120-3126 sub CanBookBeRenewed { Link Here
3120
        return (0, "too_soon", { soonest_renew_date => $soonest } ) unless $override_limit;
3127
        return (0, "too_soon", { soonest_renew_date => $soonest } ) unless $override_limit;
3121
    }
3128
    }
3122
3129
3123
    return ( 1, "auto_renew" ) if $auto_renew eq "ok" || $auto_renew eq "auto_too_soon" && !$override_limit;    # 0 if auto-renewal should not succeed
3130
    my $auto_renew_code = $final_renewal ? 'auto_renew_final' : $final_unseen_renewal ? 'auto_unseen_final' : 'auto_renew';
3131
    return ( 1, $auto_renew_code ) if $auto_renew eq "ok" || $auto_renew eq "auto_too_soon" && !$override_limit;
3124
3132
3125
    return ( 1, undef );
3133
    return ( 1, undef );
3126
}
3134
}
(-)a/misc/cronjobs/automatic_renewals.pl (-20 / +22 lines)
Lines 153-159 while ( my $auto_renew = $auto_renews->next ) { Link Here
153
    print "examining item '" . $auto_renew->itemnumber . "' to auto renew\n" if $verbose;
153
    print "examining item '" . $auto_renew->itemnumber . "' to auto renew\n" if $verbose;
154
154
155
    my ( $borrower_preferences, $wants_messages, $wants_digest ) = ( undef, 0, 0 );
155
    my ( $borrower_preferences, $wants_messages, $wants_digest ) = ( undef, 0, 0 );
156
    if ( $send_notices_pref eq 'preferences' ){
156
    if ( $send_notices_pref eq 'preferences' ) {
157
        $borrower_preferences = C4::Members::Messaging::GetMessagingPreferences(
157
        $borrower_preferences = C4::Members::Messaging::GetMessagingPreferences(
158
            {
158
            {
159
                borrowernumber => $auto_renew->borrowernumber,
159
                borrowernumber => $auto_renew->borrowernumber,
Lines 166-178 while ( my $auto_renew = $auto_renews->next ) { Link Here
166
        $wants_digest = 1
166
        $wants_digest = 1
167
            if $wants_messages
167
            if $wants_messages
168
            && $borrower_preferences->{wants_digest};
168
            && $borrower_preferences->{wants_digest};
169
    } else { # Preference is never or cron
169
    } else {    # Preference is never or cron
170
        $wants_messages = $send_notices;
170
        $wants_messages = $send_notices;
171
        $wants_digest = 0;
171
        $wants_digest   = 0;
172
    }
172
    }
173
173
174
    my ( $success, $error, $updated ) = $auto_renew->attempt_auto_renew({ confirm => $confirm });
174
    my ( $success, $error, $updated ) = $auto_renew->attempt_auto_renew( { confirm => $confirm } );
175
    if ( $success ) {
175
    if ($success) {
176
        if ($verbose) {
176
        if ($verbose) {
177
            say sprintf "Issue id: %s for borrower: %s and item: %s %s be renewed.",
177
            say sprintf "Issue id: %s for borrower: %s and item: %s %s be renewed.",
178
                $auto_renew->issue_id, $auto_renew->borrowernumber, $auto_renew->itemnumber,
178
                $auto_renew->issue_id, $auto_renew->borrowernumber, $auto_renew->itemnumber,
Lines 182-208 while ( my $auto_renew = $auto_renews->next ) { Link Here
182
            push @item_renewal_ids, $auto_renew->itemnumber;
182
            push @item_renewal_ids, $auto_renew->itemnumber;
183
        }
183
        }
184
        push @{ $report{ $auto_renew->borrowernumber } }, $auto_renew
184
        push @{ $report{ $auto_renew->borrowernumber } }, $auto_renew
185
            if ( $wants_messages ) && !$wants_digest;
185
            if ($wants_messages) && !$wants_digest;
186
    } elsif (
186
    } elsif (
187
187
        # FIXME Do we need to list every status? Why not simply else?
188
        # FIXME Do we need to list every status? Why not simply else?
188
        $error eq 'too_many' ||
189
           $error eq 'too_many'
189
        $error eq 'on_reserve' ||
190
        || $error eq 'on_reserve'
190
        $error eq 'restriction' ||
191
        || $error eq 'restriction'
191
        $error eq 'overdue' ||
192
        || $error eq 'overdue'
192
        $error eq 'too_unseen' ||
193
        || $error eq 'too_unseen'
193
        $error eq 'auto_account_expired' ||
194
        || $error eq 'auto_account_expired'
194
        $error eq 'auto_too_late' ||
195
        || $error eq 'auto_too_late'
195
        $error eq 'auto_too_much_oweing' ||
196
        || $error eq 'auto_too_much_oweing'
196
        $error eq 'auto_too_soon' ||
197
        || $error eq 'auto_too_soon'
197
        $error eq 'item_denied_renewal' ||
198
        || $error eq 'item_denied_renewal'
198
        $error eq 'item_issued_to_other_patron'
199
        || $error eq 'item_issued_to_other_patron'
199
    ) {
200
        )
200
        if ( $verbose ) {
201
    {
202
        if ($verbose) {
201
            say sprintf "Issue id: %s for borrower: %s and item: %s %s not be renewed. (%s)",
203
            say sprintf "Issue id: %s for borrower: %s and item: %s %s not be renewed. (%s)",
202
                $auto_renew->issue_id, $auto_renew->borrowernumber, $auto_renew->itemnumber,
204
                $auto_renew->issue_id, $auto_renew->borrowernumber, $auto_renew->itemnumber,
203
                $confirm ? 'will' : 'would', $error;
205
                $confirm ? 'will' : 'would', $error;
204
        }
206
        }
205
        if ( $updated ) {
207
        if ($updated) {
206
            push @{ $report{ $auto_renew->borrowernumber } }, $auto_renew
208
            push @{ $report{ $auto_renew->borrowernumber } }, $auto_renew
207
                if $error ne 'auto_too_soon' && ( $wants_messages && !$wants_digest );  # Do not notify if it's too soon
209
                if $error ne 'auto_too_soon' && ( $wants_messages && !$wants_digest );  # Do not notify if it's too soon
208
        }
210
        }
(-)a/t/db_dependent/Circulation.t (-3 / +67 lines)
Lines 431-437 subtest "GetIssuingCharges tests" => sub { Link Here
431
431
432
my ( $reused_itemnumber_1, $reused_itemnumber_2 );
432
my ( $reused_itemnumber_1, $reused_itemnumber_2 );
433
subtest "CanBookBeRenewed tests" => sub {
433
subtest "CanBookBeRenewed tests" => sub {
434
    plan tests => 112;
434
    plan tests => 113;
435
435
436
    C4::Context->set_preference('ItemsDeniedRenewal','');
436
    C4::Context->set_preference('ItemsDeniedRenewal','');
437
    # Generate test biblio
437
    # Generate test biblio
Lines 1412-1419 subtest "CanBookBeRenewed tests" => sub { Link Here
1412
        );
1412
        );
1413
1413
1414
    };
1414
    };
1415
    # Too many renewals
1416
1415
1416
    subtest "auto_renew_final" => sub {
1417
        plan tests => 6;
1418
        my $item_to_auto_renew = $builder->build_sample_item();
1419
        Koha::CirculationRules->set_rules(
1420
            {
1421
                categorycode => undef,
1422
                branchcode   => undef,
1423
                itemtype     => $item_to_auto_renew->itype,
1424
                rules        => {
1425
                    norenewalbefore => undef,
1426
                    renewalsallowed => 1,
1427
                }
1428
            }
1429
        );
1430
1431
        my $ten_days_before = dt_from_string->add( days => -10 );
1432
        my $ten_days_ahead  = dt_from_string->add( days => 10 );
1433
        my $issue           = AddIssue(
1434
            $renewing_borrower_obj, $item_to_auto_renew->barcode, $ten_days_ahead, undef, $ten_days_before,
1435
            undef, { auto_renew => 1 }
1436
        );
1437
        $issue->renewals_count(0)->store;
1438
1439
        ( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrower_obj, $issue );
1440
        is( $renewokay, 1,                  'Success for auto_renewal' );
1441
        is( $error,     'auto_renew_final', 'Auto renewal allowed, but it is the last one' );
1442
1443
        # Final unseen renewal
1444
        Koha::CirculationRules->set_rules(
1445
            {
1446
                categorycode => undef,
1447
                branchcode   => undef,
1448
                itemtype     => $item_to_auto_renew->itype,
1449
                rules        => {
1450
                    unseen_renewals_allowed => 2,
1451
                    renewalsallowed         => 10,
1452
                }
1453
            }
1454
        );
1455
        t::lib::Mocks::mock_preference( 'UnseenRenewals', 1 );
1456
        $issue->unseen_renewals(1)->renewals_count(1)->store;
1457
1458
        ( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrower_obj, $issue );
1459
        is( $renewokay, 1,                   'Success for auto_renewal' );
1460
        is( $error,     'auto_unseen_final', 'Final unseen renewal reported, not final overall' );
1461
1462
        # Final unseen renewal
1463
        Koha::CirculationRules->set_rules(
1464
            {
1465
                categorycode => undef,
1466
                branchcode   => undef,
1467
                itemtype     => $item_to_auto_renew->itype,
1468
                rules        => {
1469
                    unseen_renewals_allowed => 2,
1470
                    renewalsallowed         => 2,
1471
                }
1472
            }
1473
        );
1474
        ( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrower_obj, $issue );
1475
        is( $renewokay, 1,                  'Success for auto_renewal' );
1476
        is( $error,     'auto_renew_final', 'Final auto renewal reported' );
1477
1478
    };
1479
1480
    # Too many renewals
1417
    # set policy to forbid renewals
1481
    # set policy to forbid renewals
1418
    Koha::CirculationRules->set_rules(
1482
    Koha::CirculationRules->set_rules(
1419
        {
1483
        {
Lines 1444-1449 subtest "CanBookBeRenewed tests" => sub { Link Here
1444
        }
1508
        }
1445
    );
1509
    );
1446
    t::lib::Mocks::mock_preference('UnseenRenewals', 1);
1510
    t::lib::Mocks::mock_preference('UnseenRenewals', 1);
1511
1447
    $issue_1->unseen_renewals(2)->store;
1512
    $issue_1->unseen_renewals(2)->store;
1448
1513
1449
    ( $renewokay, $error ) = CanBookBeRenewed($renewing_borrower_obj, $issue_1);
1514
    ( $renewokay, $error ) = CanBookBeRenewed($renewing_borrower_obj, $issue_1);
1450
- 

Return to bug 34924