Koha/recalls/recalls_to_pull.pl
Aleisha Amohia b439354026
Bug 33220: Fix recalls to pull to not show in transit or allocated items
This patch fixes the Recalls to pull circulation report so that it does
not show items that are already allocated to another recall.

This requires the UseRecalls system preference to be enabled and recalls
circulation and fines rules to be configured.

To test:
1. Cancel any recalls on Item A/Biblio A.
2. Check out Item A to Patron A. Item A should be the only item on Biblio A (pick a record with only one item, or create a record with one item).
2. Log into the OPAC as Patron B.
3. Place a recall on Item A for Patron B. Change the pickup library so
it isn't your default library.
4. Log into the OPAC as Patron C.
5. Place a recall on Item A for Patron C. Item A should now be checked out to Patron A, with two recalls on it for Patrons B and C.
6. Log back into the staff interface.
7. Check in Item A. Confirm the recall and transfer for Patron B.
8. Go to Circulation -> Recalls to pull. Notice the recall for Patron C shows here, even though the one item that could fill this recall has already been allocated to Patron B and is in transit
9. Apply the patch and restart services
10. Refresh the Recalls to pull page
11. Confirm the recall no longer shows on the Recalls to pull page -->
SUCCESS
12. Go to Biblio A and add a second item - Item B
13. Go back to Recalls to pull and refresh the page
14. Confirm the recall for Patron C now shows and can be filled by Item
B

Sponsored-by: Auckland University of Technology
Signed-off-by: Andrew Auld <andrew.auld@ptfs-europe.com>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
2023-05-16 15:17:29 -03:00

127 lines
4.9 KiB
Perl
Executable file

#!/usr/bin/perl
# Copyright 2020 Aleisha Amohia <aleisha@catalyst.net.nz>
#
# This file is part of Koha.
# Koha is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# Koha is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Koha; if not, see <http://www.gnu.org/licenses>.
use Modern::Perl;
use CGI qw ( -utf8 );
use List::MoreUtils qw( uniq );
use C4::Auth qw( get_template_and_user );
use C4::Output qw( output_html_with_http_headers );
use Koha::BiblioFrameworks;
my $query = CGI->new;
my ( $template, $loggedinuser, $cookie, $flags ) = get_template_and_user(
{
template_name => "recalls/recalls_to_pull.tt",
query => $query,
type => "intranet",
flagsrequired => { recalls => 'manage_recalls' },
debug => 1,
}
);
my $op = $query->param('op') || 'list';
my $recall_id = $query->param('recall_id');
if ( $op eq 'cancel' ) {
my $recall = Koha::Recalls->find( $recall_id );
if ( $recall->in_transit ) {
C4::Items::ModItemTransfer(
$recall->item->itemnumber, $recall->item->holdingbranch,
$recall->item->homebranch, 'RecallCancellation'
);
}
$recall->set_cancelled;
$op = 'list';
}
if ( $op eq 'list' ) {
my @recalls = Koha::Recalls->search({ status => [ 'requested','overdue' ] })->as_list;
my @pull_list;
my %seen_bib;
foreach my $recall ( @recalls ) {
if ( $seen_bib{$recall->biblio_id} ){
# we've already looked at the recalls on this biblio
next;
} else {
# this is an unseen biblio
$seen_bib{$recall->biblio_id}++;
# get recall data about this biblio
my $biblio = $recall->biblio;
my @this_bib_recalls = $biblio->recalls->search(
{ status => [ 'requested','overdue' ] },
{ order_by => { -asc => 'created_date' } }
)->as_list;
my $recalls_count = scalar @this_bib_recalls;
my @unique_patrons = uniq @this_bib_recalls ;
my $patrons_count = scalar @unique_patrons;
my $first_recall = $this_bib_recalls[0];
my $items_count = 0;
my @callnumbers;
my @copynumbers;
my @enumchrons;
my @itemtypes;
my @locations;
my @libraries;
my @items = $biblio->items->as_list;
foreach my $item ( @items ) {
if ( $item->can_be_waiting_recall and !$item->checkout and Koha::Recalls->search({ item_id => $item->id, status => [ 'waiting','in_transit' ], completed => 0 })->count == 0 ) {
# if item can be pulled to fulfill recall, collect item data
$items_count++;
push( @callnumbers, $item->itemcallnumber ) if ( $item->itemcallnumber );
push( @copynumbers, $item->copynumber ) if ( $item->copynumber );
push( @enumchrons, $item->enumchron ) if ( $item->enumchron );
push( @itemtypes, $item->effective_itemtype ) if ( $item->effective_itemtype );
push( @locations, $item->location ) if ( $item->location );
push( @libraries, $item->holdingbranch ) if ( $item->holdingbranch );
}
}
if ( $items_count > 0 ) {
# don't push data if there are no items available for this recall
# get unique values
push( @pull_list, {
biblio => $biblio,
items_count => $items_count,
recalls_count => $recalls_count,
patrons_count => $patrons_count,
pull_count => $items_count <= $recalls_count ? $items_count : $recalls_count,
first_recall => $first_recall,
callnumbers => [ uniq @callnumbers ],
copynumbers => [ uniq @copynumbers ],
enumchrons => [ uniq @enumchrons ],
itemtypes => [ uniq @itemtypes ],
locations => [ uniq @locations ],
libraries => [ uniq @libraries ],
});
}
}
}
$template->param(
recalls => \@pull_list,
);
}
# Checking if there is a Fast Cataloging Framework
$template->param( fast_cataloging => 1 ) if Koha::BiblioFrameworks->find( 'FA' );
# writing the template
output_html_with_http_headers $query, $cookie, $template->output;