From 0ce4a042c3774a5006ae8ada8f802b953fcc0c5f 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 --- 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 6885b4d6bf..cfaeb4583a 100644 --- a/Koha/Holds.pm +++ b/Koha/Holds.pm @@ -111,7 +111,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( @@ -132,7 +136,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 0b2fea2195..8ca7245b3c 100755 --- a/circ/pendingreserves.pl +++ b/circ/pendingreserves.pl @@ -155,9 +155,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, @@ -169,11 +169,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 @@ -188,7 +188,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'); @@ -215,8 +215,7 @@ my $holds_biblios_map = { {%where}, { join => ['itembib', 'biblio'], - alias => 'reserve', - select => ['reserve.biblionumber', 'reserve.reserve_id'], + select => ['me.biblionumber', 'me.reserve_id'], } )->unblessed } @@ -227,7 +226,6 @@ my $all_holds = { { reserve_id => [ values %$holds_biblios_map ]}, { prefetch => [ 'borrowernumber', 'itembib', 'biblio' ], - alias => 'reserve', } )->as_list } -- 2.39.5