Bugzilla – Attachment 135401 Details for
Bug 22456
Allow patrons to cancel their waiting holds
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 22456: Add Koha::Holds->filter_by_has_cancellation_requests
Bug-22456-Add-KohaHolds-filterbyhascancellationreq.patch (text/plain), 3.69 KB, created by
Tomás Cohen Arazi (tcohen)
on 2022-05-26 19:22:58 UTC
(
hide
)
Description:
Bug 22456: Add Koha::Holds->filter_by_has_cancellation_requests
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2022-05-26 19:22:58 UTC
Size:
3.69 KB
patch
obsolete
>From 0de3eb93b57546e05ae698c084a3b3ca64b468e3 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Mon, 23 May 2022 11:44:19 -0300 >Subject: [PATCH] Bug 22456: Add > Koha::Holds->filter_by_has_cancellation_requests > >This patch adds that method. Which is covered by new tests. > >To test: >1. Apply this patch >2. Run: > $ kshell > k$ prove t/db_dependent/Koha/Holds.t >=> SUCCESS: Tests pass! >3. Sign off :-D > >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> >--- > Koha/Holds.pm | 21 ++++++++++-- > t/db_dependent/Koha/Holds.t | 67 +++++++++++++++++++++++++++++++++++-- > 2 files changed, 84 insertions(+), 4 deletions(-) > >diff --git a/Koha/Holds.pm b/Koha/Holds.pm >index 2a117f5f66..408593bd8b 100644 >--- a/Koha/Holds.pm >+++ b/Koha/Holds.pm >@@ -32,7 +32,7 @@ Koha::Holds - Koha Hold object set class > > =head1 API > >-=head2 Class Methods >+=head2 Class methods > > =cut > >@@ -145,7 +145,24 @@ sub get_items_that_can_fill { > )->filter_by_for_hold(); > } > >-=head3 type >+=head3 filter_by_has_cancellation_requests >+ >+ my $with_cancellation_reqs = $holds->filter_by_has_cancellation_requests; >+ >+Returns a filtered resultset only containing holds that have cancellation requests. >+ >+=cut >+ >+sub filter_by_has_cancellation_requests { >+ my ($self) = @_; >+ >+ return $self->search( { 'hold_cancellation_request_id' => { '!=' => undef } }, >+ { join => 'cancellation_requests' } ); >+} >+ >+=head2 Internal methods >+ >+=head3 _type > > =cut > >diff --git a/t/db_dependent/Koha/Holds.t b/t/db_dependent/Koha/Holds.t >index d9f8b666a7..aef7cdc13e 100755 >--- a/t/db_dependent/Koha/Holds.t >+++ b/t/db_dependent/Koha/Holds.t >@@ -19,7 +19,7 @@ > > use Modern::Perl; > >-use Test::More tests => 7; >+use Test::More tests => 8; > use Test::Warn; > > use C4::Circulation qw( AddIssue ); >@@ -638,4 +638,67 @@ subtest 'set_waiting+patron_expiration_date' => sub { > > $schema->storage->txn_rollback; > >-1; >+subtest 'filter_by_has_cancellation_requests() tests' => sub { >+ >+ plan tests => 4; >+ >+ $schema->storage->txn_begin; >+ >+ my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); >+ >+ my $item_1 = $builder->build_sample_item; >+ my $item_2 = $builder->build_sample_item; >+ my $item_3 = $builder->build_sample_item; >+ >+ my $hold_1 = $builder->build_object( >+ { >+ class => 'Koha::Holds', >+ value => { >+ found => 'W', >+ itemnumber => $item_1->id, >+ biblionumber => $item_1->biblionumber, >+ borrowernumber => $patron->id >+ } >+ } >+ ); >+ my $hold_2 = $builder->build_object( >+ { >+ class => 'Koha::Holds', >+ value => { >+ found => 'W', >+ itemnumber => $item_2->id, >+ biblionumber => $item_2->biblionumber, >+ borrowernumber => $patron->id >+ } >+ } >+ ); >+ my $hold_3 = $builder->build_object( >+ { >+ class => 'Koha::Holds', >+ value => { >+ found => 'W', >+ itemnumber => $item_3->id, >+ biblionumber => $item_3->biblionumber, >+ borrowernumber => $patron->id >+ } >+ } >+ ); >+ >+ my $rs = Koha::Holds->search( >+ { reserve_id => [ $hold_1->id, $hold_2->id, $hold_3->id ] } ); >+ >+ is( $rs->count, 3 ); >+ >+ my $filtered_rs = $rs->filter_by_has_cancellation_requests; >+ >+ is( $filtered_rs->count, 0 ); >+ >+ $hold_2->add_cancellation_request; >+ >+ $filtered_rs = $rs->filter_by_has_cancellation_requests; >+ >+ is( $filtered_rs->count, 1 ); >+ is( $filtered_rs->next->id, $hold_2->id ); >+ >+ $schema->storage->txn_rollback; >+}; >-- >2.34.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 22456
:
135165
|
135166
|
135167
|
135168
|
135169
|
135170
|
135171
|
135319
|
135320
|
135321
|
135322
|
135323
|
135324
|
135325
|
135326
|
135349
|
135350
|
135351
|
135352
|
135396
|
135397
|
135398
|
135399
|
135400
|
135401
|
135402
|
135403
|
135404
|
135405
|
135406
|
135407
|
135408
|
135409
|
135410
|
135411
|
135430
|
135830
|
135831
|
135832
|
135838
|
135839
|
135840
|
135841
|
135842
|
135843
|
135844
|
135845
|
135846
|
137580
|
137581
|
137582
|
137583
|
137584
|
137585
|
137586
|
137587
|
137588
|
137589
|
137591
|
138209
|
138210
|
138211
|
138212
|
138213
|
138214
|
138215
|
138216
|
138217
|
138218