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

(-)a/C4/Biblio.pm (-2 / +1 lines)
Lines 406-414 sub DelBiblio { Link Here
406
    # We delete any existing holds
406
    # We delete any existing holds
407
    my $biblio = Koha::Biblios->find( $biblionumber );
407
    my $biblio = Koha::Biblios->find( $biblionumber );
408
    my $holds = $biblio->holds;
408
    my $holds = $biblio->holds;
409
    require C4::Reserves;
410
    while ( my $hold = $holds->next ) {
409
    while ( my $hold = $holds->next ) {
411
        C4::Reserves::CancelReserve({ reserve_id => $hold->reserve_id }); # TODO Replace with $hold->cancel
410
        $hold->cancel;
412
    }
411
    }
413
412
414
    # Delete in Zebra. Be careful NOT to move this line after _koha_delete_biblio
413
    # Delete in Zebra. Be careful NOT to move this line after _koha_delete_biblio
(-)a/C4/ILSDI/Services.pm (-1 / +1 lines)
Lines 773-779 sub CancelHold { Link Here
773
    return { code => 'RecordNotFound' } unless $hold;
773
    return { code => 'RecordNotFound' } unless $hold;
774
    return { code => 'RecordNotFound' } unless ($hold->borrowernumber == $borrowernumber);
774
    return { code => 'RecordNotFound' } unless ($hold->borrowernumber == $borrowernumber);
775
775
776
    C4::Reserves::CancelReserve({reserve_id => $reserve_id});
776
    $hold->cancel;
777
777
778
    return { code => 'Canceled' };
778
    return { code => 'Canceled' };
779
}
779
}
(-)a/C4/Reserves.pm (-19 / +32 lines)
Lines 121-127 BEGIN { Link Here
121
        &CanBookBeReserved
121
        &CanBookBeReserved
122
        &CanItemBeReserved
122
        &CanItemBeReserved
123
        &CanReserveBeCanceledFromOpac
123
        &CanReserveBeCanceledFromOpac
124
        &CancelReserve
125
        &CancelExpiredReserves
124
        &CancelExpiredReserves
126
125
127
        &AutoUnsuspendReserves
126
        &AutoUnsuspendReserves
Lines 798-820 sub CancelExpiredReserves { Link Here
798
    my $cancel_on_holidays = C4::Context->preference('ExpireReservesOnHolidays');
797
    my $cancel_on_holidays = C4::Context->preference('ExpireReservesOnHolidays');
799
798
800
    my $dbh = C4::Context->dbh;
799
    my $dbh = C4::Context->dbh;
801
    my $sth = $dbh->prepare( "
802
        SELECT * FROM reserves WHERE DATE(expirationdate) < DATE( CURDATE() )
803
        AND expirationdate IS NOT NULL
804
    " );
805
    $sth->execute();
806
800
807
    while ( my $res = $sth->fetchrow_hashref() ) {
801
    my $dtf = Koha::Database->new->schema->storage->datetime_parser;
808
        my $calendar = Koha::Calendar->new( branchcode => $res->{'branchcode'} );
802
    my $today = dt_from_string;
809
        my $cancel_params = { reserve_id => $res->{'reserve_id'} };
803
    # FIXME To move to Koha::Holds->search_expired (?)
804
    my $holds = Koha::Holds->search(
805
        {
806
            expirationdate => { '<', $dtf->format_date($today) }
807
        }
808
    );
809
810
    while ( my $hold = $holds->next ) {
811
        my $calendar = Koha::Calendar->new( branchcode => $hold->branchcode );
810
812
811
        next if !$cancel_on_holidays && $calendar->is_holiday( $today );
813
        next if !$cancel_on_holidays && $calendar->is_holiday( $today );
812
814
813
        if ( $res->{found} eq 'W' ) {
815
        my $cancel_params = {};
816
        if ( $holds->found eq 'W' ) {
814
            $cancel_params->{charge_cancel_fee} = 1;
817
            $cancel_params->{charge_cancel_fee} = 1;
815
        }
818
        }
819
        $hold->cancel( $cancel_params );
816
820
817
        CancelReserve($cancel_params);
818
    }
821
    }
819
}
822
}
820
823
Lines 954-964 sub ModReserve { Link Here
954
        $reserve_id = $hold->reserve_id;
957
        $reserve_id = $hold->reserve_id;
955
    }
958
    }
956
959
960
    $hold ||= Koha::Holds->find($reserve_id);
961
957
    if ( $rank eq "del" ) {
962
    if ( $rank eq "del" ) {
958
        CancelReserve({ reserve_id => $reserve_id });
963
        $hold->cancel;
959
    }
964
    }
960
    elsif ($rank =~ /^\d+/ and $rank > 0) {
965
    elsif ($rank =~ /^\d+/ and $rank > 0) {
961
        $hold ||= Koha::Holds->find($reserve_id);
962
        logaction( 'HOLDS', 'MODIFY', $hold->reserve_id, Dumper($hold->unblessed) )
966
        logaction( 'HOLDS', 'MODIFY', $hold->reserve_id, Dumper($hold->unblessed) )
963
            if C4::Context->preference('HoldsLog');
967
            if C4::Context->preference('HoldsLog');
964
968
Lines 1016-1021 sub ModReserveFill { Link Here
1016
        }
1020
        }
1017
    );
1021
    );
1018
1022
1023
    # FIXME Must call Koha::Hold->cancel ?
1019
    Koha::Old::Hold->new( $hold->unblessed() )->store();
1024
    Koha::Old::Hold->new( $hold->unblessed() )->store();
1020
1025
1021
    $hold->delete();
1026
    $hold->delete();
Lines 1128-1134 sub ModReserveCancelAll { Link Here
1128
    my ( $itemnumber, $borrowernumber ) = @_;
1133
    my ( $itemnumber, $borrowernumber ) = @_;
1129
1134
1130
    #step 1 : cancel the reservation
1135
    #step 1 : cancel the reservation
1131
    my $CancelReserve = CancelReserve({ itemnumber => $itemnumber, borrowernumber => $borrowernumber });
1136
    my $holds = Koha::Holds->search({ itemnumber => $itemnumber, borrowernumber => $borrowernumber });
1137
    return unless $holds->count;
1138
    $holds->next->cancel;
1132
1139
1133
    #step 2 launch the subroutine of the others reserves
1140
    #step 2 launch the subroutine of the others reserves
1134
    ( $messages, $nextreservinfo ) = GetOtherReserves($itemnumber);
1141
    ( $messages, $nextreservinfo ) = GetOtherReserves($itemnumber);
Lines 1452-1464 sub _FixPriority { Link Here
1452
1459
1453
    my $dbh = C4::Context->dbh;
1460
    my $dbh = C4::Context->dbh;
1454
1461
1455
    unless ( $biblionumber ) {
1462
    my $hold;
1456
        my $hold = Koha::Holds->find( $reserve_id );
1463
    if ( $reserve_id ) {
1464
        $hold = Koha::Holds->find( $reserve_id );
1465
        return unless $hold;
1466
    }
1467
1468
    unless ( $biblionumber ) { # FIXME This is a very weird API
1457
        $biblionumber = $hold->biblionumber;
1469
        $biblionumber = $hold->biblionumber;
1458
    }
1470
    }
1459
1471
1460
    if ( $rank eq "del" ) {
1472
    if ( $rank eq "del" ) { # FIXME will crash if called without $hold
1461
         CancelReserve({ reserve_id => $reserve_id });
1473
        $hold->cancel;
1462
    }
1474
    }
1463
    elsif ( $rank eq "W" || $rank eq "0" ) {
1475
    elsif ( $rank eq "W" || $rank eq "0" ) {
1464
1476
Lines 1894-1900 sub MoveReserve { Link Here
1894
            RevertWaitingStatus({ itemnumber => $itemnumber });
1906
            RevertWaitingStatus({ itemnumber => $itemnumber });
1895
        }
1907
        }
1896
        elsif ( $cancelreserve eq 'cancel' || $cancelreserve ) { # cancel reserves on this item
1908
        elsif ( $cancelreserve eq 'cancel' || $cancelreserve ) { # cancel reserves on this item
1897
            CancelReserve( { reserve_id => $res->{'reserve_id'} } );
1909
            my $hold = Koha::Holds->find( $res->{reserve_id} );
1910
            $hold->cancel;
1898
        }
1911
        }
1899
    }
1912
    }
1900
}
1913
}
(-)a/C4/SIP/ILS/Transaction/Hold.pm (-4 / +10 lines)
Lines 8-13 use Modern::Perl; Link Here
8
use C4::SIP::ILS::Transaction;
8
use C4::SIP::ILS::Transaction;
9
9
10
use C4::Reserves;	# AddReserve
10
use C4::Reserves;	# AddReserve
11
use Koha::Holds;
11
use Koha::Patrons;
12
use Koha::Patrons;
12
use parent qw(C4::SIP::ILS::Transaction);
13
use parent qw(C4::SIP::ILS::Transaction);
13
14
Lines 81-91 sub drop_hold { Link Here
81
	}
82
	}
82
    my $item = Koha::Items->find({ barcode => $self->{item}->id });
83
    my $item = Koha::Items->find({ barcode => $self->{item}->id });
83
84
84
      CancelReserve({
85
    my $holds = Koha::Holds->search(
86
        {
85
            biblionumber   => $item->biblionumber,
87
            biblionumber   => $item->biblionumber,
86
        itemnumber     => $self->{item}->id,
88
            itemnumber     => $self->{item}->id,
87
           borrowernumber => $patron->borrowernumber
89
            borrowernumber => $patron->borrowernumber
88
      });
90
        }
91
    );
92
    return $self unless $holds->count;
93
94
    $holds->next->cancel;
89
95
90
	$self->ok(1);
96
	$self->ok(1);
91
	return $self;
97
	return $self;
(-)a/Koha/Hold.pm (-1 / +57 lines)
Lines 1-6 Link Here
1
package Koha::Hold;
1
package Koha::Hold;
2
2
3
# Copyright ByWater Solutions 2014
3
# Copyright ByWater Solutions 2014
4
# Copyright 2017 Koha Development team
4
#
5
#
5
# This file is part of Koha.
6
# This file is part of Koha.
6
#
7
#
Lines 30-35 use Koha::Patrons; Link Here
30
use Koha::Biblios;
31
use Koha::Biblios;
31
use Koha::Items;
32
use Koha::Items;
32
use Koha::Libraries;
33
use Koha::Libraries;
34
use Koha::Old::Holds;
33
35
34
use base qw(Koha::Object);
36
use base qw(Koha::Object);
35
37
Lines 294-299 sub is_suspended { Link Here
294
    return $self->suspend();
296
    return $self->suspend();
295
}
297
}
296
298
299
300
=head3 cancel
301
302
my $cancel_hold = $hold->cancel();
303
304
Cancel a hold:
305
- The hold will be moved to the old_reserves table with a priority=0
306
- The priority of other holds will be updated
307
- The patron will be charge (see ExpireReservesMaxPickUpDelayCharge) if the charge_cancel_fee parameter is set
308
- a CANCEL HOLDS log will be done if the pref HoldsLog is on
309
310
=cut
311
312
sub cancel {
313
    my ( $self, $params ) = @_;
314
    $self->_result->result_source->schema->txn_do(
315
        sub {
316
            $self->cancellationdate(dt_from_string);
317
            $self->priority(0);
318
            $self->_move_to_old;
319
            $self->delete;
320
321
            # now fix the priority on the others....
322
            C4::Reserves::_FixPriority({ biblionumber => $self->biblionumber });
323
324
            # and, if desired, charge a cancel fee
325
            my $charge = C4::Context->preference("ExpireReservesMaxPickUpDelayCharge");
326
            if ( $charge && $params->{'charge_cancel_fee'} ) {
327
                C4::Accounts::manualinvoice($selt->borrowernumber, $self->itemnumber, '', 'HE', $charge);
328
            }
329
330
            C4::Log::logaction( 'HOLDS', 'CANCEL', $self->reserve_id, Dumper($self->unblessed) )
331
                if C4::Context->preference('HoldsLog');
332
        }
333
    );
334
    return $self;
335
}
336
337
=head3 _move_to_old
338
339
my $is_moved = $hold->_move_to_old;
340
341
Move a hold to the old_reserve table following the same pattern as Koha::Patron->move_to_deleted
342
343
=cut
344
345
sub _move_to_old {
346
    my ($self) = @_;
347
    my $hold_infos = $self->unblessed;
348
    return Koha::Old::Hold->new( $hold_infos )->store;
349
}
350
297
=head3 type
351
=head3 type
298
352
299
=cut
353
=cut
Lines 302-311 sub _type { Link Here
302
    return 'Reserve';
356
    return 'Reserve';
303
}
357
}
304
358
305
=head1 AUTHOR
359
=head1 AUTHORS
306
360
307
Kyle M Hall <kyle@bywatersolutions.com>
361
Kyle M Hall <kyle@bywatersolutions.com>
308
362
363
Jonathan Druart <jonathan.druart@bugs.koha-community.org>
364
309
=cut
365
=cut
310
366
311
1;
367
1;
(-)a/Koha/Patron/Discharge.pm (-2 / +1 lines)
Lines 7-13 use Carp; Link Here
7
7
8
use C4::Templates qw ( gettemplate );
8
use C4::Templates qw ( gettemplate );
9
use C4::Members qw( GetPendingIssues );
9
use C4::Members qw( GetPendingIssues );
10
use C4::Reserves qw( CancelReserve );
11
10
12
use Koha::Database;
11
use Koha::Database;
13
use Koha::DateUtils qw( dt_from_string output_pref );
12
use Koha::DateUtils qw( dt_from_string output_pref );
Lines 82-88 sub discharge { Link Here
82
    my $patron = Koha::Patrons->find( $borrowernumber );
81
    my $patron = Koha::Patrons->find( $borrowernumber );
83
    my $holds = $patron->holds;
82
    my $holds = $patron->holds;
84
    while ( my $hold = $holds->next ) {
83
    while ( my $hold = $holds->next ) {
85
        CancelReserve( { reserve_id => $hold->reserve_id } );
84
        $hold->cancel;
86
    }
85
    }
87
86
88
    # Debar the member
87
    # Debar the member
(-)a/Koha/REST/V1/Hold.pm (-1 / +1 lines)
Lines 155-161 sub delete { Link Here
155
    return $c->$cb({error => "Reserve not found"}, 404)
155
    return $c->$cb({error => "Reserve not found"}, 404)
156
        unless $hold;
156
        unless $hold;
157
157
158
    C4::Reserves::CancelReserve({ reserve_id => $reserve_id });
158
    $hold->cancel;
159
159
160
    return $c->$cb({}, 200);
160
    return $c->$cb({}, 200);
161
}
161
}
(-)a/circ/branchtransfers.pl (-8 / +15 lines)
Lines 33-38 use C4::Koha; Link Here
33
use C4::Members;
33
use C4::Members;
34
use Koha::BiblioFrameworks;
34
use Koha::BiblioFrameworks;
35
use Koha::AuthorisedValues;
35
use Koha::AuthorisedValues;
36
use Koha::Holds;
36
use Koha::Items;
37
use Koha::Items;
37
use Koha::Patrons;
38
use Koha::Patrons;
38
39
Lines 81-92 my $ignoreRs = 0; Link Here
81
# Deal with the requests....
82
# Deal with the requests....
82
if ( $request eq "KillWaiting" ) {
83
if ( $request eq "KillWaiting" ) {
83
    my $item = $query->param('itemnumber');
84
    my $item = $query->param('itemnumber');
84
    CancelReserve({
85
    my $holds = Koha::Holds->search(
85
        itemnumber     => $item,
86
        itemnumber     => $item,
86
        borrowernumber => $borrowernumber
87
        borrowernumber => $borrowernumber
87
    });
88
    });
88
    $cancelled   = 1;
89
    if ( $holds->count ) {
89
    $reqmessage  = 1;
90
        $holds->next->cancel;
91
        $cancelled   = 1;
92
        $reqmessage  = 1;
93
    } # FIXME else?
90
}
94
}
91
elsif ( $request eq "SetWaiting" ) {
95
elsif ( $request eq "SetWaiting" ) {
92
    my $item = $query->param('itemnumber');
96
    my $item = $query->param('itemnumber');
Lines 96-108 elsif ( $request eq "SetWaiting" ) { Link Here
96
    $reqmessage  = 1;
100
    $reqmessage  = 1;
97
}
101
}
98
elsif ( $request eq 'KillReserved' ) {
102
elsif ( $request eq 'KillReserved' ) {
99
    my $biblio = $query->param('biblionumber');
103
    my $biblionumber = $query->param('biblionumber');
100
    CancelReserve({
104
    my $holds = Koha::Holds->search(
101
        biblionumber   => $biblio,
105
        biblionumber   => $biblionumber,
102
        borrowernumber => $borrowernumber
106
        borrowernumber => $borrowernumber
103
    });
107
    });
104
    $cancelled   = 1;
108
    if ( $holds->count ) {
105
    $reqmessage  = 1;
109
        $holds->next->cancel;
110
        $cancelled   = 1;
111
        $reqmessage  = 1;
112
    } # FIXME else?
106
}
113
}
107
114
108
# collect the stack of books already transfered so they can printed...
115
# collect the stack of books already transfered so they can printed...
(-)a/circ/returns.pl (-1 / +5 lines)
Lines 54-59 use Koha::DateUtils; Link Here
54
use Koha::Calendar;
54
use Koha::Calendar;
55
use Koha::BiblioFrameworks;
55
use Koha::BiblioFrameworks;
56
use Koha::Checkouts;
56
use Koha::Checkouts;
57
use Koha::Holds;
57
use Koha::Items;
58
use Koha::Items;
58
use Koha::Patrons;
59
use Koha::Patrons;
59
60
Lines 159-165 if ( $query->param('reserve_id') ) { Link Here
159
    my $biblio = $item->biblio;
160
    my $biblio = $item->biblio;
160
161
161
    if ( $cancel_reserve ) {
162
    if ( $cancel_reserve ) {
162
        CancelReserve({ reserve_id => $reserve_id, charge_cancel_fee => !$forgivemanualholdsexpire });
163
        my $hold = Koha::Holds->find( $reserve_id );
164
        if ( $hold ) {
165
            $hold->cancel( { charge_cancel_fee => !$forgivemanualholdsexpire } );
166
        } # FIXME else?
163
    } else {
167
    } else {
164
        my $diffBranchSend = ($userenv_branch ne $diffBranchReturned) ? $diffBranchReturned : undef;
168
        my $diffBranchSend = ($userenv_branch ne $diffBranchReturned) ? $diffBranchReturned : undef;
165
        # diffBranchSend tells ModReserveAffect whether document is expected in this library or not,
169
        # diffBranchSend tells ModReserveAffect whether document is expected in this library or not,
(-)a/circ/waitingreserves.pl (-1 / +1 lines)
Lines 68-74 my $transfer_when_cancel_all = C4::Context->preference('TransferWhenCancelAllWai Link Here
68
$template->param( TransferWhenCancelAllWaitingHolds => 1 ) if $transfer_when_cancel_all;
68
$template->param( TransferWhenCancelAllWaitingHolds => 1 ) if $transfer_when_cancel_all;
69
69
70
my @cancel_result;
70
my @cancel_result;
71
# if we have a return from the form we launch the subroutine CancelReserve
71
# if we have a return from the form we cancel the holds
72
if ($item) {
72
if ($item) {
73
    my $res = cancel( $item, $borrowernumber, $fbr, $tbr );
73
    my $res = cancel( $item, $borrowernumber, $fbr, $tbr );
74
    push @cancel_result, $res if $res;
74
    push @cancel_result, $res if $res;
(-)a/opac/opac-modrequest.pl (-1 / +5 lines)
Lines 29-34 use CGI qw ( -utf8 ); Link Here
29
use C4::Output;
29
use C4::Output;
30
use C4::Reserves;
30
use C4::Reserves;
31
use C4::Auth;
31
use C4::Auth;
32
use Koha::Holds;
32
my $query = new CGI;
33
my $query = new CGI;
33
34
34
my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
35
my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
Lines 44-50 my ( $template, $borrowernumber, $cookie ) = get_template_and_user( Link Here
44
my $reserve_id = $query->param('reserve_id');
45
my $reserve_id = $query->param('reserve_id');
45
46
46
if ($reserve_id && $borrowernumber) {
47
if ($reserve_id && $borrowernumber) {
47
    CancelReserve({ reserve_id => $reserve_id }) if CanReserveBeCanceledFromOpac($reserve_id, $borrowernumber);
48
    if ( CanReserveBeCanceledFromOpac($reserve_id, $borrowernumber) ) {
49
        my $hold = Koha::Holds->find( $reserve_id );
50
        $hold->cancel if $hold;
51
    }
48
}
52
}
49
53
50
print $query->redirect("/cgi-bin/koha/opac-user.pl#opac-user-holds");
54
print $query->redirect("/cgi-bin/koha/opac-user.pl#opac-user-holds");
(-)a/reserve/request.pl (-1 / +2 lines)
Lines 91-97 if ( $action eq 'move' ) { Link Here
91
  AlterPriority( $where, $reserve_id );
91
  AlterPriority( $where, $reserve_id );
92
} elsif ( $action eq 'cancel' ) {
92
} elsif ( $action eq 'cancel' ) {
93
  my $reserve_id = $input->param('reserve_id');
93
  my $reserve_id = $input->param('reserve_id');
94
  CancelReserve({ reserve_id => $reserve_id });
94
  my $hold = Koha::Holds->find( $reserve_id );
95
  $hold->cancel if $hold;
95
} elsif ( $action eq 'setLowestPriority' ) {
96
} elsif ( $action eq 'setLowestPriority' ) {
96
  my $reserve_id = $input->param('reserve_id');
97
  my $reserve_id = $input->param('reserve_id');
97
  ToggleLowestPriority( $reserve_id );
98
  ToggleLowestPriority( $reserve_id );
(-)a/t/db_dependent/Circulation.t (-2 / +2 lines)
Lines 501-508 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
501
    is( $renewokay, 0, '(Bug 8236), Cannot renew, this item is overdue');
501
    is( $renewokay, 0, '(Bug 8236), Cannot renew, this item is overdue');
502
502
503
503
504
    $reserveid = Koha::Holds->search({ biblionumber => $biblionumber, borrowernumber => $reserving_borrowernumber })->next->reserve_id;
504
    my $hold = Koha::Holds->search({ biblionumber => $biblionumber, borrowernumber => $reserving_borrowernumber })->next;
505
    CancelReserve({ reserve_id => $reserveid });
505
    $hold->cancel;
506
506
507
    # Bug 14101
507
    # Bug 14101
508
    # Test automatic renewal before value for "norenewalbefore" in policy is set
508
    # Test automatic renewal before value for "norenewalbefore" in policy is set
(-)a/t/db_dependent/Holds.t (-8 / +8 lines)
Lines 7-13 use t::lib::TestBuilder; Link Here
7
7
8
use C4::Context;
8
use C4::Context;
9
9
10
use Test::More tests => 56;
10
use Test::More tests => 55;
11
use MARC::Record;
11
use MARC::Record;
12
use C4::Biblio;
12
use C4::Biblio;
13
use C4::Items;
13
use C4::Items;
Lines 127-135 $holds = $patron->holds; Link Here
127
is( $holds->next->borrowernumber, $borrowernumbers[0], "Test Koha::Patron->holds");
127
is( $holds->next->borrowernumber, $borrowernumbers[0], "Test Koha::Patron->holds");
128
128
129
129
130
CancelReserve({ 'reserve_id' => $reserve_id });
130
Koha::Holds->find( $reserve_id )->cancel;
131
131
$holds = $biblio->holds;
132
$holds = $biblio->holds;
132
is( $holds->count, $borrowers_count - 1, "Test CancelReserve()" );
133
is( $holds->count, $borrowers_count - 1, "Koha::Hold->cancel" );
133
134
134
$holds = $item->current_holds;
135
$holds = $item->current_holds;
135
$first_hold = $holds->next;
136
$first_hold = $holds->next;
Lines 288-316 AddReserve( Link Here
288
my $reserveid1 = Koha::Holds->search({ biblionumber => $bibnum, borrowernumber => $borrowernumbers[0] })->next->reserve_id;
289
my $reserveid1 = Koha::Holds->search({ biblionumber => $bibnum, borrowernumber => $borrowernumbers[0] })->next->reserve_id;
289
290
290
($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1 } , $bibnum);
291
($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1 } , $bibnum);
291
AddReserve(
292
my $reserveid2 = AddReserve(
292
    $branch_1,
293
    $branch_1,
293
    $borrowernumbers[1],
294
    $borrowernumbers[1],
294
    $bibnum,
295
    $bibnum,
295
    '',
296
    '',
296
    2,
297
    2,
297
);
298
);
298
my $reserveid2 = Koha::Holds->search({ biblionumber => $bibnum, borrowernumber => $borrowernumbers[1] })->next->reserve_id;
299
299
300
CancelReserve({ reserve_id => $reserveid1 });
300
my $hold1 = Koha::Holds->find( $reserveid1 );
301
$hold1->cancel;
301
302
302
my $hold2 = Koha::Holds->find( $reserveid2 );
303
my $hold2 = Koha::Holds->find( $reserveid2 );
303
is( $hold2->priority, 1, "After cancelreserve, the 2nd reserve becomes the first on the waiting list" );
304
is( $hold2->priority, 1, "After cancelreserve, the 2nd reserve becomes the first on the waiting list" );
304
305
305
($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1 } , $bibnum);
306
($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1 } , $bibnum);
306
AddReserve(
307
my $reserveid3 = AddReserve(
307
    $branch_1,
308
    $branch_1,
308
    $borrowernumbers[0],
309
    $borrowernumbers[0],
309
    $bibnum,
310
    $bibnum,
310
    '',
311
    '',
311
    2,
312
    2,
312
);
313
);
313
my $reserveid3 = Koha::Holds->search({ biblionumber => $bibnum, borrowernumber => $borrowernumbers[0] })->next->reserve_id;
314
314
315
my $hold3 = Koha::Holds->find( $reserveid3 );
315
my $hold3 = Koha::Holds->find( $reserveid3 );
316
is( $hold3->priority, 2, "New reserve for patron 0, the reserve has a priority = 2" );
316
is( $hold3->priority, 2, "New reserve for patron 0, the reserve has a priority = 2" );
(-)a/t/db_dependent/Holds/HoldFulfillmentPolicy.t (-9 / +10 lines)
Lines 7-12 use C4::Context; Link Here
7
use Test::More tests => 10;
7
use Test::More tests => 10;
8
8
9
use t::lib::TestBuilder;
9
use t::lib::TestBuilder;
10
use Koha::Holds;
10
11
11
BEGIN {
12
BEGIN {
12
    use_ok('C4::Reserves');
13
    use_ok('C4::Reserves');
Lines 79-97 $dbh->do("INSERT INTO default_circ_rules ( holdallowed, hold_fulfillment_policy Link Here
79
my $reserve_id = AddReserve( $library_A, $borrowernumber, $biblionumber, '', 1 );
80
my $reserve_id = AddReserve( $library_A, $borrowernumber, $biblionumber, '', 1 );
80
my ( $status ) = CheckReserves($itemnumber);
81
my ( $status ) = CheckReserves($itemnumber);
81
is( $status, 'Reserved', "Hold where pickup branch matches home branch targeted" );
82
is( $status, 'Reserved', "Hold where pickup branch matches home branch targeted" );
82
CancelReserve( { reserve_id => $reserve_id } );
83
Koha::Holds->find( $reserve_id )->cancel;
83
84
84
# Holding branch matches pickup branch
85
# Holding branch matches pickup branch
85
$reserve_id = AddReserve( $library_B, $borrowernumber, $biblionumber, '', 1 );
86
$reserve_id = AddReserve( $library_B, $borrowernumber, $biblionumber, '', 1 );
86
( $status ) = CheckReserves($itemnumber);
87
( $status ) = CheckReserves($itemnumber);
87
is($status, q{}, "Hold where pickup ne home, pickup eq home not targeted" );
88
is($status, q{}, "Hold where pickup ne home, pickup eq home not targeted" );
88
CancelReserve( { reserve_id => $reserve_id } );
89
Koha::Holds->find( $reserve_id )->cancel;
89
90
90
# Neither branch matches pickup branch
91
# Neither branch matches pickup branch
91
$reserve_id = AddReserve( $library_C, $borrowernumber, $biblionumber, '', 1 );
92
$reserve_id = AddReserve( $library_C, $borrowernumber, $biblionumber, '', 1 );
92
( $status ) = CheckReserves($itemnumber);
93
( $status ) = CheckReserves($itemnumber);
93
is( $status, q{}, "Hold where pickup ne home, pickup ne holding not targeted" );
94
is( $status, q{}, "Hold where pickup ne home, pickup ne holding not targeted" );
94
CancelReserve( { reserve_id => $reserve_id } );
95
Koha::Holds->find( $reserve_id )->cancel;
95
96
96
# With hold_fulfillment_policy = holdingbranch, hold should only be picked up if pickup branch = holdingbranch
97
# With hold_fulfillment_policy = holdingbranch, hold should only be picked up if pickup branch = holdingbranch
97
$dbh->do("DELETE FROM default_circ_rules");
98
$dbh->do("DELETE FROM default_circ_rules");
Lines 101-119 $dbh->do("INSERT INTO default_circ_rules ( holdallowed, hold_fulfillment_policy Link Here
101
$reserve_id = AddReserve( $library_A, $borrowernumber, $biblionumber, '', 1 );
102
$reserve_id = AddReserve( $library_A, $borrowernumber, $biblionumber, '', 1 );
102
( $status ) = CheckReserves($itemnumber);
103
( $status ) = CheckReserves($itemnumber);
103
is( $status, q{}, "Hold where pickup eq home, pickup ne holding not targeted" );
104
is( $status, q{}, "Hold where pickup eq home, pickup ne holding not targeted" );
104
CancelReserve( { reserve_id => $reserve_id } );
105
Koha::Holds->find( $reserve_id )->cancel;
105
106
106
# Holding branch matches pickup branch
107
# Holding branch matches pickup branch
107
$reserve_id = AddReserve( $library_B, $borrowernumber, $biblionumber, '', 1 );
108
$reserve_id = AddReserve( $library_B, $borrowernumber, $biblionumber, '', 1 );
108
( $status ) = CheckReserves($itemnumber);
109
( $status ) = CheckReserves($itemnumber);
109
is( $status, 'Reserved', "Hold where pickup ne home, pickup eq holding targeted" );
110
is( $status, 'Reserved', "Hold where pickup ne home, pickup eq holding targeted" );
110
CancelReserve( { reserve_id => $reserve_id } );
111
Koha::Holds->find( $reserve_id )->cancel;
111
112
112
# Neither branch matches pickup branch
113
# Neither branch matches pickup branch
113
$reserve_id = AddReserve( $library_C, $borrowernumber, $biblionumber, '', 1 );
114
$reserve_id = AddReserve( $library_C, $borrowernumber, $biblionumber, '', 1 );
114
( $status ) = CheckReserves($itemnumber);
115
( $status ) = CheckReserves($itemnumber);
115
is( $status, q{}, "Hold where pickup ne home, pickup ne holding not targeted" );
116
is( $status, q{}, "Hold where pickup ne home, pickup ne holding not targeted" );
116
CancelReserve( { reserve_id => $reserve_id } );
117
Koha::Holds->find( $reserve_id )->cancel;
117
118
118
# With hold_fulfillment_policy = any, hold should be pikcup up reguardless of matching home or holding branch
119
# With hold_fulfillment_policy = any, hold should be pikcup up reguardless of matching home or holding branch
119
$dbh->do("DELETE FROM default_circ_rules");
120
$dbh->do("DELETE FROM default_circ_rules");
Lines 123-138 $dbh->do("INSERT INTO default_circ_rules ( holdallowed, hold_fulfillment_policy Link Here
123
$reserve_id = AddReserve( $library_A, $borrowernumber, $biblionumber, '', 1 );
124
$reserve_id = AddReserve( $library_A, $borrowernumber, $biblionumber, '', 1 );
124
( $status ) = CheckReserves($itemnumber);
125
( $status ) = CheckReserves($itemnumber);
125
is( $status, 'Reserved', "Hold where pickup eq home, pickup ne holding targeted" );
126
is( $status, 'Reserved', "Hold where pickup eq home, pickup ne holding targeted" );
126
CancelReserve( { reserve_id => $reserve_id } );
127
Koha::Holds->find( $reserve_id )->cancel;
127
128
128
# Holding branch matches pickup branch
129
# Holding branch matches pickup branch
129
$reserve_id = AddReserve( $library_B, $borrowernumber, $biblionumber, '', 1 );
130
$reserve_id = AddReserve( $library_B, $borrowernumber, $biblionumber, '', 1 );
130
( $status ) = CheckReserves($itemnumber);
131
( $status ) = CheckReserves($itemnumber);
131
is( $status, 'Reserved', "Hold where pickup ne home, pickup eq holding targeted" );
132
is( $status, 'Reserved', "Hold where pickup ne home, pickup eq holding targeted" );
132
CancelReserve( { reserve_id => $reserve_id } );
133
Koha::Holds->find( $reserve_id )->cancel;
133
134
134
# Neither branch matches pickup branch
135
# Neither branch matches pickup branch
135
$reserve_id = AddReserve( $library_C, $borrowernumber, $biblionumber, '', 1 );
136
$reserve_id = AddReserve( $library_C, $borrowernumber, $biblionumber, '', 1 );
136
( $status ) = CheckReserves($itemnumber);
137
( $status ) = CheckReserves($itemnumber);
137
is( $status, 'Reserved', "Hold where pickup ne home, pickup ne holding targeted" );
138
is( $status, 'Reserved', "Hold where pickup ne home, pickup ne holding targeted" );
138
CancelReserve( { reserve_id => $reserve_id } );
139
Koha::Holds->find( $reserve_id )->cancel;
(-)a/t/db_dependent/Holds/HoldItemtypeLimit.t (-3 / +5 lines)
Lines 8-13 use Test::More tests => 4; Link Here
8
8
9
use t::lib::TestBuilder;
9
use t::lib::TestBuilder;
10
10
11
use Koha::Holds;
12
11
BEGIN {
13
BEGIN {
12
    use FindBin;
14
    use FindBin;
13
    use lib $FindBin::Bin;
15
    use lib $FindBin::Bin;
Lines 94-112 $dbh->do("INSERT INTO default_circ_rules ( holdallowed, hold_fulfillment_policy Link Here
94
my $reserve_id = AddReserve( $branchcode, $borrowernumber, $biblionumber, '', 1, undef, undef, undef, undef, undef, undef, $right_itemtype );
96
my $reserve_id = AddReserve( $branchcode, $borrowernumber, $biblionumber, '', 1, undef, undef, undef, undef, undef, undef, $right_itemtype );
95
my ( $status ) = CheckReserves($itemnumber);
97
my ( $status ) = CheckReserves($itemnumber);
96
is( $status, 'Reserved', "Hold where itemtype matches item's itemtype targed" );
98
is( $status, 'Reserved', "Hold where itemtype matches item's itemtype targed" );
97
CancelReserve( { reserve_id => $reserve_id } );
99
Koha::Holds->find( $reserve_id )->cancel;
98
100
99
# Itemtypes don't match
101
# Itemtypes don't match
100
$reserve_id = AddReserve( $branchcode, $borrowernumber, $biblionumber, '', 1, undef, undef, undef, undef, undef, undef, $wrong_itemtype );
102
$reserve_id = AddReserve( $branchcode, $borrowernumber, $biblionumber, '', 1, undef, undef, undef, undef, undef, undef, $wrong_itemtype );
101
( $status ) = CheckReserves($itemnumber);
103
( $status ) = CheckReserves($itemnumber);
102
is($status, q{}, "Hold where itemtype does not match item's itemtype not targeted" );
104
is($status, q{}, "Hold where itemtype does not match item's itemtype not targeted" );
103
CancelReserve( { reserve_id => $reserve_id } );
105
Koha::Holds->find( $reserve_id )->cancel;
104
106
105
# No itemtype set
107
# No itemtype set
106
$reserve_id = AddReserve( $branchcode, $borrowernumber, $biblionumber, '', 1, undef, undef, undef, undef, undef, undef, undef );
108
$reserve_id = AddReserve( $branchcode, $borrowernumber, $biblionumber, '', 1, undef, undef, undef, undef, undef, undef, undef );
107
( $status ) = CheckReserves($itemnumber);
109
( $status ) = CheckReserves($itemnumber);
108
is( $status, 'Reserved', "Item targeted with no hold itemtype set" );
110
is( $status, 'Reserved', "Item targeted with no hold itemtype set" );
109
CancelReserve( { reserve_id => $reserve_id } );
111
Koha::Holds->find( $reserve_id )->cancel;
110
112
111
# Cleanup
113
# Cleanup
112
$schema->storage->txn_rollback;
114
$schema->storage->txn_rollback;
(-)a/t/db_dependent/HoldsQueue.t (-12 / +13 lines)
Lines 17-22 use C4::Members; Link Here
17
use Koha::Database;
17
use Koha::Database;
18
use Koha::DateUtils;
18
use Koha::DateUtils;
19
use Koha::Items;
19
use Koha::Items;
20
use Koha::Holds;
20
21
21
use t::lib::TestBuilder;
22
use t::lib::TestBuilder;
22
use t::lib::Mocks;
23
use t::lib::Mocks;
Lines 561-581 $reserve_id = AddReserve( $library_A, $borrowernumber, $biblionumber, '', 1 ); Link Here
561
C4::HoldsQueue::CreateQueue();
562
C4::HoldsQueue::CreateQueue();
562
$holds_queue = $dbh->selectall_arrayref( "SELECT * FROM tmp_holdsqueue", { Slice => {} } );
563
$holds_queue = $dbh->selectall_arrayref( "SELECT * FROM tmp_holdsqueue", { Slice => {} } );
563
is( @$holds_queue, 1, "Hold where pickup branch matches home branch targeted" );
564
is( @$holds_queue, 1, "Hold where pickup branch matches home branch targeted" );
564
CancelReserve( { reserve_id => $reserve_id } );
565
Koha::Holds->find( $reserve_id )->cancel;
565
566
566
# Holding branch matches pickup branch
567
# Holding branch matches pickup branch
567
$reserve_id = AddReserve( $library_B, $borrowernumber, $biblionumber, '', 1 );
568
$reserve_id = AddReserve( $library_B, $borrowernumber, $biblionumber, '', 1 );
568
C4::HoldsQueue::CreateQueue();
569
C4::HoldsQueue::CreateQueue();
569
$holds_queue = $dbh->selectall_arrayref( "SELECT * FROM tmp_holdsqueue", { Slice => {} } );
570
$holds_queue = $dbh->selectall_arrayref( "SELECT * FROM tmp_holdsqueue", { Slice => {} } );
570
is( @$holds_queue, 0, "Hold where pickup ne home, pickup eq home not targeted" );
571
is( @$holds_queue, 0, "Hold where pickup ne home, pickup eq home not targeted" );
571
CancelReserve( { reserve_id => $reserve_id } );
572
Koha::Holds->find( $reserve_id )->cancel;
572
573
573
# Neither branch matches pickup branch
574
# Neither branch matches pickup branch
574
$reserve_id = AddReserve( $library_C, $borrowernumber, $biblionumber, '', 1 );
575
$reserve_id = AddReserve( $library_C, $borrowernumber, $biblionumber, '', 1 );
575
C4::HoldsQueue::CreateQueue();
576
C4::HoldsQueue::CreateQueue();
576
$holds_queue = $dbh->selectall_arrayref( "SELECT * FROM tmp_holdsqueue", { Slice => {} } );
577
$holds_queue = $dbh->selectall_arrayref( "SELECT * FROM tmp_holdsqueue", { Slice => {} } );
577
is( @$holds_queue, 0, "Hold where pickup ne home, pickup ne holding not targeted" );
578
is( @$holds_queue, 0, "Hold where pickup ne home, pickup ne holding not targeted" );
578
CancelReserve( { reserve_id => $reserve_id } );
579
Koha::Holds->find( $reserve_id )->cancel;
579
580
580
# With hold_fulfillment_policy = holdingbranch, hold should only be picked up if pickup branch = holdingbranch
581
# With hold_fulfillment_policy = holdingbranch, hold should only be picked up if pickup branch = holdingbranch
581
$dbh->do("DELETE FROM default_circ_rules");
582
$dbh->do("DELETE FROM default_circ_rules");
Lines 586-606 $reserve_id = AddReserve( $library_A, $borrowernumber, $biblionumber, '', 1 ); Link Here
586
C4::HoldsQueue::CreateQueue();
587
C4::HoldsQueue::CreateQueue();
587
$holds_queue = $dbh->selectall_arrayref( "SELECT * FROM tmp_holdsqueue", { Slice => {} } );
588
$holds_queue = $dbh->selectall_arrayref( "SELECT * FROM tmp_holdsqueue", { Slice => {} } );
588
is( @$holds_queue, 0, "Hold where pickup eq home, pickup ne holding not targeted" );
589
is( @$holds_queue, 0, "Hold where pickup eq home, pickup ne holding not targeted" );
589
CancelReserve( { reserve_id => $reserve_id } );
590
Koha::Holds->find( $reserve_id )->cancel;
590
591
591
# Holding branch matches pickup branch
592
# Holding branch matches pickup branch
592
$reserve_id = AddReserve( $library_B, $borrowernumber, $biblionumber, '', 1 );
593
$reserve_id = AddReserve( $library_B, $borrowernumber, $biblionumber, '', 1 );
593
C4::HoldsQueue::CreateQueue();
594
C4::HoldsQueue::CreateQueue();
594
$holds_queue = $dbh->selectall_arrayref( "SELECT * FROM tmp_holdsqueue", { Slice => {} } );
595
$holds_queue = $dbh->selectall_arrayref( "SELECT * FROM tmp_holdsqueue", { Slice => {} } );
595
is( @$holds_queue, 1, "Hold where pickup ne home, pickup eq holding targeted" );
596
is( @$holds_queue, 1, "Hold where pickup ne home, pickup eq holding targeted" );
596
CancelReserve( { reserve_id => $reserve_id } );
597
Koha::Holds->find( $reserve_id )->cancel;
597
598
598
# Neither branch matches pickup branch
599
# Neither branch matches pickup branch
599
$reserve_id = AddReserve( $library_C, $borrowernumber, $biblionumber, '', 1 );
600
$reserve_id = AddReserve( $library_C, $borrowernumber, $biblionumber, '', 1 );
600
C4::HoldsQueue::CreateQueue();
601
C4::HoldsQueue::CreateQueue();
601
$holds_queue = $dbh->selectall_arrayref( "SELECT * FROM tmp_holdsqueue", { Slice => {} } );
602
$holds_queue = $dbh->selectall_arrayref( "SELECT * FROM tmp_holdsqueue", { Slice => {} } );
602
is( @$holds_queue, 0, "Hold where pickup ne home, pickup ne holding not targeted" );
603
is( @$holds_queue, 0, "Hold where pickup ne home, pickup ne holding not targeted" );
603
CancelReserve( { reserve_id => $reserve_id } );
604
Koha::Holds->find( $reserve_id )->cancel;
604
605
605
# With hold_fulfillment_policy = any, hold should be pikcup up reguardless of matching home or holding branch
606
# With hold_fulfillment_policy = any, hold should be pikcup up reguardless of matching home or holding branch
606
$dbh->do("DELETE FROM default_circ_rules");
607
$dbh->do("DELETE FROM default_circ_rules");
Lines 611-631 $reserve_id = AddReserve( $library_A, $borrowernumber, $biblionumber, '', 1 ); Link Here
611
C4::HoldsQueue::CreateQueue();
612
C4::HoldsQueue::CreateQueue();
612
$holds_queue = $dbh->selectall_arrayref( "SELECT * FROM tmp_holdsqueue", { Slice => {} } );
613
$holds_queue = $dbh->selectall_arrayref( "SELECT * FROM tmp_holdsqueue", { Slice => {} } );
613
is( @$holds_queue, 1, "Hold where pickup eq home, pickup ne holding targeted" );
614
is( @$holds_queue, 1, "Hold where pickup eq home, pickup ne holding targeted" );
614
CancelReserve( { reserve_id => $reserve_id } );
615
Koha::Holds->find( $reserve_id )->cancel;
615
616
616
# Holding branch matches pickup branch
617
# Holding branch matches pickup branch
617
$reserve_id = AddReserve( $library_B, $borrowernumber, $biblionumber, '', 1 );
618
$reserve_id = AddReserve( $library_B, $borrowernumber, $biblionumber, '', 1 );
618
C4::HoldsQueue::CreateQueue();
619
C4::HoldsQueue::CreateQueue();
619
$holds_queue = $dbh->selectall_arrayref( "SELECT * FROM tmp_holdsqueue", { Slice => {} } );
620
$holds_queue = $dbh->selectall_arrayref( "SELECT * FROM tmp_holdsqueue", { Slice => {} } );
620
is( @$holds_queue, 1, "Hold where pickup ne home, pickup eq holding targeted" );
621
is( @$holds_queue, 1, "Hold where pickup ne home, pickup eq holding targeted" );
621
CancelReserve( { reserve_id => $reserve_id } );
622
Koha::Holds->find( $reserve_id )->cancel;
622
623
623
# Neither branch matches pickup branch
624
# Neither branch matches pickup branch
624
$reserve_id = AddReserve( $library_C, $borrowernumber, $biblionumber, '', 1 );
625
$reserve_id = AddReserve( $library_C, $borrowernumber, $biblionumber, '', 1 );
625
C4::HoldsQueue::CreateQueue();
626
C4::HoldsQueue::CreateQueue();
626
$holds_queue = $dbh->selectall_arrayref( "SELECT * FROM tmp_holdsqueue", { Slice => {} } );
627
$holds_queue = $dbh->selectall_arrayref( "SELECT * FROM tmp_holdsqueue", { Slice => {} } );
627
is( @$holds_queue, 1, "Hold where pickup ne home, pickup ne holding targeted" );
628
is( @$holds_queue, 1, "Hold where pickup ne home, pickup ne holding targeted" );
628
CancelReserve( { reserve_id => $reserve_id } );
629
Koha::Holds->find( $reserve_id )->cancel;
629
630
630
# End testing hold_fulfillment_policy
631
# End testing hold_fulfillment_policy
631
632
Lines 673-693 $reserve_id = AddReserve( $library_A, $borrowernumber, $biblionumber, '', 1, und Link Here
673
C4::HoldsQueue::CreateQueue();
674
C4::HoldsQueue::CreateQueue();
674
$holds_queue = $dbh->selectall_arrayref( "SELECT * FROM tmp_holdsqueue", { Slice => {} } );
675
$holds_queue = $dbh->selectall_arrayref( "SELECT * FROM tmp_holdsqueue", { Slice => {} } );
675
is( @$holds_queue, 0, "Item with incorrect itemtype not targeted" );
676
is( @$holds_queue, 0, "Item with incorrect itemtype not targeted" );
676
CancelReserve( { reserve_id => $reserve_id } );
677
Koha::Holds->find( $reserve_id )->cancel;
677
678
678
# Holding branch matches pickup branch
679
# Holding branch matches pickup branch
679
$reserve_id = AddReserve( $library_A, $borrowernumber, $biblionumber, '', 1, undef, undef, undef, undef, undef, undef, $right_itemtype );
680
$reserve_id = AddReserve( $library_A, $borrowernumber, $biblionumber, '', 1, undef, undef, undef, undef, undef, undef, $right_itemtype );
680
C4::HoldsQueue::CreateQueue();
681
C4::HoldsQueue::CreateQueue();
681
$holds_queue = $dbh->selectall_arrayref( "SELECT * FROM tmp_holdsqueue", { Slice => {} } );
682
$holds_queue = $dbh->selectall_arrayref( "SELECT * FROM tmp_holdsqueue", { Slice => {} } );
682
is( @$holds_queue, 1, "Item with matching itemtype is targeted" );
683
is( @$holds_queue, 1, "Item with matching itemtype is targeted" );
683
CancelReserve( { reserve_id => $reserve_id } );
684
Koha::Holds->find( $reserve_id )->cancel;
684
685
685
# Neither branch matches pickup branch
686
# Neither branch matches pickup branch
686
$reserve_id = AddReserve( $library_A, $borrowernumber, $biblionumber, '', 1, undef, undef, undef, undef, undef, undef, undef );
687
$reserve_id = AddReserve( $library_A, $borrowernumber, $biblionumber, '', 1, undef, undef, undef, undef, undef, undef, undef );
687
C4::HoldsQueue::CreateQueue();
688
C4::HoldsQueue::CreateQueue();
688
$holds_queue = $dbh->selectall_arrayref( "SELECT * FROM tmp_holdsqueue", { Slice => {} } );
689
$holds_queue = $dbh->selectall_arrayref( "SELECT * FROM tmp_holdsqueue", { Slice => {} } );
689
is( @$holds_queue, 1, "Item targeted when hold itemtype is not set" );
690
is( @$holds_queue, 1, "Item targeted when hold itemtype is not set" );
690
CancelReserve( { reserve_id => $reserve_id } );
691
Koha::Holds->find( $reserve_id )->cancel;
691
692
692
# End testing hold itemtype limit
693
# End testing hold itemtype limit
693
694
(-)a/t/db_dependent/Reserves.t (-12 / +6 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 70;
20
use Test::More tests => 67;
21
use Test::MockModule;
21
use Test::MockModule;
22
use Test::Warn;
22
use Test::Warn;
23
23
Lines 321-336 $holds = $biblio->holds; Link Here
321
is($holds->count, 1, "Only one reserves for this biblio");
321
is($holds->count, 1, "Only one reserves for this biblio");
322
my $reserve_id = $holds->next->reserve_id;
322
my $reserve_id = $holds->next->reserve_id;
323
323
324
$reserve = CancelReserve({reserve_id => $reserve_id});
324
Koha::Holds->find( $reserve_id )->cancel;
325
isa_ok($reserve, 'HASH', "CancelReserve return");
326
is($reserve->{biblionumber}, $biblionumber);
327
325
328
my $hold = Koha::Holds->find( $reserve_id );
326
my $hold = Koha::Holds->find( $reserve_id );
329
is($hold, undef, "CancelReserve should have cancel the reserve");
327
is($hold, undef, "Koha::Holds->cancel should have cancel the reserve");
330
331
$reserve = CancelReserve({reserve_id => $reserve_id});
332
is($reserve, undef, "CancelReserve return undef if reserve does not exist");
333
334
328
335
# Tests for bug 9761 (ConfirmFutureHolds): new CheckReserves lookahead parameter, and corresponding change in AddReturn
329
# Tests for bug 9761 (ConfirmFutureHolds): new CheckReserves lookahead parameter, and corresponding change in AddReturn
336
# Note that CheckReserve uses its lookahead parameter and does not check ConfirmFutureHolds pref (it should be passed if needed like AddReturn does)
330
# Note that CheckReserve uses its lookahead parameter and does not check ConfirmFutureHolds pref (it should be passed if needed like AddReturn does)
Lines 602-608 my $bz14464_reserve = AddReserve( Link Here
602
596
603
ok( $bz14464_reserve, 'Bug 14464 - 1st reserve correctly created' );
597
ok( $bz14464_reserve, 'Bug 14464 - 1st reserve correctly created' );
604
598
605
CancelReserve({ reserve_id => $bz14464_reserve, charge_cancel_fee => 1 });
599
Koha::Holds->find( $bz14464_reserve )->cancel( { charge_cancel_fee => 1 } );
606
600
607
my $old_reserve = Koha::Database->new()->schema()->resultset('OldReserve')->find( $bz14464_reserve );
601
my $old_reserve = Koha::Database->new()->schema()->resultset('OldReserve')->find( $bz14464_reserve );
608
is($old_reserve->get_column('found'), 'W', 'Bug 14968 - Keep found column from reserve');
602
is($old_reserve->get_column('found'), 'W', 'Bug 14968 - Keep found column from reserve');
Lines 629-635 $bz14464_reserve = AddReserve( Link Here
629
623
630
ok( $bz14464_reserve, 'Bug 14464 - 2nd reserve correctly created' );
624
ok( $bz14464_reserve, 'Bug 14464 - 2nd reserve correctly created' );
631
625
632
CancelReserve({ reserve_id => $bz14464_reserve });
626
Koha::Holds->find( $bz14464_reserve )->cancel();
633
627
634
$bz14464_fines = $patron->account->balance;
628
$bz14464_fines = $patron->account->balance;
635
is( !$bz14464_fines || $bz14464_fines==0, 1, 'Bug 14464 - No fines after cancelling reserve with no charge desired' );
629
is( !$bz14464_fines || $bz14464_fines==0, 1, 'Bug 14464 - No fines after cancelling reserve with no charge desired' );
Lines 651-657 $bz14464_reserve = AddReserve( Link Here
651
645
652
ok( $bz14464_reserve, 'Bug 14464 - 1st reserve correctly created' );
646
ok( $bz14464_reserve, 'Bug 14464 - 1st reserve correctly created' );
653
647
654
CancelReserve({ reserve_id => $bz14464_reserve, charge_cancel_fee => 1 });
648
Koha::Holds->find( $bz14464_reserve )->cancel( { charge_cancel_fee => 1 } );
655
649
656
$bz14464_fines = $patron->account->balance;
650
$bz14464_fines = $patron->account->balance;
657
is( int( $bz14464_fines ), 42, 'Bug 14464 - Fine applied after cancelling reserve with charge desired and configured' );
651
is( int( $bz14464_fines ), 42, 'Bug 14464 - Fine applied after cancelling reserve with charge desired and configured' );
(-)a/t/db_dependent/UsageStats.t (-1 / +1 lines)
Lines 304-310 sub construct_objects_needed { Link Here
304
    AddReserve( $branchcode, $borrowernumber1, $biblionumber1, '', 1, undef, undef, '', 'Title', undef, undef );
304
    AddReserve( $branchcode, $borrowernumber1, $biblionumber1, '', 1, undef, undef, '', 'Title', undef, undef );
305
    my $biblio = Koha::Biblios->find( $biblionumber1 );
305
    my $biblio = Koha::Biblios->find( $biblionumber1 );
306
    my $holds = $biblio->holds;
306
    my $holds = $biblio->holds;
307
    CancelReserve( { reserve_id => $holds->next->reserve_id } );
307
    $holds->next->cancel if $holds->count;
308
308
309
    # ---------- Add 1 aqbudgets
309
    # ---------- Add 1 aqbudgets
310
    $query = '
310
    $query = '
(-)a/tools/batch_delete_records.pl (-2 / +1 lines)
Lines 147-153 if ( $op eq 'form' ) { Link Here
147
            my $holds = $biblio->holds;
147
            my $holds = $biblio->holds;
148
            while ( my $hold = $holds->next ) {
148
            while ( my $hold = $holds->next ) {
149
                eval{
149
                eval{
150
                    C4::Reserves::CancelReserve( { reserve_id => $hold->reserve_id } );
150
                    $hold->cancel;
151
                };
151
                };
152
                if ( $@ ) {
152
                if ( $@ ) {
153
                    push @messages, {
153
                    push @messages, {
154
- 

Return to bug 19059