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

(-)a/C4/Circulation.pm (-2 / +22 lines)
Lines 2586-2597 already renewed the loan. $error will contain the reason the renewal can not pro Link Here
2586
=cut
2586
=cut
2587
2587
2588
sub CanBookBeRenewed {
2588
sub CanBookBeRenewed {
2589
    my ( $borrowernumber, $itemnumber, $override_limit ) = @_;
2589
    my ( $borrowernumber, $itemnumber, $override_limit, $date_due ) = @_;
2590
2590
2591
    my $dbh    = C4::Context->dbh;
2591
    my $dbh    = C4::Context->dbh;
2592
    my $renews = 1;
2592
    my $renews = 1;
2593
2593
2594
    my $item      = GetItem($itemnumber)      or return ( 0, 'no_item' );
2594
    my $item = Koha::Items->find( $itemnumber ) or return ( 0, 'no_item' );;
2595
    my $issue = Koha::Checkouts->find( { itemnumber => $itemnumber } ) or return ( 0, 'no_checkout' );
2595
    my $issue = Koha::Checkouts->find( { itemnumber => $itemnumber } ) or return ( 0, 'no_checkout' );
2596
    return ( 0, 'onsite_checkout' ) if $issue->onsite_checkout;
2596
    return ( 0, 'onsite_checkout' ) if $issue->onsite_checkout;
2597
2597
Lines 2664-2669 sub CanBookBeRenewed { Link Here
2664
            }
2664
            }
2665
        }
2665
        }
2666
    }
2666
    }
2667
2668
    unless ($date_due) {
2669
        my $itemtype = $item->effective_itemtype;
2670
        my $patron_unblessed = $patron->unblessed;
2671
        $date_due = (C4::Context->preference('RenewalPeriodBase') eq 'date_due') ?
2672
                                        dt_from_string( $issue->date_due, 'sql' ) :
2673
                                        DateTime->now( time_zone => C4::Context->tz());
2674
        $date_due =  CalcDateDue($date_due, $itemtype, _GetCircControlBranch($item, $patron_unblessed), $patron_unblessed, 'is a renewal');
2675
    }
2676
2677
    my $now = dt_from_string();
2678
    my $biblionumber = $item->biblionumber;
2679
    my $preventCheckoutOnSameReservePeriod =
2680
        C4::Context->preference("PreventCheckoutOnSameReservePeriod");
2681
    my $reserves_on_same_period =
2682
        ReservesOnSamePeriod($biblionumber, $itemnumber, $now->ymd, $date_due->ymd);
2683
    if ($preventCheckoutOnSameReservePeriod && $reserves_on_same_period) {
2684
        $resfound = 1;
2685
    }
2686
2667
    return ( 0, "on_reserve" ) if $resfound;    # '' when no hold was found
2687
    return ( 0, "on_reserve" ) if $resfound;    # '' when no hold was found
2668
2688
2669
    return ( 1, undef ) if $override_limit;
2689
    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 / +62 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 113;
20
use Test::More tests => 115;
21
21
22
use DateTime;
22
use DateTime;
23
23
Lines 225-230 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
225
    my $title = 'Silence in the library';
225
    my $title = 'Silence in the library';
226
    my ($biblionumber, $biblioitemnumber) = add_biblio($title, 'Moffat, Steven');
226
    my ($biblionumber, $biblioitemnumber) = add_biblio($title, 'Moffat, Steven');
227
227
228
228
    my $barcode = 'R00000342';
229
    my $barcode = 'R00000342';
229
    my $branch = $library2->{branchcode};
230
    my $branch = $library2->{branchcode};
230
231
Lines 331-336 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
331
    my $borrowing_borrowernumber = Koha::Checkouts->find( { itemnumber => $itemnumber } )->borrowernumber;
332
    my $borrowing_borrowernumber = Koha::Checkouts->find( { itemnumber => $itemnumber } )->borrowernumber;
332
    is ($borrowing_borrowernumber, $renewing_borrowernumber, "Item checked out to $renewing_borrower->{firstname} $renewing_borrower->{surname}");
333
    is ($borrowing_borrowernumber, $renewing_borrowernumber, "Item checked out to $renewing_borrower->{firstname} $renewing_borrower->{surname}");
333
334
335
    t::lib::Mocks::mock_preference('CircControl', 'PatronLibrary');
334
    my ( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $itemnumber, 1);
336
    my ( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $itemnumber, 1);
335
    is( $renewokay, 1, 'Can renew, no holds for this title or item');
337
    is( $renewokay, 1, 'Can renew, no holds for this title or item');
336
338
Lines 1153-1158 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
1153
}
1155
}
1154
1156
1155
{
1157
{
1158
    # Don't allow renewing on reserve period with PreventCheckoutOnSameReservePeriod enabled
1159
    t::lib::Mocks::mock_preference( 'PreventCheckoutOnSameReservePeriod', 1 );
1160
1161
    my $start_issue_dt = DateTime->now();
1162
    $start_issue_dt->subtract( days => 15);
1163
    my $due_date = $start_issue_dt->clone;
1164
    $due_date->add( days => 17 );
1165
1166
    my $biblio = $builder->build({
1167
        source => 'Biblio',
1168
    });
1169
    my $biblionumber = $biblio->{biblionumber};
1170
1171
    my $item = $builder->build({
1172
        source => 'Item',
1173
        value => {
1174
            biblionumber => $biblionumber
1175
        }
1176
    });
1177
    my $itemnumber = $item->{itemnumber};
1178
1179
    my $issue = $builder->build({
1180
        source => 'Issue',
1181
        value => {
1182
            itemnumber => $itemnumber,
1183
            biblionumber => $biblionumber,
1184
            issuedate => $start_issue_dt->ymd,
1185
            date_due => $due_date->ymd,
1186
            onsite_checkout => 0
1187
        }
1188
    });
1189
1190
    my $reservedate = $due_date->clone;
1191
    $reservedate->add( days => 5 );
1192
    my $expirationdate = $reservedate->clone;
1193
    $expirationdate->add( days => 15 );
1194
    $builder->build({
1195
        source => 'Reserve',
1196
        value => {
1197
            biblionumber => $biblionumber,
1198
            itemnumber => $itemnumber,
1199
            reservedate => $reservedate->ymd,
1200
            expirationdate => $expirationdate->ymd
1201
        }
1202
    });
1203
1204
    my $requested_date_due = $due_date->clone;
1205
    $requested_date_due->add( days => 4 );
1206
    my ( $renewed, $error ) = CanBookBeRenewed( $issue->{borrowernumber}, $itemnumber, 1, $requested_date_due );
1207
    is( $renewed, 1, 'CanBookBeRenewed should allow to renew if no reserve date overlap' );
1208
1209
    $requested_date_due->add( days => 2 );
1210
    ( $renewed, $error ) = CanBookBeRenewed( $issue->{borrowernumber}, $itemnumber, 1, $requested_date_due );
1211
    is( $renewed, 0, 'CanBookBeRenewed should not allow to renew if reserve date overlap' );
1212
1213
    t::lib::Mocks::mock_preference( 'PreventCheckoutOnSameReservePeriod', 0 );
1214
}
1215
1216
{
1156
    my $library = $builder->build({ source => 'Branch' });
1217
    my $library = $builder->build({ source => 'Branch' });
1157
1218
1158
    my ($biblionumber, $biblioitemnumber) = add_biblio();
1219
    my ($biblionumber, $biblioitemnumber) = add_biblio();
1159
- 

Return to bug 15261