From 1bc4a4b78f0661f7ed66cae64f3a7f721d08df92 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Fri, 18 May 2018 07:20:06 -0400 Subject: [PATCH] Bug 17561: (QA follow-up) Simplify new ReserveSlip code Signed-off-by: Kyle M Hall Signed-off-by: Jonathan Druart Signed-off-by: Nick Clemens Signed-off-by: Martin Renvoize (cherry picked from commit a088aad171fda8deefca517517d35bee851f7ffc) Signed-off-by: Fridolin Somers --- C4/Reserves.pm | 54 +++++++++++++++++++++++++++++++++----------------- 1 file changed, 36 insertions(+), 18 deletions(-) diff --git a/C4/Reserves.pm b/C4/Reserves.pm index 5b245ee4d2..f7e8f9b0c6 100644 --- a/C4/Reserves.pm +++ b/C4/Reserves.pm @@ -1964,13 +1964,15 @@ sub RevertWaitingStatus { =head2 ReserveSlip - ReserveSlip($args => { - branchcode, - borrowernumber, - biblionumber, - [itemnumber], - [barcode], - }) +ReserveSlip( + { + branchcode => $branchcode, + borrowernumber => $borrowernumber, + biblionumber => $biblionumber, + [ itemnumber => $itemnumber, ] + [ barcode => $barcode, ] + } + ) Returns letter hash ( see C4::Letters::GetPreparedLetter ) or undef @@ -1988,18 +1990,34 @@ available within the slip: sub ReserveSlip { my ($args) = @_; - my $patron = Koha::Patrons->find( $args->{borrowernumber} ); + my $branchcode = $args->{branchcode}; + my $borrowernumber = $args->{borrowernumber}; + my $biblionumber = $args->{biblionumber}; + my $itemnumber = $args->{itemnumber}; + my $barcode = $args->{barcode}; + + + my $patron = Koha::Patrons->find($borrowernumber); my $hold; - if ($args->{itemnumber}) { - $hold = Koha::Holds->search({biblionumber => $args->{biblionumber}, borrowernumber => $args->{borrowernumber}, itemnumber => $args->{itemnumber} })->next; - } elsif ($args->{barcode}) { - my $itemnumber = Koha::Items->find({ barcode => $args->{barcode} }); - if ($args->{itemnumber}) { - $hold = Koha::Holds->search({biblionumber => $args->{biblionumber}, borrowernumber => $args->{borrowernumber}, itemnumber => $args->{itemnumber} })->next; - } - } else { - $hold = Koha::Holds->search({biblionumber => $args->{biblionumber}, borrowernumber => $args->{borrowernumber} })->next; + if ($itemnumber || $barcode ) { + $itemnumber ||= Koha::Items->find( { barcode => $barcode } )->itemnumber; + + $hold = Koha::Holds->search( + { + biblionumber => $biblionumber, + borrowernumber => $borrowernumber, + itemnumber => $itemnumber + } + )->next; + } + else { + $hold = Koha::Holds->search( + { + biblionumber => $biblionumber, + borrowernumber => $borrowernumber + } + )->next; } return unless $hold; @@ -2008,7 +2026,7 @@ sub ReserveSlip { return C4::Letters::GetPreparedLetter ( module => 'circulation', letter_code => 'HOLD_SLIP', - branchcode => $args->{branchcode}, + branchcode => $branchcode, lang => $patron->lang, tables => { 'reserves' => $reserve, -- 2.39.5