Bugzilla – Attachment 184810 Details for
Bug 40542
Add `cancellation_reason` to holds strings embed
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 40542: Add cancellation_reason to Koha::Hold->strings_map
Bug-40542-Add-cancellationreason-to-KohaHold-strin.patch (text/plain), 4.13 KB, created by
Tomás Cohen Arazi (tcohen)
on 2025-07-29 14:22:16 UTC
(
hide
)
Description:
Bug 40542: Add cancellation_reason to Koha::Hold->strings_map
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2025-07-29 14:22:16 UTC
Size:
4.13 KB
patch
obsolete
>From 7df2ae21c90b608fb8acdea3459040e9390ee7c5 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Tue, 29 Jul 2025 11:15:31 -0300 >Subject: [PATCH] Bug 40542: Add cancellation_reason to Koha::Hold->strings_map > >This patch adds the mentioned AV to the returned strings structure. > >It also adds tests for the method. > >To test: >1. Apply this patch >2. Run: > $ ktd --shell > k$ prove t/db_dependent/Koha/Hold.t >=> SUCCESS: Tests pass! >3. Sign off :-D >--- > Koha/Hold.pm | 30 +++++++++++++++++-- > t/db_dependent/Koha/Hold.t | 61 +++++++++++++++++++++++++++++++++++++- > 2 files changed, 87 insertions(+), 4 deletions(-) > >diff --git a/Koha/Hold.pm b/Koha/Hold.pm >index 59b498a7d22..bdebac76511 100644 >--- a/Koha/Hold.pm >+++ b/Koha/Hold.pm >@@ -1067,10 +1067,34 @@ Returns a map of column name to string representations including the string. > =cut > > sub strings_map { >- my ($self) = @_; >- return { >- pickup_library_id => { str => $self->branch->branchname, type => 'library' }, >+ my ( $self, $params ) = @_; >+ >+ my $strings = { >+ pickup_library_id => { str => $self->pickup_library->branchname, type => 'library' }, > }; >+ >+ if ( defined $self->cancellation_reason ) { >+ my $av = Koha::AuthorisedValues->search( >+ { >+ category => 'HOLD_CANCELLATION', >+ authorised_value => $self->cancellation_reason, >+ } >+ ); >+ my $cancellation_reason_str = >+ $av->count >+ ? $params->{public} >+ ? $av->next->opac_description >+ : $av->next->lib >+ : $self->cancellation_reason; >+ >+ $strings->{cancellation_reason} = { >+ category => 'HOLD_CANCELLATION', >+ str => $cancellation_reason_str, >+ type => 'av', >+ }; >+ } >+ >+ return $strings; > } > > =head2 Internal methods >diff --git a/t/db_dependent/Koha/Hold.t b/t/db_dependent/Koha/Hold.t >index 55fe078227b..c34441971c3 100755 >--- a/t/db_dependent/Koha/Hold.t >+++ b/t/db_dependent/Koha/Hold.t >@@ -20,7 +20,7 @@ > use Modern::Perl; > > use Test::NoWarnings; >-use Test::More tests => 15; >+use Test::More tests => 16; > > use Test::Exception; > use Test::MockModule; >@@ -1200,3 +1200,62 @@ subtest 'change_type() tests' => sub { > > $schema->storage->txn_rollback; > }; >+ >+subtest 'strings_map() tests' => sub { >+ >+ plan tests => 3; >+ >+ $schema->txn_begin; >+ >+ my $av = Koha::AuthorisedValue->new( >+ { >+ category => 'HOLD_CANCELLATION', >+ authorised_value => 'JUST_BECAUSE', >+ lib => 'Just because', >+ lib_opac => 'Serious reasons', >+ } >+ )->store; >+ >+ my $library = $builder->build_object( { class => 'Koha::Libraries' } ); >+ >+ my $hold = $builder->build_object( >+ { >+ class => 'Koha::Holds', >+ value => { cancellation_reason => $av->authorised_value, branchcode => $library->id } >+ } >+ ); >+ >+ my $strings_map = $hold->strings_map( { public => 0 } ); >+ is_deeply( >+ $strings_map, >+ { >+ pickup_library_id => { str => $library->branchname, type => 'library' }, >+ cancellation_reason => { str => $av->lib, type => 'av', category => 'HOLD_CANCELLATION' }, >+ }, >+ 'Strings map is correct' >+ ); >+ >+ $strings_map = $hold->strings_map( { public => 1 } ); >+ is_deeply( >+ $strings_map, >+ { >+ pickup_library_id => { str => $library->branchname, type => 'library' }, >+ cancellation_reason => { str => $av->lib_opac, type => 'av', category => 'HOLD_CANCELLATION' }, >+ }, >+ 'Strings map is correct (OPAC)' >+ ); >+ >+ $av->delete(); >+ >+ $strings_map = $hold->strings_map( { public => 1 } ); >+ is_deeply( >+ $strings_map, >+ { >+ pickup_library_id => { str => $library->branchname, type => 'library' }, >+ cancellation_reason => { str => $hold->cancellation_reason, type => 'av', category => 'HOLD_CANCELLATION' }, >+ }, >+ 'Strings map shows the cancellation_value when AV not present' >+ ); >+ >+ $schema->txn_rollback; >+}; >-- >2.50.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 40542
:
184810
|
184811
|
184836
|
184837
|
184881
|
184882
|
185074