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

(-)a/C4/Circulation.pm (-1 / +21 lines)
Lines 2661-2667 already renewed the loan. $error will contain the reason the renewal can not pro Link Here
2661
=cut
2661
=cut
2662
2662
2663
sub CanBookBeRenewed {
2663
sub CanBookBeRenewed {
2664
    my ( $borrowernumber, $itemnumber, $override_limit ) = @_;
2664
    my ( $borrowernumber, $itemnumber, $override_limit, $date_due ) = @_;
2665
2665
2666
    my $dbh    = C4::Context->dbh;
2666
    my $dbh    = C4::Context->dbh;
2667
    my $renews = 1;
2667
    my $renews = 1;
Lines 2738-2743 sub CanBookBeRenewed { Link Here
2738
            }
2738
            }
2739
        }
2739
        }
2740
    }
2740
    }
2741
2742
    unless ($date_due) {
2743
        my $itemtype = $item->effective_itemtype;
2744
        my $patron_unblessed = $patron->unblessed;
2745
        $date_due = (C4::Context->preference('RenewalPeriodBase') eq 'date_due') ?
2746
                                        dt_from_string( $issue->date_due, 'sql' ) :
2747
                                        DateTime->now( time_zone => C4::Context->tz());
2748
        $date_due =  CalcDateDue($date_due, $itemtype, _GetCircControlBranch($item, $patron_unblessed), $patron_unblessed, 'is a renewal');
2749
    }
2750
2751
    my $now = dt_from_string();
2752
    my $biblionumber = $item->biblionumber;
2753
    my $preventCheckoutOnSameReservePeriod =
2754
        C4::Context->preference("PreventCheckoutOnSameReservePeriod");
2755
    my $reserves_on_same_period =
2756
        ReservesOnSamePeriod($biblionumber, $itemnumber, $now->ymd, $date_due->ymd);
2757
    if ($preventCheckoutOnSameReservePeriod && $reserves_on_same_period) {
2758
        $resfound = 1;
2759
    }
2760
2741
    return ( 0, "on_reserve" ) if $resfound;    # '' when no hold was found
2761
    return ( 0, "on_reserve" ) if $resfound;    # '' when no hold was found
2742
2762
2743
    return ( 1, undef ) if $override_limit;
2763
    return ( 1, undef ) if $override_limit;
(-)a/svc/renew (-1 / +1 lines)
Lines 57-63 $data->{borrowernumber} = $borrowernumber; Link Here
57
$data->{branchcode} = $branchcode;
57
$data->{branchcode} = $branchcode;
58
58
59
( $data->{renew_okay}, $data->{error} ) =
59
( $data->{renew_okay}, $data->{error} ) =
60
  CanBookBeRenewed( $borrowernumber, $itemnumber, $override_limit );
60
  CanBookBeRenewed( $borrowernumber, $itemnumber, $override_limit, $date_due );
61
61
62
# If we're allowing reserved items to be renewed...
62
# If we're allowing reserved items to be renewed...
63
if ( $data->{error} && $data->{error} eq 'on_reserve' && C4::Context->preference('AllowRenewalOnHoldOverride')) {
63
if ( $data->{error} && $data->{error} eq 'on_reserve' && C4::Context->preference('AllowRenewalOnHoldOverride')) {
(-)a/t/db_dependent/Circulation.t (-2 / +61 lines)
Lines 18-24 Link Here
18
use Modern::Perl;
18
use Modern::Perl;
19
use utf8;
19
use utf8;
20
20
21
use Test::More tests => 45;
21
use Test::More tests => 47;
22
use Test::MockModule;
22
use Test::MockModule;
23
23
24
use Data::Dumper;
24
use Data::Dumper;
Lines 382-387 subtest "CanBookBeRenewed tests" => sub { Link Here
382
    my $borrowing_borrowernumber = Koha::Checkouts->find( { itemnumber => $item_1->itemnumber } )->borrowernumber;
382
    my $borrowing_borrowernumber = Koha::Checkouts->find( { itemnumber => $item_1->itemnumber } )->borrowernumber;
383
    is ($borrowing_borrowernumber, $renewing_borrowernumber, "Item checked out to $renewing_borrower->{firstname} $renewing_borrower->{surname}");
383
    is ($borrowing_borrowernumber, $renewing_borrowernumber, "Item checked out to $renewing_borrower->{firstname} $renewing_borrower->{surname}");
384
384
385
    t::lib::Mocks::mock_preference('CircControl', 'PatronLibrary');
385
    my ( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $item_1->itemnumber, 1);
386
    my ( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $item_1->itemnumber, 1);
386
    is( $renewokay, 1, 'Can renew, no holds for this title or item');
387
    is( $renewokay, 1, 'Can renew, no holds for this title or item');
387
388
Lines 1250-1255 subtest "AllowRenewalIfOtherItemsAvailable tests" => sub { Link Here
1250
    is( $error, 'onsite_checkout', 'A correct error code should be returned by CanBookBeRenewed for on-site checkout' );
1251
    is( $error, 'onsite_checkout', 'A correct error code should be returned by CanBookBeRenewed for on-site checkout' );
1251
}
1252
}
1252
1253
1254
{
1255
    # Don't allow renewing on reserve period with PreventCheckoutOnSameReservePeriod enabled
1256
    t::lib::Mocks::mock_preference( 'PreventCheckoutOnSameReservePeriod', 1 );
1257
1258
    my $start_issue_dt = DateTime->now();
1259
    $start_issue_dt->subtract( days => 15);
1260
    my $due_date = $start_issue_dt->clone;
1261
    $due_date->add( days => 17 );
1262
1263
    my $biblio = $builder->build({
1264
        source => 'Biblio',
1265
    });
1266
    my $biblionumber = $biblio->{biblionumber};
1267
1268
    my $item = $builder->build({
1269
        source => 'Item',
1270
        value => {
1271
            biblionumber => $biblionumber
1272
        }
1273
    });
1274
    my $itemnumber = $item->{itemnumber};
1275
1276
    my $issue = $builder->build({
1277
        source => 'Issue',
1278
        value => {
1279
            itemnumber => $itemnumber,
1280
            biblionumber => $biblionumber,
1281
            issuedate => $start_issue_dt->ymd,
1282
            date_due => $due_date->ymd,
1283
            onsite_checkout => 0
1284
        }
1285
    });
1286
1287
    my $reservedate = $due_date->clone;
1288
    $reservedate->add( days => 5 );
1289
    my $expirationdate = $reservedate->clone;
1290
    $expirationdate->add( days => 15 );
1291
    $builder->build({
1292
        source => 'Reserve',
1293
        value => {
1294
            biblionumber => $biblionumber,
1295
            itemnumber => $itemnumber,
1296
            reservedate => $reservedate->ymd,
1297
            expirationdate => $expirationdate->ymd
1298
        }
1299
    });
1300
1301
    my $requested_date_due = $due_date->clone;
1302
    $requested_date_due->add( days => 4 );
1303
    my ( $renewed, $error ) = CanBookBeRenewed( $issue->{borrowernumber}, $itemnumber, 1, $requested_date_due );
1304
    is( $renewed, 1, 'CanBookBeRenewed should allow to renew if no reserve date overlap' );
1305
1306
    $requested_date_due->add( days => 2 );
1307
    ( $renewed, $error ) = CanBookBeRenewed( $issue->{borrowernumber}, $itemnumber, 1, $requested_date_due );
1308
    is( $renewed, 0, 'CanBookBeRenewed should not allow to renew if reserve date overlap' );
1309
1310
    t::lib::Mocks::mock_preference( 'PreventCheckoutOnSameReservePeriod', 0 );
1311
}
1312
1253
{
1313
{
1254
    my $library = $builder->build({ source => 'Branch' });
1314
    my $library = $builder->build({ source => 'Branch' });
1255
1315
1256
- 

Return to bug 15261