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

(-)a/C4/Circulation.pm (-1 / +21 lines)
Lines 2622-2628 already renewed the loan. $error will contain the reason the renewal can not pro Link Here
2622
=cut
2622
=cut
2623
2623
2624
sub CanBookBeRenewed {
2624
sub CanBookBeRenewed {
2625
    my ( $borrowernumber, $itemnumber, $override_limit ) = @_;
2625
    my ( $borrowernumber, $itemnumber, $override_limit, $date_due ) = @_;
2626
2626
2627
    my $dbh    = C4::Context->dbh;
2627
    my $dbh    = C4::Context->dbh;
2628
    my $renews = 1;
2628
    my $renews = 1;
Lines 2699-2704 sub CanBookBeRenewed { Link Here
2699
            }
2699
            }
2700
        }
2700
        }
2701
    }
2701
    }
2702
2703
    unless ($date_due) {
2704
        my $itemtype = $item->effective_itemtype;
2705
        my $patron_unblessed = $patron->unblessed;
2706
        $date_due = (C4::Context->preference('RenewalPeriodBase') eq 'date_due') ?
2707
                                        dt_from_string( $issue->date_due, 'sql' ) :
2708
                                        DateTime->now( time_zone => C4::Context->tz());
2709
        $date_due =  CalcDateDue($date_due, $itemtype, _GetCircControlBranch($item, $patron_unblessed), $patron_unblessed, 'is a renewal');
2710
    }
2711
2712
    my $now = dt_from_string();
2713
    my $biblionumber = $item->biblionumber;
2714
    my $preventCheckoutOnSameReservePeriod =
2715
        C4::Context->preference("PreventCheckoutOnSameReservePeriod");
2716
    my $reserves_on_same_period =
2717
        ReservesOnSamePeriod($biblionumber, $itemnumber, $now->ymd, $date_due->ymd);
2718
    if ($preventCheckoutOnSameReservePeriod && $reserves_on_same_period) {
2719
        $resfound = 1;
2720
    }
2721
2702
    return ( 0, "on_reserve" ) if $resfound;    # '' when no hold was found
2722
    return ( 0, "on_reserve" ) if $resfound;    # '' when no hold was found
2703
2723
2704
    return ( 1, undef ) if $override_limit;
2724
    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 ( $data->{renew_okay} ) {
62
if ( $data->{renew_okay} ) {
63
    $date_due = AddRenewal( $borrowernumber, $itemnumber, $branchcode, $date_due );
63
    $date_due = AddRenewal( $borrowernumber, $itemnumber, $branchcode, $date_due );
(-)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 => 127;
21
use Test::More tests => 129;
22
use Test::MockModule;
22
use Test::MockModule;
23
23
24
use Data::Dumper;
24
use Data::Dumper;
Lines 327-332 my ( $reused_itemnumber_1, $reused_itemnumber_2 ); Link Here
327
    my $borrowing_borrowernumber = Koha::Checkouts->find( { itemnumber => $item_1->itemnumber } )->borrowernumber;
327
    my $borrowing_borrowernumber = Koha::Checkouts->find( { itemnumber => $item_1->itemnumber } )->borrowernumber;
328
    is ($borrowing_borrowernumber, $renewing_borrowernumber, "Item checked out to $renewing_borrower->{firstname} $renewing_borrower->{surname}");
328
    is ($borrowing_borrowernumber, $renewing_borrowernumber, "Item checked out to $renewing_borrower->{firstname} $renewing_borrower->{surname}");
329
329
330
    t::lib::Mocks::mock_preference('CircControl', 'PatronLibrary');
330
    my ( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $item_1->itemnumber, 1);
331
    my ( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $item_1->itemnumber, 1);
331
    is( $renewokay, 1, 'Can renew, no holds for this title or item');
332
    is( $renewokay, 1, 'Can renew, no holds for this title or item');
332
333
Lines 1192-1197 my ( $reused_itemnumber_1, $reused_itemnumber_2 ); Link Here
1192
    is( $error, 'onsite_checkout', 'A correct error code should be returned by CanBookBeRenewed for on-site checkout' );
1193
    is( $error, 'onsite_checkout', 'A correct error code should be returned by CanBookBeRenewed for on-site checkout' );
1193
}
1194
}
1194
1195
1196
{
1197
    # Don't allow renewing on reserve period with PreventCheckoutOnSameReservePeriod enabled
1198
    t::lib::Mocks::mock_preference( 'PreventCheckoutOnSameReservePeriod', 1 );
1199
1200
    my $start_issue_dt = DateTime->now();
1201
    $start_issue_dt->subtract( days => 15);
1202
    my $due_date = $start_issue_dt->clone;
1203
    $due_date->add( days => 17 );
1204
1205
    my $biblio = $builder->build({
1206
        source => 'Biblio',
1207
    });
1208
    my $biblionumber = $biblio->{biblionumber};
1209
1210
    my $item = $builder->build({
1211
        source => 'Item',
1212
        value => {
1213
            biblionumber => $biblionumber
1214
        }
1215
    });
1216
    my $itemnumber = $item->{itemnumber};
1217
1218
    my $issue = $builder->build({
1219
        source => 'Issue',
1220
        value => {
1221
            itemnumber => $itemnumber,
1222
            biblionumber => $biblionumber,
1223
            issuedate => $start_issue_dt->ymd,
1224
            date_due => $due_date->ymd,
1225
            onsite_checkout => 0
1226
        }
1227
    });
1228
1229
    my $reservedate = $due_date->clone;
1230
    $reservedate->add( days => 5 );
1231
    my $expirationdate = $reservedate->clone;
1232
    $expirationdate->add( days => 15 );
1233
    $builder->build({
1234
        source => 'Reserve',
1235
        value => {
1236
            biblionumber => $biblionumber,
1237
            itemnumber => $itemnumber,
1238
            reservedate => $reservedate->ymd,
1239
            expirationdate => $expirationdate->ymd
1240
        }
1241
    });
1242
1243
    my $requested_date_due = $due_date->clone;
1244
    $requested_date_due->add( days => 4 );
1245
    my ( $renewed, $error ) = CanBookBeRenewed( $issue->{borrowernumber}, $itemnumber, 1, $requested_date_due );
1246
    is( $renewed, 1, 'CanBookBeRenewed should allow to renew if no reserve date overlap' );
1247
1248
    $requested_date_due->add( days => 2 );
1249
    ( $renewed, $error ) = CanBookBeRenewed( $issue->{borrowernumber}, $itemnumber, 1, $requested_date_due );
1250
    is( $renewed, 0, 'CanBookBeRenewed should not allow to renew if reserve date overlap' );
1251
1252
    t::lib::Mocks::mock_preference( 'PreventCheckoutOnSameReservePeriod', 0 );
1253
}
1254
1195
{
1255
{
1196
    my $library = $builder->build({ source => 'Branch' });
1256
    my $library = $builder->build({ source => 'Branch' });
1197
1257
1198
- 

Return to bug 15261