From 2287338bb39eb5c7b9bf6ee5c505e9c41144081b Mon Sep 17 00:00:00 2001 From: Aleisha Amohia Date: Fri, 6 Nov 2020 10:42:08 +1300 Subject: [PATCH] Bug 19532: (follow-up) Fix undef recall_id preventing fulfillment of recall Signed-off-by: David Nind --- C4/Circulation.pm | 6 +++--- Koha/Recalls.pm | 10 +++++----- circ/circulation.pl | 5 +++++ 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index 59e4786f9b..2317cb9528 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -1131,10 +1131,10 @@ sub CanBookBeIssued { if ( $r->itemnumber and $r->itemnumber == $item_object->itemnumber and $r->borrowernumber == $patron->borrowernumber and - $r->waiting ) { + ( $r->waiting or $r->requested ) ) { $messages{RECALLED} = $r->recall_id; $recall = $r; - # this item is already waiting for this borrower and the recall can be fulfilled + # this item is recalled by or already waiting for this borrower and the recall can be fulfilled last; } elsif ( $r->itemnumber and @@ -1571,7 +1571,7 @@ sub AddIssue { $item_object->discard_changes; } - Koha::Recalls->move_recall({ action => $cancel_recall, recall_id => $recall_id, itemnumber => $item_object->itemnumber, borrowernumber => $borrower->{borrowernumber} }) if C4::Context->preference('UseRecalls'); + Koha::Recalls->move_recall({ action => $cancel_recall, recall_id => $recall_id, item => $item_object, borrowernumber => $borrower->{borrowernumber} }) if C4::Context->preference('UseRecalls'); C4::Reserves::MoveReserve( $item_object->itemnumber, $borrower->{'borrowernumber'}, $cancelreserve ); diff --git a/Koha/Recalls.pm b/Koha/Recalls.pm index 5e27d421f0..e454499f67 100644 --- a/Koha/Recalls.pm +++ b/Koha/Recalls.pm @@ -145,7 +145,7 @@ sub add_recall { my $message = Koha::Recalls->move_recall({ recall_id = $recall_id, action => $action, - itemnumber => $itemnumber, + item => $item_object, borrowernumber => $borrowernumber, }); @@ -155,7 +155,7 @@ We can also fulfill the recall here if the recall is placed by this borrower. recall_id = ID of the recall to perform the action on action = either cancel or revert -itemnumber = itemnumber the patron is attempting to check out +item = item object that the patron is attempting to check out borrowernumber = borrowernumber of the patron that is attemptig to check out =cut @@ -166,7 +166,7 @@ sub move_recall { my $recall_id = $params->{recall_id}; my $action = $params->{action}; return 'no recall_id provided' if ( !defined $recall_id ); - my $itemnumber = $params->{itemnumber}; + my $item = $params->{item}; my $borrowernumber = $params->{borrowernumber}; my $message = 'no action provided'; @@ -181,9 +181,9 @@ sub move_recall { $message = 'reverted'; } - if ( $message eq 'no action provided' and $itemnumber and $borrowernumber ) { + if ( $message eq 'no action provided' and $item and $item->biblionumber and $borrowernumber ) { # move_recall was not called to revert or cancel, but was called to fulfill - my $recall = Koha::Recalls->find({ borrowernumber => $borrowernumber, itemnumber => $itemnumber, old => undef }); + my $recall = Koha::Recalls->find({ borrowernumber => $borrowernumber, biblionumber => $item->biblionumber, itemnumber => [ $item->itemnumber, undef ], old => undef }); if ( $recall ) { $recall->set_finished; $message = 'fulfilled'; diff --git a/circ/circulation.pl b/circ/circulation.pl index bf95920273..61d32cc6cf 100755 --- a/circ/circulation.pl +++ b/circ/circulation.pl @@ -410,6 +410,11 @@ if (@$barcodes) { } unless($confirm_required) { my $switch_onsite_checkout = exists $messages->{ONSITE_CHECKOUT_WILL_BE_SWITCHED}; + if ( !$recall_id ) { + my $item = Koha::Items->find({ barcode => $barcode }); + my $recall = Koha::Recalls->find({ biblionumber => $item->biblionumber, itemnumber => [ undef, $item->itemnumber ], status => [ 'R','W' ], old => undef, borrowernumber => $patron->borrowernumber }); + $recall_id = ( $recall and $recall->recall_id ) ? $recall->recall_id : undef; + } my $issue = AddIssue( $patron->unblessed, $barcode, $datedue, $cancelreserve, undef, undef, { onsite_checkout => $onsite_checkout, auto_renew => $session->param('auto_renew'), switch_onsite_checkout => $switch_onsite_checkout, cancel_recall => $cancel_recall, recall_id => $recall_id, } ); $template_params->{issue} = $issue; $session->clear('auto_renew'); -- 2.11.0