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

(-)a/C4/Circulation.pm (-2 / +10 lines)
Lines 2953-2959 sub CanBookBeRenewed { Link Here
2953
    return ( 0, 'item_issued_to_other_patron') if $issue->borrowernumber != $patron->borrowernumber;
2953
    return ( 0, 'item_issued_to_other_patron') if $issue->borrowernumber != $patron->borrowernumber;
2954
    return ( 0, 'item_denied_renewal') if $item->is_denied_renewal;
2954
    return ( 0, 'item_denied_renewal') if $item->is_denied_renewal;
2955
2955
2956
       # override_limit will override anything else except on_reserve
2956
    my $final_renewal        = 0;
2957
    my $final_unseen_renewal = 0;
2958
2959
    # override_limit will override anything else except on_reserve
2957
    unless ( $override_limit ){
2960
    unless ( $override_limit ){
2958
        my $branchcode = _GetCircControlBranch( $item, $patron );
2961
        my $branchcode = _GetCircControlBranch( $item, $patron );
2959
        my $issuing_rule = Koha::CirculationRules->get_effective_rules(
2962
        my $issuing_rule = Koha::CirculationRules->get_effective_rules(
Lines 2977-2982 sub CanBookBeRenewed { Link Here
2977
            looks_like_number($issuing_rule->{unseen_renewals_allowed}) &&
2980
            looks_like_number($issuing_rule->{unseen_renewals_allowed}) &&
2978
            $issuing_rule->{unseen_renewals_allowed} <= $issue->unseen_renewals;
2981
            $issuing_rule->{unseen_renewals_allowed} <= $issue->unseen_renewals;
2979
2982
2983
        $final_renewal        = $issuing_rule->{renewalsallowed} == ( $issue->renewals_count + 1 ) ? 1 : 0;
2984
        $final_unseen_renewal = ( C4::Context->preference('UnseenRenewals')
2985
                && $issuing_rule->{unseen_renewals_allowed} == ( $issue->unseen_renewals + 1 ) ) ? 1 : 0;
2986
2980
        my $overduesblockrenewing = C4::Context->preference('OverduesBlockRenewing');
2987
        my $overduesblockrenewing = C4::Context->preference('OverduesBlockRenewing');
2981
        my $restrictionblockrenewing = C4::Context->preference('RestrictionBlockRenewing');
2988
        my $restrictionblockrenewing = C4::Context->preference('RestrictionBlockRenewing');
2982
        my $restricted  = $patron->is_debarred;
2989
        my $restricted  = $patron->is_debarred;
Lines 3077-3083 sub CanBookBeRenewed { Link Here
3077
        return (0, "too_soon", { soonest_renew_date => $soonest } ) unless $override_limit;
3084
        return (0, "too_soon", { soonest_renew_date => $soonest } ) unless $override_limit;
3078
    }
3085
    }
3079
3086
3080
    return ( 0, "auto_renew" ) if $auto_renew eq "ok" && !$override_limit; # 0 if auto-renewal should not succeed
3087
    my $auto_renew_code = $final_renewal ? 'auto_renew_final' : $final_unseen_renewal ? 'auto_unseen_final' : 'auto_renew';
3088
    return ( 0, $auto_renew_code ) if $auto_renew eq "ok" && !$override_limit;    # 0 if auto-renewal should not succeed
3081
3089
3082
    return ( 1, undef );
3090
    return ( 1, undef );
3083
}
3091
}
(-)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