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 940-946 sub CancelHold { Link Here
940
    return { code => 'RecordNotFound' } unless $hold;
941
    return { code => 'RecordNotFound' } unless $hold;
941
942
942
    # Check if reserve belongs to the borrower and if it is in a state which allows cancellation
943
    # Check if reserve belongs to the borrower and if it is in a state which allows cancellation
943
    return { code => 'BorrowerCannotCancelHold' } unless CanReserveBeCanceledFromOpac( $reserve_id, $borrowernumber );
944
    return { code => 'BorrowerCannotCancelHold' } unless Koha::Policy::Patrons::Holds->can_cancel_from_opac( $patron, $hold );
944
945
945
    $hold->cancel;
946
    $hold->cancel;
946
947
(-)a/C4/Reserves.pm (-21 lines)
Lines 120-126 BEGIN { Link Here
120
      CheckReserves
120
      CheckReserves
121
      CanBookBeReserved
121
      CanBookBeReserved
122
      CanItemBeReserved
122
      CanItemBeReserved
123
      CanReserveBeCanceledFromOpac
124
      CancelExpiredReserves
123
      CancelExpiredReserves
125
124
126
      AutoUnsuspendReserves
125
      AutoUnsuspendReserves
Lines 692-717 sub CanItemBeReserved { Link Here
692
    return _cache { status => 'OK' };
691
    return _cache { status => 'OK' };
693
}
692
}
694
693
695
=head2 CanReserveBeCanceledFromOpac
696
697
    $number = CanReserveBeCanceledFromOpac($reserve_id, $borrowernumber);
698
699
    returns 1 if reserve can be cancelled by user from OPAC.
700
    First check if reserve belongs to user, next checks if reserve is not in
701
    transfer or waiting status
702
703
=cut
704
705
sub CanReserveBeCanceledFromOpac {
706
    my ($reserve_id, $borrowernumber) = @_;
707
708
    return unless $reserve_id and $borrowernumber;
709
    my $reserve = Koha::Holds->find($reserve_id) or return;
710
711
    return 0 unless $reserve->borrowernumber == $borrowernumber;
712
    return $reserve->is_cancelable_from_opac;
713
}
714
715
=head2 GetOtherReserves
694
=head2 GetOtherReserves
716
695
717
  ($messages,$nextreservinfo)=$GetOtherReserves(itemnumber);
696
  ($messages,$nextreservinfo)=$GetOtherReserves(itemnumber);
(-)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 (-60 / +43 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 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 137-160 $requesters{$branch_1} = Koha::Patron->new({ Link Here
137
    branchcode   => $branch_1,
138
    branchcode   => $branch_1,
138
    categorycode => $category_2,
139
    categorycode => $category_2,
139
    surname      => "borrower from $branch_1",
140
    surname      => "borrower from $branch_1",
140
})->store->borrowernumber;
141
})->store;
141
for my $i ( 2 .. 5 ) {
142
for my $i ( 2 .. 5 ) {
142
    $requesters{"CPL$i"} = Koha::Patron->new({
143
    $requesters{"CPL$i"} = Koha::Patron->new({
143
        branchcode   => $branch_1,
144
        branchcode   => $branch_1,
144
        categorycode => $category_2,
145
        categorycode => $category_2,
145
        surname      => "borrower $i from $branch_1",
146
        surname      => "borrower $i from $branch_1",
146
    })->store->borrowernumber;
147
    })->store;
147
}
148
}
148
$requesters{$branch_2} = Koha::Patron->new({
149
$requesters{$branch_2} = Koha::Patron->new({
149
    branchcode   => $branch_2,
150
    branchcode   => $branch_2,
150
    categorycode => $category_2,
151
    categorycode => $category_2,
151
    surname      => "borrower from $branch_2",
152
    surname      => "borrower from $branch_2",
152
})->store->borrowernumber;
153
})->store;
153
$requesters{$branch_3} = Koha::Patron->new({
154
$requesters{$branch_3} = Koha::Patron->new({
154
    branchcode   => $branch_3,
155
    branchcode   => $branch_3,
155
    categorycode => $category_2,
156
    categorycode => $category_2,
156
    surname      => "borrower from $branch_3",
157
    surname      => "borrower from $branch_3",
157
})->store->borrowernumber;
158
})->store;
158
159
159
# Configure rules so that $branch_1 allows only $branch_1 patrons
160
# Configure rules so that $branch_1 allows only $branch_1 patrons
160
# to request its items, while $branch_2 will allow its items
161
# to request its items, while $branch_2 will allow its items
Lines 223-229 $dbh->do("DELETE FROM reserves WHERE biblionumber=?",undef,($bibnum2)); Link Here
223
AddReserve(
224
AddReserve(
224
    {
225
    {
225
        branchcode     => $branch_3,
226
        branchcode     => $branch_3,
226
        borrowernumber => $requesters{$branch_3},
227
        borrowernumber => $requesters{$branch_3}->borrowernumber,
227
        biblionumber   => $bibnum2,
228
        biblionumber   => $bibnum2,
228
        priority       => 1,
229
        priority       => 1,
229
    }
230
    }
Lines 231-237 AddReserve( Link Here
231
AddReserve(
232
AddReserve(
232
    {
233
    {
233
        branchcode     => $branch_2,
234
        branchcode     => $branch_2,
234
        borrowernumber => $requesters{$branch_2},
235
        borrowernumber => $requesters{$branch_2}->borrowernumber,
235
        biblionumber   => $bibnum2,
236
        biblionumber   => $bibnum2,
236
        priority       => 2,
237
        priority       => 2,
237
    }
238
    }
Lines 239-250 AddReserve( Link Here
239
AddReserve(
240
AddReserve(
240
    {
241
    {
241
        branchcode     => $branch_1,
242
        branchcode     => $branch_1,
242
        borrowernumber => $requesters{$branch_1},
243
        borrowernumber => $requesters{$branch_1}->borrowernumber,
243
        biblionumber   => $bibnum2,
244
        biblionumber   => $bibnum2,
244
        priority       => 3,
245
        priority       => 3,
245
    }
246
    }
246
);
247
);
247
ModReserveAffect($itemnum_cpl, $requesters{$branch_3}, 0);
248
ModReserveAffect($itemnum_cpl, $requesters{$branch_3}->borrowernumber, 0);
248
249
249
# Now it should have different priorities.
250
# Now it should have different priorities.
250
my $biblio = Koha::Biblios->find( $bibnum2 );
251
my $biblio = Koha::Biblios->find( $bibnum2 );
Lines 253-268 is($holds->next->priority, 0, 'Item is correctly waiting'); Link Here
253
is($holds->next->priority, 1, 'Item is correctly priority 1');
254
is($holds->next->priority, 1, 'Item is correctly priority 1');
254
is($holds->next->priority, 2, 'Item is correctly priority 2');
255
is($holds->next->priority, 2, 'Item is correctly priority 2');
255
256
256
my @reserves = Koha::Holds->search({ borrowernumber => $requesters{$branch_3} })->waiting->as_list;
257
my @reserves = Koha::Holds->search({ borrowernumber => $requesters{$branch_3}->borrowernumber })->waiting->as_list;
257
is( @reserves, 1, 'GetWaiting got only the waiting reserve' );
258
is( @reserves, 1, 'GetWaiting got only the waiting reserve' );
258
is( $reserves[0]->borrowernumber(), $requesters{$branch_3}, 'GetWaiting got the reserve for the correct borrower' );
259
is( $reserves[0]->borrowernumber(), $requesters{$branch_3}->borrowernumber, 'GetWaiting got the reserve for the correct borrower' );
259
260
260
261
261
$dbh->do("DELETE FROM reserves WHERE biblionumber=?",undef,($bibnum2));
262
$dbh->do("DELETE FROM reserves WHERE biblionumber=?",undef,($bibnum2));
262
AddReserve(
263
AddReserve(
263
    {
264
    {
264
        branchcode     => $branch_3,
265
        branchcode     => $branch_3,
265
        borrowernumber => $requesters{$branch_3},
266
        borrowernumber => $requesters{$branch_3}->borrowernumber,
266
        biblionumber   => $bibnum2,
267
        biblionumber   => $bibnum2,
267
        priority       => 1,
268
        priority       => 1,
268
    }
269
    }
Lines 270-276 AddReserve( Link Here
270
AddReserve(
271
AddReserve(
271
    {
272
    {
272
        branchcode     => $branch_2,
273
        branchcode     => $branch_2,
273
        borrowernumber => $requesters{$branch_2},
274
        borrowernumber => $requesters{$branch_2}->borrowernumber,
274
        biblionumber   => $bibnum2,
275
        biblionumber   => $bibnum2,
275
        priority       => 2,
276
        priority       => 2,
276
    }
277
    }
Lines 279-285 AddReserve( Link Here
279
AddReserve(
280
AddReserve(
280
    {
281
    {
281
        branchcode     => $branch_1,
282
        branchcode     => $branch_1,
282
        borrowernumber => $requesters{$branch_1},
283
        borrowernumber => $requesters{$branch_1}->borrowernumber,
283
        biblionumber   => $bibnum2,
284
        biblionumber   => $bibnum2,
284
        priority       => 3,
285
        priority       => 3,
285
    }
286
    }
Lines 294-300 my $messages; Link Here
294
# requests cannot be filled by that item per policy.
295
# requests cannot be filled by that item per policy.
295
(undef, $messages, undef, undef) = AddReturn('bug10272_CPL', $branch_2);
296
(undef, $messages, undef, undef) = AddReturn('bug10272_CPL', $branch_2);
296
is( $messages->{ResFound}->{borrowernumber},
297
is( $messages->{ResFound}->{borrowernumber},
297
    $requesters{$branch_1},
298
    $requesters{$branch_1}->borrowernumber,
298
    'restrictive library\'s items only fill requests by own patrons (bug 10272)');
299
    'restrictive library\'s items only fill requests by own patrons (bug 10272)');
299
300
300
# Return the FPL item at FPL.  The hold that should be triggered is
301
# Return the FPL item at FPL.  The hold that should be triggered is
Lines 306-312 t::lib::Mocks::mock_preference( 'LocalHoldsPriority', '' ); Link Here
306
307
307
(undef, $messages, undef, undef) = AddReturn('bug10272_FPL', $branch_2);
308
(undef, $messages, undef, undef) = AddReturn('bug10272_FPL', $branch_2);
308
is( $messages->{ResFound}->{borrowernumber},
309
is( $messages->{ResFound}->{borrowernumber},
309
    $requesters{$branch_3},
310
    $requesters{$branch_3}->borrowernumber,
310
    'for generous library, its items fill first hold request in line (bug 10272)');
311
    'for generous library, its items fill first hold request in line (bug 10272)');
311
312
312
$biblio = Koha::Biblios->find( $biblionumber );
313
$biblio = Koha::Biblios->find( $biblionumber );
Lines 321-327 $dbh->do("DELETE FROM reserves WHERE biblionumber=?",undef,($bibnum)); Link Here
321
AddReserve(
322
AddReserve(
322
    {
323
    {
323
        branchcode     => $branch_1,
324
        branchcode     => $branch_1,
324
        borrowernumber => $requesters{$branch_1},
325
        borrowernumber => $requesters{$branch_1}->borrowernumber,
325
        biblionumber   => $bibnum,
326
        biblionumber   => $bibnum,
326
        priority       => 1,
327
        priority       => 1,
327
    }
328
    }
Lines 339-345 $resdate->add_duration(DateTime::Duration->new(days => 4)); Link Here
339
my $reserve_id = AddReserve(
340
my $reserve_id = AddReserve(
340
    {
341
    {
341
        branchcode       => $branch_1,
342
        branchcode       => $branch_1,
342
        borrowernumber   => $requesters{$branch_1},
343
        borrowernumber   => $requesters{$branch_1}->borrowernumber,
343
        biblionumber     => $bibnum,
344
        biblionumber     => $bibnum,
344
        priority         => 1,
345
        priority         => 1,
345
        reservation_date => $resdate,
346
        reservation_date => $resdate,
Lines 373-379 my $now_holder = $builder->build_object({ class => 'Koha::Patrons', value => { Link Here
373
my $now_reserve_id = AddReserve(
374
my $now_reserve_id = AddReserve(
374
    {
375
    {
375
        branchcode       => $branch_1,
376
        branchcode       => $branch_1,
376
        borrowernumber   => $requesters{$branch_1},
377
        borrowernumber   => $requesters{$branch_1}->borrowernumber,
377
        biblionumber     => $bibnum,
378
        biblionumber     => $bibnum,
378
        priority         => 2,
379
        priority         => 2,
379
        reservation_date => dt_from_string(),
380
        reservation_date => dt_from_string(),
Lines 392-403 ModReserve({ reserve_id => $now_reserve_id, rank => 'del', cancellation_reason = Link Here
392
393
393
# test marking a hold as captured
394
# test marking a hold as captured
394
my $hold_notice_count = count_hold_print_messages();
395
my $hold_notice_count = count_hold_print_messages();
395
ModReserveAffect($item->itemnumber, $requesters{$branch_1}, 0);
396
ModReserveAffect($item->itemnumber, $requesters{$branch_1}->borrowernumber, 0);
396
my $new_count = count_hold_print_messages();
397
my $new_count = count_hold_print_messages();
397
is($new_count, $hold_notice_count + 1, 'patron notified when item set to waiting');
398
is($new_count, $hold_notice_count + 1, 'patron notified when item set to waiting');
398
399
399
# test that duplicate notices aren't generated
400
# test that duplicate notices aren't generated
400
ModReserveAffect($item->itemnumber, $requesters{$branch_1}, 0);
401
ModReserveAffect($item->itemnumber, $requesters{$branch_1}->borrowernumber, 0);
401
$new_count = count_hold_print_messages();
402
$new_count = count_hold_print_messages();
402
is($new_count, $hold_notice_count + 1, 'patron not notified a second time (bug 11445)');
403
is($new_count, $hold_notice_count + 1, 'patron not notified a second time (bug 11445)');
403
404
Lines 423-429 $resdate->add_duration(DateTime::Duration->new(days => 2)); Link Here
423
AddReserve(
424
AddReserve(
424
    {
425
    {
425
        branchcode       => $branch_1,
426
        branchcode       => $branch_1,
426
        borrowernumber   => $requesters{$branch_1},
427
        borrowernumber   => $requesters{$branch_1}->borrowernumber,
427
        biblionumber     => $bibnum,
428
        biblionumber     => $bibnum,
428
        priority         => 1,
429
        priority         => 1,
429
        reservation_date => $resdate,
430
        reservation_date => $resdate,
Lines 439-445 $dbh->do("DELETE FROM reserves WHERE biblionumber=?",undef,($bibnum)); Link Here
439
AddReserve(
440
AddReserve(
440
    {
441
    {
441
        branchcode       => $branch_1,
442
        branchcode       => $branch_1,
442
        borrowernumber   => $requesters{$branch_1},
443
        borrowernumber   => $requesters{$branch_1}->borrowernumber,
443
        biblionumber     => $bibnum,
444
        biblionumber     => $bibnum,
444
        priority         => 1,
445
        priority         => 1,
445
        reservation_date => $resdate,
446
        reservation_date => $resdate,
Lines 449-455 AddReserve( Link Here
449
$future_holds = $holds->search({ reservedate => { '>' => $dtf->format_date( dt_from_string ) } } );
450
$future_holds = $holds->search({ reservedate => { '>' => $dtf->format_date( dt_from_string ) } } );
450
is( $future_holds->count, 0, 'current_holds does not return a future item level hold' );
451
is( $future_holds->count, 0, 'current_holds does not return a future item level hold' );
451
# 9788c: current_holds returns future wait (confirmed future hold)
452
# 9788c: current_holds returns future wait (confirmed future hold)
452
ModReserveAffect( $item->itemnumber,  $requesters{$branch_1} , 0); #confirm hold
453
ModReserveAffect( $item->itemnumber,  $requesters{$branch_1}->borrowernumber, 0); #confirm hold
453
$future_holds = $holds->search({ reservedate => { '>' => $dtf->format_date( dt_from_string ) } } );
454
$future_holds = $holds->search({ reservedate => { '>' => $dtf->format_date( dt_from_string ) } } );
454
is( $future_holds->count, 1, 'current_holds returns a future wait (confirmed future hold)' );
455
is( $future_holds->count, 1, 'current_holds returns a future wait (confirmed future hold)' );
455
# End of tests for bug 9788
456
# End of tests for bug 9788
Lines 461-467 is($p, 4, 'CalculatePriority should now return priority 4'); Link Here
461
AddReserve(
462
AddReserve(
462
    {
463
    {
463
        branchcode     => $branch_1,
464
        branchcode     => $branch_1,
464
        borrowernumber => $requesters{'CPL2'},
465
        borrowernumber => $requesters{'CPL2'}->borrowernumber,
465
        biblionumber   => $bibnum2,
466
        biblionumber   => $bibnum2,
466
        priority       => $p,
467
        priority       => $p,
467
    }
468
    }
Lines 476-482 is($p, 1, 'CalculatePriority should now return priority 1'); Link Here
476
AddReserve(
477
AddReserve(
477
    {
478
    {
478
        branchcode     => $branch_1,
479
        branchcode     => $branch_1,
479
        borrowernumber => $requesters{$branch_1},
480
        borrowernumber => $requesters{$branch_1}->borrowernumber,
480
        biblionumber   => $bibnum,
481
        biblionumber   => $bibnum,
481
        priority       => $p,
482
        priority       => $p,
482
        itemnumber     => $item->itemnumber,
483
        itemnumber     => $item->itemnumber,
Lines 484-497 AddReserve( Link Here
484
);
485
);
485
$p = C4::Reserves::CalculatePriority($bibnum);
486
$p = C4::Reserves::CalculatePriority($bibnum);
486
is($p, 2, 'CalculatePriority should now return priority 2');
487
is($p, 2, 'CalculatePriority should now return priority 2');
487
ModReserveAffect( $item->itemnumber,  $requesters{$branch_1} , 0);
488
ModReserveAffect( $item->itemnumber,  $requesters{$branch_1}->borrowernumber, 0);
488
$p = C4::Reserves::CalculatePriority($bibnum);
489
$p = C4::Reserves::CalculatePriority($bibnum);
489
is($p, 1, 'CalculatePriority should now return priority 1');
490
is($p, 1, 'CalculatePriority should now return priority 1');
490
#add another biblio hold, no resdate
491
#add another biblio hold, no resdate
491
AddReserve(
492
AddReserve(
492
    {
493
    {
493
        branchcode     => $branch_1,
494
        branchcode     => $branch_1,
494
        borrowernumber => $requesters{'CPL2'},
495
        borrowernumber => $requesters{'CPL2'}->borrowernumber,
495
        biblionumber   => $bibnum,
496
        biblionumber   => $bibnum,
496
        priority       => $p,
497
        priority       => $p,
497
    }
498
    }
Lines 505-511 $resdate->add_duration(DateTime::Duration->new(days => 1)); Link Here
505
AddReserve(
506
AddReserve(
506
    {
507
    {
507
        branchcode     => $branch_1,
508
        branchcode     => $branch_1,
508
        borrowernumber => $requesters{'CPL2'},
509
        borrowernumber => $requesters{'CPL2'}->borrowernumber,
509
        biblionumber   => $bibnum,
510
        biblionumber   => $bibnum,
510
        priority       => $p,
511
        priority       => $p,
511
        reservation_date => $resdate,
512
        reservation_date => $resdate,
Lines 562-615 $dbh->do('DELETE FROM reserves', undef, ($bibnum)); Link Here
562
AddReserve(
563
AddReserve(
563
    {
564
    {
564
        branchcode     => $branch_1,
565
        branchcode     => $branch_1,
565
        borrowernumber => $requesters{$branch_1},
566
        borrowernumber => $requesters{$branch_1}->borrowernumber,
566
        biblionumber   => $bibnum,
567
        biblionumber   => $bibnum,
567
        priority       => 1,
568
        priority       => 1,
568
    }
569
    }
569
);
570
);
570
my (undef, $canres, undef) = CheckReserves( $item );
571
my (undef, $canres, undef) = CheckReserves( $item );
571
572
572
is( CanReserveBeCanceledFromOpac(), undef,
573
my $hold      = Koha::Holds->find( $canres->{reserve_id} );
573
    'CanReserveBeCanceledFromOpac should return undef if called without any parameter'
574
my $cancancel = Koha::Policy::Patrons::Holds->can_cancel_from_opac( $requesters{$branch_1}, $hold );
574
);
575
ok( $cancancel, 'Can user cancel its own reserve' );
575
is(
576
    CanReserveBeCanceledFromOpac( $canres->{resserve_id} ),
577
    undef,
578
    'CanReserveBeCanceledFromOpac should return undef if called without the reserve_id'
579
);
580
is(
581
    CanReserveBeCanceledFromOpac( undef, $requesters{CPL} ),
582
    undef,
583
    'CanReserveBeCanceledFromOpac should return undef if called without borrowernumber'
584
);
585
586
my $cancancel = CanReserveBeCanceledFromOpac($canres->{reserve_id}, $requesters{$branch_1});
587
is($cancancel, 1, 'Can user cancel its own reserve');
588
576
589
$cancancel = CanReserveBeCanceledFromOpac($canres->{reserve_id}, $requesters{$branch_2});
577
$cancancel = Koha::Policy::Patrons::Holds->can_cancel_from_opac( $requesters{$branch_2}, $hold );
590
is($cancancel, 0, 'Other user cant cancel reserve');
578
ok( !$cancancel, 'Other user cant cancel reserve' );
591
579
592
ModReserveAffect($item->itemnumber, $requesters{$branch_1}, 1);
580
ModReserveAffect( $item->itemnumber, $requesters{$branch_1}->borrowernumber, 1 );
593
$cancancel = CanReserveBeCanceledFromOpac($canres->{reserve_id}, $requesters{$branch_1});
581
$cancancel = Koha::Policy::Patrons::Holds->can_cancel_from_opac( $requesters{$branch_1}, $hold->get_from_storage );
594
is($cancancel, 0, 'Reserve in transfer status cant be canceled');
582
ok( !$cancancel, 'Reserve in transfer status cant be canceled' );
595
596
$dbh->do('DELETE FROM reserves', undef, ($bibnum));
597
is( CanReserveBeCanceledFromOpac($canres->{resserve_id}, $requesters{$branch_1}), undef,
598
    'Cannot cancel a deleted hold' );
599
583
600
AddReserve(
584
AddReserve(
601
    {
585
    {
602
        branchcode     => $branch_1,
586
        branchcode     => $branch_1,
603
        borrowernumber => $requesters{$branch_1},
587
        borrowernumber => $requesters{$branch_1}->borrowernumber,
604
        biblionumber   => $bibnum,
588
        biblionumber   => $bibnum,
605
        priority       => 1,
589
        priority       => 1,
606
    }
590
    }
607
);
591
);
608
(undef, $canres, undef) = CheckReserves( $item );
592
(undef, $canres, undef) = CheckReserves( $item );
609
593
610
ModReserveAffect($item->itemnumber, $requesters{$branch_1}, 0);
594
ModReserveAffect( $item->itemnumber, $requesters{$branch_1}->borrowernumber, 0 );
611
$cancancel = CanReserveBeCanceledFromOpac($canres->{reserve_id}, $requesters{$branch_1});
595
$cancancel = Koha::Policy::Patrons::Holds->can_cancel_from_opac( $requesters{$branch_1}, $hold->get_from_storage );
612
is($cancancel, 0, 'Reserve in waiting status cant be canceled');
596
ok( !$cancancel, 'Reserve in waiting status cant be canceled' );
613
597
614
# End of tests for bug 12876
598
# End of tests for bug 12876
615
599
616
- 

Return to bug 30856