From a088aad171fda8deefca517517d35bee851f7ffc 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 --- C4/Reserves.pm | 54 +++++++++++++++++++++++++++++++++----------------- 1 file changed, 36 insertions(+), 18 deletions(-) diff --git a/C4/Reserves.pm b/C4/Reserves.pm index e7fc3c1eb5..359fd984b6 100644 --- a/C4/Reserves.pm +++ b/C4/Reserves.pm @@ -1868,13 +1868,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 @@ -1892,18 +1894,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; @@ -1912,7 +1930,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