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

(-)a/C4/Circulation.pm (-2 / +10 lines)
Lines 2982-2988 sub CanBookBeRenewed { Link Here
2982
    return ( 0, 'item_issued_to_other_patron') if $issue->borrowernumber != $patron->borrowernumber;
2982
    return ( 0, 'item_issued_to_other_patron') if $issue->borrowernumber != $patron->borrowernumber;
2983
    return ( 0, 'item_denied_renewal') if $item->is_denied_renewal;
2983
    return ( 0, 'item_denied_renewal') if $item->is_denied_renewal;
2984
2984
2985
       # override_limit will override anything else except on_reserve
2985
    my $final_renewal        = 0;
2986
    my $final_unseen_renewal = 0;
2987
2988
    # override_limit will override anything else except on_reserve
2986
    unless ( $override_limit ){
2989
    unless ( $override_limit ){
2987
        my $branchcode = _GetCircControlBranch( $item, $patron );
2990
        my $branchcode = _GetCircControlBranch( $item, $patron );
2988
        my $issuing_rule = Koha::CirculationRules->get_effective_rules(
2991
        my $issuing_rule = Koha::CirculationRules->get_effective_rules(
Lines 3006-3011 sub CanBookBeRenewed { Link Here
3006
            looks_like_number($issuing_rule->{unseen_renewals_allowed}) &&
3009
            looks_like_number($issuing_rule->{unseen_renewals_allowed}) &&
3007
            $issuing_rule->{unseen_renewals_allowed} <= $issue->unseen_renewals;
3010
            $issuing_rule->{unseen_renewals_allowed} <= $issue->unseen_renewals;
3008
3011
3012
        $final_renewal        = $issuing_rule->{renewalsallowed} == ( $issue->renewals_count + 1 ) ? 1 : 0;
3013
        $final_unseen_renewal = ( C4::Context->preference('UnseenRenewals')
3014
                && $issuing_rule->{unseen_renewals_allowed} == ( $issue->unseen_renewals + 1 ) ) ? 1 : 0;
3015
3009
        my $overduesblockrenewing = C4::Context->preference('OverduesBlockRenewing');
3016
        my $overduesblockrenewing = C4::Context->preference('OverduesBlockRenewing');
3010
        my $restrictionblockrenewing = C4::Context->preference('RestrictionBlockRenewing');
3017
        my $restrictionblockrenewing = C4::Context->preference('RestrictionBlockRenewing');
3011
        my $restricted  = $patron->is_debarred;
3018
        my $restricted  = $patron->is_debarred;
Lines 3106-3112 sub CanBookBeRenewed { Link Here
3106
        return (0, "too_soon", { soonest_renew_date => $soonest } ) unless $override_limit;
3113
        return (0, "too_soon", { soonest_renew_date => $soonest } ) unless $override_limit;
3107
    }
3114
    }
3108
3115
3109
    return ( 0, "auto_renew" ) if $auto_renew eq "ok" && !$override_limit; # 0 if auto-renewal should not succeed
3116
    my $auto_renew_code = $final_renewal ? 'auto_renew_final' : $final_unseen_renewal ? 'auto_unseen_final' : 'auto_renew';
3117
    return ( 0, $auto_renew_code ) if $auto_renew eq "ok" && !$override_limit;    # 0 if auto-renewal should not succeed
3110
3118
3111
    return ( 1, undef );
3119
    return ( 1, undef );
3112
}
3120
}
(-)a/t/db_dependent/Circulation.t (-3 / +67 lines)
Lines 430-436 subtest "GetIssuingCharges tests" => sub { Link Here
430
430
431
my ( $reused_itemnumber_1, $reused_itemnumber_2 );
431
my ( $reused_itemnumber_1, $reused_itemnumber_2 );
432
subtest "CanBookBeRenewed tests" => sub {
432
subtest "CanBookBeRenewed tests" => sub {
433
    plan tests => 104;
433
    plan tests => 105;
434
434
435
    C4::Context->set_preference('ItemsDeniedRenewal','');
435
    C4::Context->set_preference('ItemsDeniedRenewal','');
436
    # Generate test biblio
436
    # Generate test biblio
Lines 1345-1352 subtest "CanBookBeRenewed tests" => sub { Link Here
1345
        );
1345
        );
1346
1346
1347
    };
1347
    };
1348
    # Too many renewals
1349
1348
1349
    subtest "auto_renew_final" => sub {
1350
        plan tests => 6;
1351
        my $item_to_auto_renew = $builder->build_sample_item();
1352
        Koha::CirculationRules->set_rules(
1353
            {
1354
                categorycode => undef,
1355
                branchcode   => undef,
1356
                itemtype     => $item_to_auto_renew->itype,
1357
                rules        => {
1358
                    norenewalbefore => undef,
1359
                    renewalsallowed => 1,
1360
                }
1361
            }
1362
        );
1363
1364
        my $ten_days_before = dt_from_string->add( days => -10 );
1365
        my $ten_days_ahead  = dt_from_string->add( days => 10 );
1366
        my $issue           = AddIssue(
1367
            $renewing_borrower_obj, $item_to_auto_renew->barcode, $ten_days_ahead, undef, $ten_days_before,
1368
            undef, { auto_renew => 1 }
1369
        );
1370
        $issue->renewals_count(0)->store;
1371
1372
        ( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrower_obj, $issue );
1373
        is( $renewokay, 0,                  'No success for auto_renewal' );
1374
        is( $error,     'auto_renew_final', 'Auto renewal allowed, but it is the last one' );
1375
1376
        # Final unseen renewal
1377
        Koha::CirculationRules->set_rules(
1378
            {
1379
                categorycode => undef,
1380
                branchcode   => undef,
1381
                itemtype     => $item_to_auto_renew->itype,
1382
                rules        => {
1383
                    unseen_renewals_allowed => 2,
1384
                    renewalsallowed         => 10,
1385
                }
1386
            }
1387
        );
1388
        t::lib::Mocks::mock_preference( 'UnseenRenewals', 1 );
1389
        $issue->unseen_renewals(1)->renewals_count(1)->store;
1390
1391
        ( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrower_obj, $issue );
1392
        is( $renewokay, 0,                  'No success for auto_renewal' );
1393
        is( $error,     'auto_unseen_final', 'Final unseen renewal reported, not final overall' );
1394
1395
        # Final unseen renewal
1396
        Koha::CirculationRules->set_rules(
1397
            {
1398
                categorycode => undef,
1399
                branchcode   => undef,
1400
                itemtype     => $item_to_auto_renew->itype,
1401
                rules        => {
1402
                    unseen_renewals_allowed => 2,
1403
                    renewalsallowed         => 2,
1404
                }
1405
            }
1406
        );
1407
        ( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrower_obj, $issue );
1408
        is( $renewokay, 0,                  'No success for auto_renewal' );
1409
        is( $error,     'auto_renew_final', 'Final auto renewal reported' );
1410
1411
    };
1412
1413
    # Too many renewals
1350
    # set policy to forbid renewals
1414
    # set policy to forbid renewals
1351
    Koha::CirculationRules->set_rules(
1415
    Koha::CirculationRules->set_rules(
1352
        {
1416
        {
Lines 1377-1382 subtest "CanBookBeRenewed tests" => sub { Link Here
1377
        }
1441
        }
1378
    );
1442
    );
1379
    t::lib::Mocks::mock_preference('UnseenRenewals', 1);
1443
    t::lib::Mocks::mock_preference('UnseenRenewals', 1);
1444
1380
    $issue_1->unseen_renewals(2)->store;
1445
    $issue_1->unseen_renewals(2)->store;
1381
1446
1382
    ( $renewokay, $error ) = CanBookBeRenewed($renewing_borrower_obj, $issue_1);
1447
    ( $renewokay, $error ) = CanBookBeRenewed($renewing_borrower_obj, $issue_1);
1383
- 

Return to bug 34924