From 6391e8ef2a562d1b2a645b020736689ce1b87093 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Tue, 4 Jan 2022 13:37:53 +0000 Subject: [PATCH] Bug 29786: Select only specific items for item level holds This patch adjusts get_items_that_can_fill to make two requests: first the list of items for item-level holds second the list of biblionumbers for title-level holds This stops the report from pulling more items for item-level hold This patch also removes the aliases used in the code - while readability is a bit harder, it allows for using 'me' in get_items_that_can_fill Otherwise, this routine would need a parameter to know what we called the table. To test: 1 - Find a record with many items available 2 - Place an item level hold for an item on the record, not the one with lowest itemnumber 3 - Run 'Hold to pull' report 4 - Note the barcode does not match 5 - Apply patch 6 - Reload report 7 - It matches! Signed-off-by: Andrew Fuerste-Henry Signed-off-by: Jonathan Druart Signed-off-by: Fridolin Somers Signed-off-by: Kyle M Hall (cherry picked from commit 0ce4a042c3774a5006ae8ada8f802b953fcc0c5f) Signed-off-by: Andrew Fuerste-Henry --- Koha/Holds.pm | 8 ++++++-- circ/pendingreserves.pl | 18 ++++++++---------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/Koha/Holds.pm b/Koha/Holds.pm index 68f77b3d0b..19bcb6c02f 100644 --- a/Koha/Holds.pm +++ b/Koha/Holds.pm @@ -112,7 +112,11 @@ Items that are not: sub get_items_that_can_fill { my ( $self ) = @_; - my @biblionumbers = $self->get_column('biblionumber'); + my @itemnumbers = $self->search({ 'me.itemnumber' => { '!=' => undef } })->get_column('itemnumber'); + my @biblionumbers = $self->search({ 'me.itemnumber' => undef })->get_column('biblionumber'); + my @bibs_or_items; + push @bibs_or_items, 'me.itemnumber' => { in => \@itemnumbers } if @itemnumbers; + push @bibs_or_items, 'biblionumber' => { in => \@biblionumbers } if @biblionumbers; my @branchtransfers = map { $_->itemnumber } Koha::Item::Transfers->search( @@ -133,7 +137,7 @@ sub get_items_that_can_fill { return Koha::Items->search( { - biblionumber => { in => \@biblionumbers }, + -or => \@bibs_or_items, itemnumber => { -not_in => [ @branchtransfers, @waiting_holds ] }, onloan => undef, } diff --git a/circ/pendingreserves.pl b/circ/pendingreserves.pl index 44d4f87e4d..bcaffe773f 100755 --- a/circ/pendingreserves.pl +++ b/circ/pendingreserves.pl @@ -157,9 +157,9 @@ unless ( $enddate ) { # building query parameters my %where = ( - 'reserve.found' => undef, - 'reserve.priority' => 1, - 'reserve.suspend' => 0, + 'me.found' => undef, + 'me.priority' => 1, + 'me.suspend' => 0, 'itembib.itemlost' => 0, 'itembib.withdrawn' => 0, 'itembib.notforloan' => 0, @@ -171,11 +171,11 @@ my $dtf = Koha::Database->new->schema->storage->datetime_parser; my $startdate_iso = $dtf->format_date($startdate); my $enddate_iso = $dtf->format_date($enddate); if ( $startdate_iso && $enddate_iso ){ - $where{'reserve.reservedate'} = [ -and => { '>=', $startdate_iso }, { '<=', $enddate_iso } ]; + $where{'me.reservedate'} = [ -and => { '>=', $startdate_iso }, { '<=', $enddate_iso } ]; } elsif ( $startdate_iso ){ - $where{'reserve.reservedate'} = { '>=', $startdate_iso }; + $where{'me.reservedate'} = { '>=', $startdate_iso }; } elsif ( $enddate_iso ){ - $where{'reserve.reservedate'} = { '<=', $enddate_iso }; + $where{'me.reservedate'} = { '<=', $enddate_iso }; } # Bug 21320 @@ -190,7 +190,7 @@ if ( C4::Context->preference('IndependentBranches') ){ # get all distinct unfulfilled reserves my $holds = Koha::Holds->search( { %where }, - { join => 'itembib', alias => 'reserve', distinct => 1, columns => qw[me.biblionumber] } + { join => 'itembib', distinct => 1, columns => qw[me.biblionumber] } ); my @biblionumbers = $holds->get_column('biblionumber'); @@ -217,8 +217,7 @@ my $holds_biblios_map = { {%where}, { join => ['itembib', 'biblio'], - alias => 'reserve', - select => ['reserve.biblionumber', 'reserve.reserve_id'], + select => ['me.biblionumber', 'me.reserve_id'], } )->unblessed } @@ -229,7 +228,6 @@ my $all_holds = { { reserve_id => [ values %$holds_biblios_map ]}, { prefetch => [ 'borrowernumber', 'itembib', 'biblio' ], - alias => 'reserve', } )->as_list } -- 2.39.5