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

(-)a/C4/ILSDI/Services.pm (-2 / +3 lines)
Lines 24-30 use C4::Members; Link Here
24
use C4::Items qw( get_hostitemnumbers_of );
24
use C4::Items qw( get_hostitemnumbers_of );
25
use C4::Circulation qw( CanBookBeRenewed barcodedecode CanBookBeIssued AddRenewal );
25
use C4::Circulation qw( CanBookBeRenewed barcodedecode CanBookBeIssued AddRenewal );
26
use C4::Accounts;
26
use C4::Accounts;
27
use C4::Reserves qw( CanBookBeReserved IsAvailableForItemLevelRequest CalculatePriority AddReserve CanItemBeReserved CanReserveBeCanceledFromOpac );
27
use C4::Reserves qw( CanBookBeReserved IsAvailableForItemLevelRequest CalculatePriority AddReserve CanItemBeReserved );
28
use C4::Context;
28
use C4::Context;
29
use C4::Auth;
29
use C4::Auth;
30
use CGI qw ( -utf8 );
30
use CGI qw ( -utf8 );
Lines 39-44 use Koha::I18N qw(__); Link Here
39
use Koha::Items;
39
use Koha::Items;
40
use Koha::Libraries;
40
use Koha::Libraries;
41
use Koha::Patrons;
41
use Koha::Patrons;
42
use Koha::Policy::Patrons::Holds;
42
43
43
=head1 NAME
44
=head1 NAME
44
45
Lines 942-948 sub CancelHold { Link Here
942
    return { code => 'RecordNotFound' } unless $hold;
943
    return { code => 'RecordNotFound' } unless $hold;
943
944
944
    # Check if reserve belongs to the borrower and if it is in a state which allows cancellation
945
    # Check if reserve belongs to the borrower and if it is in a state which allows cancellation
945
    return { code => 'BorrowerCannotCancelHold' } unless CanReserveBeCanceledFromOpac( $reserve_id, $borrowernumber );
946
    return { code => 'BorrowerCannotCancelHold' } unless Koha::Policy::Patrons::Holds->can_cancel_from_opac( $patron, $hold );
946
947
947
    $hold->cancel;
948
    $hold->cancel;
948
949
(-)a/C4/Reserves.pm (-21 lines)
Lines 118-124 BEGIN { Link Here
118
      CheckReserves
118
      CheckReserves
119
      CanBookBeReserved
119
      CanBookBeReserved
120
      CanItemBeReserved
120
      CanItemBeReserved
121
      CanReserveBeCanceledFromOpac
122
      CancelExpiredReserves
121
      CancelExpiredReserves
123
122
124
      AutoUnsuspendReserves
123
      AutoUnsuspendReserves
Lines 687-712 sub CanItemBeReserved { Link Here
687
    return _cache { status => 'OK' };
686
    return _cache { status => 'OK' };
688
}
687
}
689
688
690
=head2 CanReserveBeCanceledFromOpac
691
692
    $number = CanReserveBeCanceledFromOpac($reserve_id, $borrowernumber);
693
694
    returns 1 if reserve can be cancelled by user from OPAC.
695
    First check if reserve belongs to user, next checks if reserve is not in
696
    transfer or waiting status
697
698
=cut
699
700
sub CanReserveBeCanceledFromOpac {
701
    my ($reserve_id, $borrowernumber) = @_;
702
703
    return unless $reserve_id and $borrowernumber;
704
    my $reserve = Koha::Holds->find($reserve_id) or return;
705
706
    return 0 unless $reserve->borrowernumber == $borrowernumber;
707
    return $reserve->is_cancelable_from_opac;
708
}
709
710
=head2 ChargeReserveFee
689
=head2 ChargeReserveFee
711
690
712
    $fee = ChargeReserveFee( $borrowernumber, $fee, $title );
691
    $fee = ChargeReserveFee( $borrowernumber, $fee, $title );
(-)a/Koha/Policy/Patrons/Holds.pm (+58 lines)
Line 0 Link Here
1
package Koha::Policy::Patrons::Holds;
2
3
# Copyright 2024 Koha Development team
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
use Modern::Perl;
21
22
use C4::Context;
23
24
use Koha::Result::Boolean;
25
26
=head1 NAME
27
28
Koha::Policy::Patrons::Holds - module to deal with holds policy for patrons
29
30
=head1 API
31
32
=head2 Class Methods
33
34
=head3 new
35
36
=cut
37
38
sub new {
39
    return bless {}, shift;
40
}
41
42
43
=head3 can_cancel_from_opac
44
45
my $can_cancel = Koha::Policy::Patrons::Holds->can_cancel_from_opac( $patron, $hold );
46
47
Returns whether a patron can cancel a given hold from the OPAC
48
49
=cut
50
51
sub can_cancel_from_opac {
52
    my ( $class, $patron, $hold ) = @_;
53
54
    my $can_cancel = ( $patron->borrowernumber == $hold->borrowernumber && $hold->is_cancelable_from_opac ) ? 1 : 0;
55
    return Koha::Result::Boolean->new($can_cancel);
56
}
57
58
1;
(-)a/opac/opac-modrequest-suspend.pl (-2 / +10 lines)
Lines 19-26 use Modern::Perl; Link Here
19
19
20
use CGI qw ( -utf8 );
20
use CGI qw ( -utf8 );
21
use C4::Output;
21
use C4::Output;
22
use C4::Reserves qw( CanReserveBeCanceledFromOpac ToggleSuspend SuspendAll );
22
use C4::Reserves qw( ToggleSuspend SuspendAll );
23
use C4::Auth qw( get_template_and_user );
23
use C4::Auth qw( get_template_and_user );
24
25
use Koha::Holds;
26
use Koha::Patrons;
27
use Koha::Policy::Patrons::Holds;
28
24
my $query = CGI->new;
29
my $query = CGI->new;
25
my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
30
my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
26
    {
31
    {
Lines 36-42 my $suspend_until = $query->param('suspend_until') || undef; Link Here
36
my $reserve_id    = $query->param('reserve_id');
41
my $reserve_id    = $query->param('reserve_id');
37
42
38
if ( ( $op eq 'cud-suspend' || $op eq 'cud-unsuspend' ) && $reserve_id ) {
43
if ( ( $op eq 'cud-suspend' || $op eq 'cud-unsuspend' ) && $reserve_id ) {
39
    ToggleSuspend( $reserve_id, $suspend_until ) if CanReserveBeCanceledFromOpac($reserve_id, $borrowernumber);
44
    my $patron = Koha::Patrons->find($borrowernumber);
45
    my $hold   = Koha::Holds->find($reserve_id);
46
    ToggleSuspend( $reserve_id, $suspend_until )
47
        if $patron && $hold && Koha::Policy::Patrons::Holds->can_cancel_from_opac( $patron, $hold );
40
}
48
}
41
elsif( $op eq 'cud-suspend_all' || $op eq 'cud-unsuspend_all' ) {
49
elsif( $op eq 'cud-suspend_all' || $op eq 'cud-unsuspend_all' ) {
42
    SuspendAll(
50
    SuspendAll(
(-)a/t/db_dependent/Reserves.t (-61 / +44 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 77;
20
use Test::More tests => 73;
21
use Test::MockModule;
21
use Test::MockModule;
22
use Test::Warn;
22
use Test::Warn;
23
23
Lines 32-38 use C4::Items; Link Here
32
use C4::Biblio qw( GetMarcFromKohaField ModBiblio );
32
use C4::Biblio qw( GetMarcFromKohaField ModBiblio );
33
use C4::HoldsQueue;
33
use C4::HoldsQueue;
34
use C4::Members;
34
use C4::Members;
35
use C4::Reserves qw( AddReserve AlterPriority CheckReserves ModReserve ModReserveAffect ReserveSlip CalculatePriority CanReserveBeCanceledFromOpac CanBookBeReserved IsAvailableForItemLevelRequest MoveReserve ChargeReserveFee RevertWaitingStatus CanItemBeReserved MergeHolds );
35
use C4::Reserves qw( AddReserve AlterPriority CheckReserves ModReserve ModReserveAffect ReserveSlip CalculatePriority CanBookBeReserved IsAvailableForItemLevelRequest MoveReserve ChargeReserveFee RevertWaitingStatus CanItemBeReserved MergeHolds );
36
use Koha::ActionLogs;
36
use Koha::ActionLogs;
37
use Koha::Biblios;
37
use Koha::Biblios;
38
use Koha::Caches;
38
use Koha::Caches;
Lines 44-49 use Koha::Notice::Templates; Link Here
44
use Koha::Patrons;
44
use Koha::Patrons;
45
use Koha::Patron::Categories;
45
use Koha::Patron::Categories;
46
use Koha::CirculationRules;
46
use Koha::CirculationRules;
47
use Koha::Policy::Patrons::Holds;
47
48
48
BEGIN {
49
BEGIN {
49
    require_ok('C4::Reserves');
50
    require_ok('C4::Reserves');
Lines 136-159 $requesters{$branch_1} = Koha::Patron->new({ Link Here
136
    branchcode   => $branch_1,
137
    branchcode   => $branch_1,
137
    categorycode => $category_2,
138
    categorycode => $category_2,
138
    surname      => "borrower from $branch_1",
139
    surname      => "borrower from $branch_1",
139
})->store->borrowernumber;
140
})->store;
140
for my $i ( 2 .. 5 ) {
141
for my $i ( 2 .. 5 ) {
141
    $requesters{"CPL$i"} = Koha::Patron->new({
142
    $requesters{"CPL$i"} = Koha::Patron->new({
142
        branchcode   => $branch_1,
143
        branchcode   => $branch_1,
143
        categorycode => $category_2,
144
        categorycode => $category_2,
144
        surname      => "borrower $i from $branch_1",
145
        surname      => "borrower $i from $branch_1",
145
    })->store->borrowernumber;
146
    })->store;
146
}
147
}
147
$requesters{$branch_2} = Koha::Patron->new({
148
$requesters{$branch_2} = Koha::Patron->new({
148
    branchcode   => $branch_2,
149
    branchcode   => $branch_2,
149
    categorycode => $category_2,
150
    categorycode => $category_2,
150
    surname      => "borrower from $branch_2",
151
    surname      => "borrower from $branch_2",
151
})->store->borrowernumber;
152
})->store;
152
$requesters{$branch_3} = Koha::Patron->new({
153
$requesters{$branch_3} = Koha::Patron->new({
153
    branchcode   => $branch_3,
154
    branchcode   => $branch_3,
154
    categorycode => $category_2,
155
    categorycode => $category_2,
155
    surname      => "borrower from $branch_3",
156
    surname      => "borrower from $branch_3",
156
})->store->borrowernumber;
157
})->store;
157
158
158
# Configure rules so that $branch_1 allows only $branch_1 patrons
159
# Configure rules so that $branch_1 allows only $branch_1 patrons
159
# to request its items, while $branch_2 will allow its items
160
# to request its items, while $branch_2 will allow its items
Lines 222-228 $dbh->do("DELETE FROM reserves WHERE biblionumber=?",undef,($bibnum2)); Link Here
222
AddReserve(
223
AddReserve(
223
    {
224
    {
224
        branchcode     => $branch_3,
225
        branchcode     => $branch_3,
225
        borrowernumber => $requesters{$branch_3},
226
        borrowernumber => $requesters{$branch_3}->borrowernumber,
226
        biblionumber   => $bibnum2,
227
        biblionumber   => $bibnum2,
227
        priority       => 1,
228
        priority       => 1,
228
    }
229
    }
Lines 230-236 AddReserve( Link Here
230
AddReserve(
231
AddReserve(
231
    {
232
    {
232
        branchcode     => $branch_2,
233
        branchcode     => $branch_2,
233
        borrowernumber => $requesters{$branch_2},
234
        borrowernumber => $requesters{$branch_2}->borrowernumber,
234
        biblionumber   => $bibnum2,
235
        biblionumber   => $bibnum2,
235
        priority       => 2,
236
        priority       => 2,
236
    }
237
    }
Lines 238-249 AddReserve( Link Here
238
AddReserve(
239
AddReserve(
239
    {
240
    {
240
        branchcode     => $branch_1,
241
        branchcode     => $branch_1,
241
        borrowernumber => $requesters{$branch_1},
242
        borrowernumber => $requesters{$branch_1}->borrowernumber,
242
        biblionumber   => $bibnum2,
243
        biblionumber   => $bibnum2,
243
        priority       => 3,
244
        priority       => 3,
244
    }
245
    }
245
);
246
);
246
ModReserveAffect($itemnum_cpl, $requesters{$branch_3}, 0);
247
ModReserveAffect($itemnum_cpl, $requesters{$branch_3}->borrowernumber, 0);
247
248
248
# Now it should have different priorities.
249
# Now it should have different priorities.
249
my $biblio = Koha::Biblios->find( $bibnum2 );
250
my $biblio = Koha::Biblios->find( $bibnum2 );
Lines 252-267 is($holds->next->priority, 0, 'Item is correctly waiting'); Link Here
252
is($holds->next->priority, 1, 'Item is correctly priority 1');
253
is($holds->next->priority, 1, 'Item is correctly priority 1');
253
is($holds->next->priority, 2, 'Item is correctly priority 2');
254
is($holds->next->priority, 2, 'Item is correctly priority 2');
254
255
255
my @reserves = Koha::Holds->search({ borrowernumber => $requesters{$branch_3} })->waiting->as_list;
256
my @reserves = Koha::Holds->search({ borrowernumber => $requesters{$branch_3}->borrowernumber })->waiting->as_list;
256
is( @reserves, 1, 'GetWaiting got only the waiting reserve' );
257
is( @reserves, 1, 'GetWaiting got only the waiting reserve' );
257
is( $reserves[0]->borrowernumber(), $requesters{$branch_3}, 'GetWaiting got the reserve for the correct borrower' );
258
is( $reserves[0]->borrowernumber(), $requesters{$branch_3}->borrowernumber, 'GetWaiting got the reserve for the correct borrower' );
258
259
259
260
260
$dbh->do("DELETE FROM reserves WHERE biblionumber=?",undef,($bibnum2));
261
$dbh->do("DELETE FROM reserves WHERE biblionumber=?",undef,($bibnum2));
261
AddReserve(
262
AddReserve(
262
    {
263
    {
263
        branchcode     => $branch_3,
264
        branchcode     => $branch_3,
264
        borrowernumber => $requesters{$branch_3},
265
        borrowernumber => $requesters{$branch_3}->borrowernumber,
265
        biblionumber   => $bibnum2,
266
        biblionumber   => $bibnum2,
266
        priority       => 1,
267
        priority       => 1,
267
    }
268
    }
Lines 269-275 AddReserve( Link Here
269
AddReserve(
270
AddReserve(
270
    {
271
    {
271
        branchcode     => $branch_2,
272
        branchcode     => $branch_2,
272
        borrowernumber => $requesters{$branch_2},
273
        borrowernumber => $requesters{$branch_2}->borrowernumber,
273
        biblionumber   => $bibnum2,
274
        biblionumber   => $bibnum2,
274
        priority       => 2,
275
        priority       => 2,
275
    }
276
    }
Lines 278-284 AddReserve( Link Here
278
AddReserve(
279
AddReserve(
279
    {
280
    {
280
        branchcode     => $branch_1,
281
        branchcode     => $branch_1,
281
        borrowernumber => $requesters{$branch_1},
282
        borrowernumber => $requesters{$branch_1}->borrowernumber,
282
        biblionumber   => $bibnum2,
283
        biblionumber   => $bibnum2,
283
        priority       => 3,
284
        priority       => 3,
284
    }
285
    }
Lines 293-299 my $messages; Link Here
293
# requests cannot be filled by that item per policy.
294
# requests cannot be filled by that item per policy.
294
(undef, $messages, undef, undef) = AddReturn('bug10272_CPL', $branch_2);
295
(undef, $messages, undef, undef) = AddReturn('bug10272_CPL', $branch_2);
295
is( $messages->{ResFound}->{borrowernumber},
296
is( $messages->{ResFound}->{borrowernumber},
296
    $requesters{$branch_1},
297
    $requesters{$branch_1}->borrowernumber,
297
    'restrictive library\'s items only fill requests by own patrons (bug 10272)');
298
    'restrictive library\'s items only fill requests by own patrons (bug 10272)');
298
299
299
# Return the FPL item at FPL.  The hold that should be triggered is
300
# Return the FPL item at FPL.  The hold that should be triggered is
Lines 305-311 t::lib::Mocks::mock_preference( 'LocalHoldsPriority', '' ); Link Here
305
306
306
(undef, $messages, undef, undef) = AddReturn('bug10272_FPL', $branch_2);
307
(undef, $messages, undef, undef) = AddReturn('bug10272_FPL', $branch_2);
307
is( $messages->{ResFound}->{borrowernumber},
308
is( $messages->{ResFound}->{borrowernumber},
308
    $requesters{$branch_3},
309
    $requesters{$branch_3}->borrowernumber,
309
    'for generous library, its items fill first hold request in line (bug 10272)');
310
    'for generous library, its items fill first hold request in line (bug 10272)');
310
311
311
$biblio = Koha::Biblios->find( $biblionumber );
312
$biblio = Koha::Biblios->find( $biblionumber );
Lines 320-326 $dbh->do("DELETE FROM reserves WHERE biblionumber=?",undef,($bibnum)); Link Here
320
AddReserve(
321
AddReserve(
321
    {
322
    {
322
        branchcode     => $branch_1,
323
        branchcode     => $branch_1,
323
        borrowernumber => $requesters{$branch_1},
324
        borrowernumber => $requesters{$branch_1}->borrowernumber,
324
        biblionumber   => $bibnum,
325
        biblionumber   => $bibnum,
325
        priority       => 1,
326
        priority       => 1,
326
    }
327
    }
Lines 338-344 $resdate->add_duration(DateTime::Duration->new(days => 4)); Link Here
338
my $reserve_id = AddReserve(
339
my $reserve_id = AddReserve(
339
    {
340
    {
340
        branchcode       => $branch_1,
341
        branchcode       => $branch_1,
341
        borrowernumber   => $requesters{$branch_1},
342
        borrowernumber   => $requesters{$branch_1}->borrowernumber,
342
        biblionumber     => $bibnum,
343
        biblionumber     => $bibnum,
343
        priority         => 1,
344
        priority         => 1,
344
        reservation_date => $resdate,
345
        reservation_date => $resdate,
Lines 372-378 my $now_holder = $builder->build_object({ class => 'Koha::Patrons', value => { Link Here
372
my $now_reserve_id = AddReserve(
373
my $now_reserve_id = AddReserve(
373
    {
374
    {
374
        branchcode       => $branch_1,
375
        branchcode       => $branch_1,
375
        borrowernumber   => $requesters{$branch_1},
376
        borrowernumber   => $requesters{$branch_1}->borrowernumber,
376
        biblionumber     => $bibnum,
377
        biblionumber     => $bibnum,
377
        priority         => 2,
378
        priority         => 2,
378
        reservation_date => dt_from_string(),
379
        reservation_date => dt_from_string(),
Lines 391-402 ModReserve({ reserve_id => $now_reserve_id, rank => 'del', cancellation_reason = Link Here
391
392
392
# test marking a hold as captured
393
# test marking a hold as captured
393
my $hold_notice_count = count_hold_print_messages();
394
my $hold_notice_count = count_hold_print_messages();
394
ModReserveAffect($item->itemnumber, $requesters{$branch_1}, 0);
395
ModReserveAffect($item->itemnumber, $requesters{$branch_1}->borrowernumber, 0);
395
my $new_count = count_hold_print_messages();
396
my $new_count = count_hold_print_messages();
396
is($new_count, $hold_notice_count + 1, 'patron notified when item set to waiting');
397
is($new_count, $hold_notice_count + 1, 'patron notified when item set to waiting');
397
398
398
# test that duplicate notices aren't generated
399
# test that duplicate notices aren't generated
399
ModReserveAffect($item->itemnumber, $requesters{$branch_1}, 0);
400
ModReserveAffect($item->itemnumber, $requesters{$branch_1}->borrowernumber, 0);
400
$new_count = count_hold_print_messages();
401
$new_count = count_hold_print_messages();
401
is($new_count, $hold_notice_count + 1, 'patron not notified a second time (bug 11445)');
402
is($new_count, $hold_notice_count + 1, 'patron not notified a second time (bug 11445)');
402
403
Lines 422-428 $resdate->add_duration(DateTime::Duration->new(days => 2)); Link Here
422
AddReserve(
423
AddReserve(
423
    {
424
    {
424
        branchcode       => $branch_1,
425
        branchcode       => $branch_1,
425
        borrowernumber   => $requesters{$branch_1},
426
        borrowernumber   => $requesters{$branch_1}->borrowernumber,
426
        biblionumber     => $bibnum,
427
        biblionumber     => $bibnum,
427
        priority         => 1,
428
        priority         => 1,
428
        reservation_date => $resdate,
429
        reservation_date => $resdate,
Lines 438-444 $dbh->do("DELETE FROM reserves WHERE biblionumber=?",undef,($bibnum)); Link Here
438
AddReserve(
439
AddReserve(
439
    {
440
    {
440
        branchcode       => $branch_1,
441
        branchcode       => $branch_1,
441
        borrowernumber   => $requesters{$branch_1},
442
        borrowernumber   => $requesters{$branch_1}->borrowernumber,
442
        biblionumber     => $bibnum,
443
        biblionumber     => $bibnum,
443
        priority         => 1,
444
        priority         => 1,
444
        reservation_date => $resdate,
445
        reservation_date => $resdate,
Lines 448-454 AddReserve( Link Here
448
$future_holds = $holds->search({ reservedate => { '>' => $dtf->format_date( dt_from_string ) } } );
449
$future_holds = $holds->search({ reservedate => { '>' => $dtf->format_date( dt_from_string ) } } );
449
is( $future_holds->count, 0, 'current_holds does not return a future item level hold' );
450
is( $future_holds->count, 0, 'current_holds does not return a future item level hold' );
450
# 9788c: current_holds returns future wait (confirmed future hold)
451
# 9788c: current_holds returns future wait (confirmed future hold)
451
ModReserveAffect( $item->itemnumber,  $requesters{$branch_1} , 0); #confirm hold
452
ModReserveAffect( $item->itemnumber,  $requesters{$branch_1}->borrowernumber, 0); #confirm hold
452
$future_holds = $holds->search({ reservedate => { '>' => $dtf->format_date( dt_from_string ) } } );
453
$future_holds = $holds->search({ reservedate => { '>' => $dtf->format_date( dt_from_string ) } } );
453
is( $future_holds->count, 1, 'current_holds returns a future wait (confirmed future hold)' );
454
is( $future_holds->count, 1, 'current_holds returns a future wait (confirmed future hold)' );
454
# End of tests for bug 9788
455
# End of tests for bug 9788
Lines 460-466 is($p, 4, 'CalculatePriority should now return priority 4'); Link Here
460
AddReserve(
461
AddReserve(
461
    {
462
    {
462
        branchcode     => $branch_1,
463
        branchcode     => $branch_1,
463
        borrowernumber => $requesters{'CPL2'},
464
        borrowernumber => $requesters{'CPL2'}->borrowernumber,
464
        biblionumber   => $bibnum2,
465
        biblionumber   => $bibnum2,
465
        priority       => $p,
466
        priority       => $p,
466
    }
467
    }
Lines 475-481 is($p, 1, 'CalculatePriority should now return priority 1'); Link Here
475
AddReserve(
476
AddReserve(
476
    {
477
    {
477
        branchcode     => $branch_1,
478
        branchcode     => $branch_1,
478
        borrowernumber => $requesters{$branch_1},
479
        borrowernumber => $requesters{$branch_1}->borrowernumber,
479
        biblionumber   => $bibnum,
480
        biblionumber   => $bibnum,
480
        priority       => $p,
481
        priority       => $p,
481
        itemnumber     => $item->itemnumber,
482
        itemnumber     => $item->itemnumber,
Lines 483-496 AddReserve( Link Here
483
);
484
);
484
$p = C4::Reserves::CalculatePriority($bibnum);
485
$p = C4::Reserves::CalculatePriority($bibnum);
485
is($p, 2, 'CalculatePriority should now return priority 2');
486
is($p, 2, 'CalculatePriority should now return priority 2');
486
ModReserveAffect( $item->itemnumber,  $requesters{$branch_1} , 0);
487
ModReserveAffect( $item->itemnumber,  $requesters{$branch_1}->borrowernumber, 0);
487
$p = C4::Reserves::CalculatePriority($bibnum);
488
$p = C4::Reserves::CalculatePriority($bibnum);
488
is($p, 1, 'CalculatePriority should now return priority 1');
489
is($p, 1, 'CalculatePriority should now return priority 1');
489
#add another biblio hold, no resdate
490
#add another biblio hold, no resdate
490
AddReserve(
491
AddReserve(
491
    {
492
    {
492
        branchcode     => $branch_1,
493
        branchcode     => $branch_1,
493
        borrowernumber => $requesters{'CPL2'},
494
        borrowernumber => $requesters{'CPL2'}->borrowernumber,
494
        biblionumber   => $bibnum,
495
        biblionumber   => $bibnum,
495
        priority       => $p,
496
        priority       => $p,
496
    }
497
    }
Lines 504-510 $resdate->add_duration(DateTime::Duration->new(days => 1)); Link Here
504
AddReserve(
505
AddReserve(
505
    {
506
    {
506
        branchcode     => $branch_1,
507
        branchcode     => $branch_1,
507
        borrowernumber => $requesters{'CPL2'},
508
        borrowernumber => $requesters{'CPL2'}->borrowernumber,
508
        biblionumber   => $bibnum,
509
        biblionumber   => $bibnum,
509
        priority       => $p,
510
        priority       => $p,
510
        reservation_date => $resdate,
511
        reservation_date => $resdate,
Lines 561-614 $dbh->do('DELETE FROM reserves', undef, ($bibnum)); Link Here
561
AddReserve(
562
AddReserve(
562
    {
563
    {
563
        branchcode     => $branch_1,
564
        branchcode     => $branch_1,
564
        borrowernumber => $requesters{$branch_1},
565
        borrowernumber => $requesters{$branch_1}->borrowernumber,
565
        biblionumber   => $bibnum,
566
        biblionumber   => $bibnum,
566
        priority       => 1,
567
        priority       => 1,
567
    }
568
    }
568
);
569
);
569
my (undef, $canres, undef) = CheckReserves( $item );
570
my (undef, $canres, undef) = CheckReserves( $item );
570
571
571
is( CanReserveBeCanceledFromOpac(), undef,
572
my $hold      = Koha::Holds->find( $canres->{reserve_id} );
572
    'CanReserveBeCanceledFromOpac should return undef if called without any parameter'
573
my $cancancel = Koha::Policy::Patrons::Holds->can_cancel_from_opac( $requesters{$branch_1}, $hold );
573
);
574
ok( $cancancel, 'Can user cancel its own reserve' );
574
is(
575
    CanReserveBeCanceledFromOpac( $canres->{resserve_id} ),
576
    undef,
577
    'CanReserveBeCanceledFromOpac should return undef if called without the reserve_id'
578
);
579
is(
580
    CanReserveBeCanceledFromOpac( undef, $requesters{CPL} ),
581
    undef,
582
    'CanReserveBeCanceledFromOpac should return undef if called without borrowernumber'
583
);
584
585
my $cancancel = CanReserveBeCanceledFromOpac($canres->{reserve_id}, $requesters{$branch_1});
586
is($cancancel, 1, 'Can user cancel its own reserve');
587
575
588
$cancancel = CanReserveBeCanceledFromOpac($canres->{reserve_id}, $requesters{$branch_2});
576
$cancancel = Koha::Policy::Patrons::Holds->can_cancel_from_opac( $requesters{$branch_2}, $hold );
589
is($cancancel, 0, 'Other user cant cancel reserve');
577
ok( !$cancancel, 'Other user cant cancel reserve' );
590
578
591
ModReserveAffect($item->itemnumber, $requesters{$branch_1}, 1);
579
ModReserveAffect( $item->itemnumber, $requesters{$branch_1}->borrowernumber, 1 );
592
$cancancel = CanReserveBeCanceledFromOpac($canres->{reserve_id}, $requesters{$branch_1});
580
$cancancel = Koha::Policy::Patrons::Holds->can_cancel_from_opac( $requesters{$branch_1}, $hold->get_from_storage );
593
is($cancancel, 0, 'Reserve in transfer status cant be canceled');
581
ok( !$cancancel, 'Reserve in transfer status cant be canceled' );
594
595
$dbh->do('DELETE FROM reserves', undef, ($bibnum));
596
is( CanReserveBeCanceledFromOpac($canres->{resserve_id}, $requesters{$branch_1}), undef,
597
    'Cannot cancel a deleted hold' );
598
582
599
AddReserve(
583
AddReserve(
600
    {
584
    {
601
        branchcode     => $branch_1,
585
        branchcode     => $branch_1,
602
        borrowernumber => $requesters{$branch_1},
586
        borrowernumber => $requesters{$branch_1}->borrowernumber,
603
        biblionumber   => $bibnum,
587
        biblionumber   => $bibnum,
604
        priority       => 1,
588
        priority       => 1,
605
    }
589
    }
606
);
590
);
607
(undef, $canres, undef) = CheckReserves( $item );
591
(undef, $canres, undef) = CheckReserves( $item );
608
592
609
ModReserveAffect($item->itemnumber, $requesters{$branch_1}, 0);
593
ModReserveAffect( $item->itemnumber, $requesters{$branch_1}->borrowernumber, 0 );
610
$cancancel = CanReserveBeCanceledFromOpac($canres->{reserve_id}, $requesters{$branch_1});
594
$cancancel = Koha::Policy::Patrons::Holds->can_cancel_from_opac( $requesters{$branch_1}, $hold->get_from_storage );
611
is($cancancel, 0, 'Reserve in waiting status cant be canceled');
595
ok( !$cancancel, 'Reserve in waiting status cant be canceled' );
612
596
613
# End of tests for bug 12876
597
# End of tests for bug 12876
614
598
615
- 

Return to bug 30856