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

(-)a/C4/Circulation.pm (-2 / +22 lines)
Lines 2606-2617 already renewed the loan. $error will contain the reason the renewal can not pro Link Here
2606
=cut
2606
=cut
2607
2607
2608
sub CanBookBeRenewed {
2608
sub CanBookBeRenewed {
2609
    my ( $borrowernumber, $itemnumber, $override_limit ) = @_;
2609
    my ( $borrowernumber, $itemnumber, $override_limit, $date_due ) = @_;
2610
2610
2611
    my $dbh    = C4::Context->dbh;
2611
    my $dbh    = C4::Context->dbh;
2612
    my $renews = 1;
2612
    my $renews = 1;
2613
2613
2614
    my $item      = GetItem($itemnumber)      or return ( 0, 'no_item' );
2614
    my $item = Koha::Items->find( $itemnumber ) or return ( 0, 'no_item' );;
2615
    my $issue = Koha::Checkouts->find( { itemnumber => $itemnumber } ) or return ( 0, 'no_checkout' );
2615
    my $issue = Koha::Checkouts->find( { itemnumber => $itemnumber } ) or return ( 0, 'no_checkout' );
2616
    return ( 0, 'onsite_checkout' ) if $issue->onsite_checkout;
2616
    return ( 0, 'onsite_checkout' ) if $issue->onsite_checkout;
2617
2617
Lines 2684-2689 sub CanBookBeRenewed { Link Here
2684
            }
2684
            }
2685
        }
2685
        }
2686
    }
2686
    }
2687
2688
    unless ($date_due) {
2689
        my $itemtype = $item->effective_itemtype;
2690
        my $patron_unblessed = $patron->unblessed;
2691
        $date_due = (C4::Context->preference('RenewalPeriodBase') eq 'date_due') ?
2692
                                        dt_from_string( $issue->date_due, 'sql' ) :
2693
                                        DateTime->now( time_zone => C4::Context->tz());
2694
        $date_due =  CalcDateDue($date_due, $itemtype, _GetCircControlBranch($item, $patron_unblessed), $patron_unblessed, 'is a renewal');
2695
    }
2696
2697
    my $now = dt_from_string();
2698
    my $biblionumber = $item->biblionumber;
2699
    my $preventCheckoutOnSameReservePeriod =
2700
        C4::Context->preference("PreventCheckoutOnSameReservePeriod");
2701
    my $reserves_on_same_period =
2702
        ReservesOnSamePeriod($biblionumber, $itemnumber, $now->ymd, $date_due->ymd);
2703
    if ($preventCheckoutOnSameReservePeriod && $reserves_on_same_period) {
2704
        $resfound = 1;
2705
    }
2706
2687
    return ( 0, "on_reserve" ) if $resfound;    # '' when no hold was found
2707
    return ( 0, "on_reserve" ) if $resfound;    # '' when no hold was found
2688
2708
2689
    return ( 1, undef ) if $override_limit;
2709
    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 => 118;
20
use Test::More tests => 120;
21
21
22
use DateTime;
22
use DateTime;
23
use POSIX qw( floor );
23
use POSIX qw( floor );
Lines 231-236 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
231
    my $title = 'Silence in the library';
231
    my $title = 'Silence in the library';
232
    my ($biblionumber, $biblioitemnumber) = add_biblio($title, 'Moffat, Steven');
232
    my ($biblionumber, $biblioitemnumber) = add_biblio($title, 'Moffat, Steven');
233
233
234
234
    my $barcode = 'R00000342';
235
    my $barcode = 'R00000342';
235
    my $branch = $library2->{branchcode};
236
    my $branch = $library2->{branchcode};
236
237
Lines 337-342 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
337
    my $borrowing_borrowernumber = Koha::Checkouts->find( { itemnumber => $itemnumber } )->borrowernumber;
338
    my $borrowing_borrowernumber = Koha::Checkouts->find( { itemnumber => $itemnumber } )->borrowernumber;
338
    is ($borrowing_borrowernumber, $renewing_borrowernumber, "Item checked out to $renewing_borrower->{firstname} $renewing_borrower->{surname}");
339
    is ($borrowing_borrowernumber, $renewing_borrowernumber, "Item checked out to $renewing_borrower->{firstname} $renewing_borrower->{surname}");
339
340
341
    t::lib::Mocks::mock_preference('CircControl', 'PatronLibrary');
340
    my ( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $itemnumber, 1);
342
    my ( $renewokay, $error ) = CanBookBeRenewed($renewing_borrowernumber, $itemnumber, 1);
341
    is( $renewokay, 1, 'Can renew, no holds for this title or item');
343
    is( $renewokay, 1, 'Can renew, no holds for this title or item');
342
344
Lines 1162-1167 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
1162
}
1164
}
1163
1165
1164
{
1166
{
1167
    # Don't allow renewing on reserve period with PreventCheckoutOnSameReservePeriod enabled
1168
    t::lib::Mocks::mock_preference( 'PreventCheckoutOnSameReservePeriod', 1 );
1169
1170
    my $start_issue_dt = DateTime->now();
1171
    $start_issue_dt->subtract( days => 15);
1172
    my $due_date = $start_issue_dt->clone;
1173
    $due_date->add( days => 17 );
1174
1175
    my $biblio = $builder->build({
1176
        source => 'Biblio',
1177
    });
1178
    my $biblionumber = $biblio->{biblionumber};
1179
1180
    my $item = $builder->build({
1181
        source => 'Item',
1182
        value => {
1183
            biblionumber => $biblionumber
1184
        }
1185
    });
1186
    my $itemnumber = $item->{itemnumber};
1187
1188
    my $issue = $builder->build({
1189
        source => 'Issue',
1190
        value => {
1191
            itemnumber => $itemnumber,
1192
            biblionumber => $biblionumber,
1193
            issuedate => $start_issue_dt->ymd,
1194
            date_due => $due_date->ymd,
1195
            onsite_checkout => 0
1196
        }
1197
    });
1198
1199
    my $reservedate = $due_date->clone;
1200
    $reservedate->add( days => 5 );
1201
    my $expirationdate = $reservedate->clone;
1202
    $expirationdate->add( days => 15 );
1203
    $builder->build({
1204
        source => 'Reserve',
1205
        value => {
1206
            biblionumber => $biblionumber,
1207
            itemnumber => $itemnumber,
1208
            reservedate => $reservedate->ymd,
1209
            expirationdate => $expirationdate->ymd
1210
        }
1211
    });
1212
1213
    my $requested_date_due = $due_date->clone;
1214
    $requested_date_due->add( days => 4 );
1215
    my ( $renewed, $error ) = CanBookBeRenewed( $issue->{borrowernumber}, $itemnumber, 1, $requested_date_due );
1216
    is( $renewed, 1, 'CanBookBeRenewed should allow to renew if no reserve date overlap' );
1217
1218
    $requested_date_due->add( days => 2 );
1219
    ( $renewed, $error ) = CanBookBeRenewed( $issue->{borrowernumber}, $itemnumber, 1, $requested_date_due );
1220
    is( $renewed, 0, 'CanBookBeRenewed should not allow to renew if reserve date overlap' );
1221
1222
    t::lib::Mocks::mock_preference( 'PreventCheckoutOnSameReservePeriod', 0 );
1223
}
1224
1225
{
1165
    my $library = $builder->build({ source => 'Branch' });
1226
    my $library = $builder->build({ source => 'Branch' });
1166
1227
1167
    my ($biblionumber, $biblioitemnumber) = add_biblio();
1228
    my ($biblionumber, $biblioitemnumber) = add_biblio();
1168
- 

Return to bug 15261