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

Signed-off-by: David Nind <david@davidnind.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
(cherry picked from commit 0f533c1ceb)
Signed-off-by: Paul Derscheid <paul.derscheid@lmscloud.de>
(cherry picked from commit e991fc4057)
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
This commit is contained in:
Tomas Cohen Arazi 2025-07-29 11:15:31 -03:00 committed by Fridolin Somers
parent 9b0b996988
commit 2d2eb49661
No known key found for this signature in database
GPG Key ID: 9A8E73E2A8B96537
2 changed files with 87 additions and 4 deletions

View File

@ -1080,10 +1080,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

View File

@ -19,7 +19,7 @@
use Modern::Perl;
use Test::More tests => 14;
use Test::More tests => 15;
use Test::Exception;
use Test::MockModule;
@ -1134,3 +1134,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;
};