From eb87b4d8de23ba47d48e3155121b6e1ab34c8fa0 Mon Sep 17 00:00:00 2001 From: Alex Arnaud Date: Wed, 31 Oct 2018 16:36:59 +0100 Subject: [PATCH] Bug 21738: Move counting of items in C4::Reserves::CanBookBeReserved Test plan: - Try holding a title without items via ILS-DI => error, - try the same via UI => message is "Cannot place hold: this record has no items attached." - apply this patch, - try to hold a title without items via ILS-DI => "NotHoldable", - try again via UI => message is still "NotHoldable" --- C4/Reserves.pm | 2 +- reserve/request.pl | 10 ++++------ t/db_dependent/Reserves/NoItems.t | 25 +++++++++++++++++++++++++ 3 files changed, 30 insertions(+), 7 deletions(-) create mode 100644 t/db_dependent/Reserves/NoItems.t diff --git a/C4/Reserves.pm b/C4/Reserves.pm index 78e8f6a..44557e1 100644 --- a/C4/Reserves.pm +++ b/C4/Reserves.pm @@ -283,7 +283,7 @@ sub CanBookBeReserved{ push (@itemnumbers, @hostitems); } - my $canReserve; + my $canReserve = { status => 'NoItems' }; foreach my $itemnumber (@itemnumbers) { $canReserve = CanItemBeReserved( $borrowernumber, $itemnumber, $pickup_branchcode ); return { status => 'OK' } if $canReserve->{status} eq 'OK'; diff --git a/reserve/request.pl b/reserve/request.pl index a1668a4..28bc47a 100755 --- a/reserve/request.pl +++ b/reserve/request.pl @@ -234,6 +234,10 @@ foreach my $biblionumber (@biblionumbers) { $template->param( $canReserve->{status} => 1 ); $biblioloopiter{ $canReserve->{status} } = 1; } + elsif ( $canReserve->{status} eq 'NoItems' ) { + $template->param('noitems' => 1); + $biblioloopiter{noitems} = 1; + } else { $biblioloopiter{ $canReserve->{status} } = 1; } @@ -305,12 +309,6 @@ foreach my $biblionumber (@biblionumbers) { my $items = Koha::Items->search({ -or => { biblionumber => $biblionumber, itemnumber => { in => \@itemnumbers } } }); - unless ( $items->count ) { - # FIXME Then why do we continue? - $template->param('noitems' => 1); - $biblioloopiter{noitems} = 1; - } - ## Here we go backwards again to create hash of biblioitemnumber to itemnumbers, ## when by definition all of the itemnumber have the same biblioitemnumber my ( $iteminfos_of ); diff --git a/t/db_dependent/Reserves/NoItems.t b/t/db_dependent/Reserves/NoItems.t new file mode 100644 index 0000000..37b9f5b --- /dev/null +++ b/t/db_dependent/Reserves/NoItems.t @@ -0,0 +1,25 @@ +#!/usr/bin/perl + +use Modern::Perl; +use Test::More tests => 1; + +use C4::Reserves; + +use t::lib::TestBuilder; + +my $schema = Koha::Database->new->schema; +$schema->storage->txn_begin; + +$schema->storage->txn_rollback; + +my $builder = t::lib::TestBuilder->new(); + +my $biblio = $builder->build({ + source => 'Biblio', +}); + +my $patron = $builder->build({ + source => 'Borrower', +}); + +is( C4::Reserves::CanBookBeReserved($patron->{borrowernumber}, $biblio->{biblionumber})->{status} , 'NoItems', "Reserving a Biblio without items fail." ); -- 2.7.4