Bug 21284: ILS-DI: Allow GetPatronInfo to tell if a loaned item is on hold by someone else.

This patch adds two new entries in the loans section of GetPatronInfo response:

 - itemonhold: number of holds on this specific item.
 - recordonhold: number of holds on the record.

It allows an ILS-DI client to know if a loaned item is already on hold by someone else, and how many holds there are.

Test plan:
1. Apply the patch.
2. Enable the ILS-DI system preference.
3. Check out an item for a patron and make sure there no other holds at either an item or record level.
4. Check that the new itemonhold and recordonhold entries displayed are equal to zero (example: http://127.0.0.1:8080/cgi-bin/koha/ilsdi.pl?service=GetPatronInfo&patron_id=19&show_contact=0&show_loans=1).
5. Add either a record or item level hold for the record used in step 2.
6. Check that itemonhold and recordonhold values are incremented accordingly.
   Note: a hold at an item level counts as a hold at a record level, but not vice-versa.
7. Run the tests and make sure they pass: prove t/db_dependent/ILSDI_Services.t
8. Sign-off!

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

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
(cherry picked from commit d1d5811279)
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
This commit is contained in:
Matthias Meusburger 2018-04-27 16:22:28 +02:00 committed by Fridolin Somers
parent 619b31706a
commit 1b4cd9eeaa
3 changed files with 108 additions and 1 deletions

View file

@ -529,6 +529,13 @@ sub GetPatronInfo {
# FIXME We should only retrieve what is needed in the template # FIXME We should only retrieve what is needed in the template
my $issue = $c->unblessed_all_relateds; my $issue = $c->unblessed_all_relateds;
delete $issue->{'more_subfields_xml'}; delete $issue->{'more_subfields_xml'};
# Is the item already on hold by another user?
$issue->{'itemonhold'} = Koha::Holds->search({ itemnumber => $issue->{'itemnumber'} })->count;
# Is the record (next available item) on hold by another user?
$issue->{'recordonhold'} = Koha::Holds->search({ biblionumber => $issue->{'biblionumber'} })->count;
push @checkouts, $issue push @checkouts, $issue
} }
$borrower->{'loans'}->{'loan'} = \@checkouts; $borrower->{'loans'}->{'loan'} = \@checkouts;

View file

@ -602,6 +602,8 @@
&lt;location&gt;Salle de lecture&lt;/location&gt; &lt;location&gt;Salle de lecture&lt;/location&gt;
&lt;itemlost&gt;0&lt;/itemlost&gt; &lt;itemlost&gt;0&lt;/itemlost&gt;
&lt;publicationyear&gt;1985&lt;/publicationyear&gt; &lt;publicationyear&gt;1985&lt;/publicationyear&gt;
&lt;recordonhold&gt;0&lt;/recordonhold&gt;
&lt;itemonhold&gt;0&lt;/itemonhold&gt;
&lt;issues&gt;1&lt;/issues&gt; &lt;issues&gt;1&lt;/issues&gt;
&lt;homebranch&gt;BIB&lt;/homebranch&gt; &lt;homebranch&gt;BIB&lt;/homebranch&gt;
&lt;holdingbranch&gt;BIB&lt;/holdingbranch&gt; &lt;holdingbranch&gt;BIB&lt;/holdingbranch&gt;
@ -640,6 +642,8 @@
&lt;location&gt;Salle de lecture&lt;/location&gt; &lt;location&gt;Salle de lecture&lt;/location&gt;
&lt;itemlost&gt;0&lt;/itemlost&gt; &lt;itemlost&gt;0&lt;/itemlost&gt;
&lt;publicationyear&gt;2007&lt;/publicationyear&gt; &lt;publicationyear&gt;2007&lt;/publicationyear&gt;
&lt;recordonhold&gt;1&lt;/recordonhold&gt;
&lt;itemonhold&gt;1&lt;/itemonhold&gt;
&lt;issues&gt;1&lt;/issues&gt; &lt;issues&gt;1&lt;/issues&gt;
&lt;homebranch&gt;BIB&lt;/homebranch&gt; &lt;homebranch&gt;BIB&lt;/homebranch&gt;
&lt;holdingbranch&gt;BIB&lt;/holdingbranch&gt; &lt;holdingbranch&gt;BIB&lt;/holdingbranch&gt;

View file

@ -19,7 +19,7 @@ use Modern::Perl;
use CGI qw ( -utf8 ); use CGI qw ( -utf8 );
use Test::More tests => 12; use Test::More tests => 13;
use Test::MockModule; use Test::MockModule;
use t::lib::Mocks; use t::lib::Mocks;
use t::lib::TestBuilder; use t::lib::TestBuilder;
@ -122,6 +122,102 @@ subtest 'AuthenticatePatron test' => sub {
$schema->storage->txn_rollback; $schema->storage->txn_rollback;
}; };
subtest 'GetPatronInfo test for holds' => sub {
plan tests => 8;
$schema->storage->txn_begin;
$schema->resultset( 'Issue' )->delete_all;
$schema->resultset( 'Reserve' )->delete_all;
$schema->resultset( 'Borrower' )->delete_all;
$schema->resultset( 'Category' )->delete_all;
$schema->resultset( 'Item' )->delete_all; # 'Branch' deps. on this
$schema->resultset( 'Branch' )->delete_all;
# Configure Koha to enable ILS-DI server
t::lib::Mocks::mock_preference( 'ILS-DI', 1 );
my $library = $builder->build_object({
class => 'Koha::Libraries',
});
# Create new users:
my $brwr = $builder->build_object( {
class => 'Koha::Patrons',
value => {
branchcode => $library->branchcode,
}
} );
my $brwr2 = $builder->build_object( {
class => 'Koha::Patrons',
value => {
branchcode => $library->branchcode,
}
} );
my $brwr3 = $builder->build_object( {
class => 'Koha::Patrons',
value => {
branchcode => $library->branchcode,
}
} );
my $module = Test::MockModule->new('C4::Context');
$module->mock('userenv', sub { { branch => $library->branchcode } });
# Place a loan
my $biblio = $builder->build_object( { class => 'Koha::Biblios' } );
my $itemtype = $builder->build_object({ class => 'Koha::ItemTypes' });
my $biblioitem = $builder->build_object( { class => 'Koha::Biblioitems', value => { biblionumber => $biblio->biblionumber } } );
my $item = $builder->build_sample_item({ biblionumber => $biblio->biblionumber, library => $library->branchcode, itype => $itemtype->itemtype });
my $issue = AddIssue($brwr, $item->barcode);
# Prepare and send web request for IL-SDI server:
my $query = new CGI;
$query->param( 'service', 'GetPatronInfo' );
$query->param( 'patron_id', $brwr->borrowernumber );
$query->param( 'show_loans', '1' );
my $reply = C4::ILSDI::Services::GetPatronInfo( $query );
# Check that this loan is not on hold
is ( $reply->{loans}->{loan}[0]->{recordonhold}, "0", "Record is not on hold");
is ( $reply->{loans}->{loan}[0]->{itemonhold}, "0", "Item is not on hold");
# Place a loan
# Add a hold on the biblio
my $biblioreserve = AddReserve({ branchcode => $library->branchcode, borrowernumber => $brwr2->borrowernumber, biblionumber => $biblio->biblionumber });
# Check that it is on hold on biblio level
$reply = C4::ILSDI::Services::GetPatronInfo( $query );
is ( $reply->{loans}->{loan}[0]->{recordonhold}, "1", "Record is on hold");
is ( $reply->{loans}->{loan}[0]->{itemonhold}, "0", "Item is on hold");
# Delete holds
$schema->resultset( 'Reserve' )->delete_all;
# Add a hold on the item
my $itemreserve = AddReserve({
branchcode => $library->branchcode,
borrowernumber => $brwr2->borrowernumber,
biblionumber => $biblio->biblionumber,
itemnumber => $item->itemnumber
});
# When a specific item has a reserve, the item is on hold as well as the record
$reply = C4::ILSDI::Services::GetPatronInfo( $query );
is ( $reply->{loans}->{loan}[0]->{recordonhold}, "1", "Record is on hold");
is ( $reply->{loans}->{loan}[0]->{itemonhold}, "1", "Item is on hold");
# Add another hold on the biblio
$biblioreserve = AddReserve({ branchcode => $library->branchcode, borrowernumber => $brwr3->borrowernumber, biblionumber => $biblio->biblionumber });
# Check that there are 2 holds on the biblio and 1 on this specific item
$reply = C4::ILSDI::Services::GetPatronInfo( $query );
is ( $reply->{loans}->{loan}[0]->{recordonhold}, "2", "Record is on hold twice");
is ( $reply->{loans}->{loan}[0]->{itemonhold}, "1", "Item is on hold");
# Cleanup
$schema->storage->txn_rollback;
};
subtest 'GetPatronInfo/GetBorrowerAttributes test for extended patron attributes' => sub { subtest 'GetPatronInfo/GetBorrowerAttributes test for extended patron attributes' => sub {