From ab770ba680c502c327df8226afb85f3d4475e200 Mon Sep 17 00:00:00 2001 From: Lari Taskula Date: Fri, 30 Aug 2019 16:30:07 +0000 Subject: [PATCH] Bug 7376: Refactoring subroutines CanBookBeReturned: - Take Koha::Item as parameter instead of HASHref of an item To test: 1. cd into your Koha root directory 2. grep -rn 'CanBookBeReturned(' 3. Make sure all returned occurences are using Koha::Item Sponsored-by: National Library of Finland --- C4/Circulation.pm | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index 66993ea461..dd24308894 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -877,7 +877,7 @@ sub CanBookBeIssued { my $patron = Koha::Patrons->find( $issue->borrowernumber ); - my ( $can_be_returned, $message ) = CanBookBeReturned( $item_unblessed, C4::Context->userenv->{branch} ); + my ( $can_be_returned, $message ) = CanBookBeReturned( $item_object, C4::Context->userenv->{branch} ); unless ( $can_be_returned ) { $issuingimpossible{RETURN_IMPOSSIBLE} = 1; @@ -1120,7 +1120,7 @@ Check whether the item can be returned to the provided branch =over 4 -=item C<$item> is a hash of item information as returned Koha::Items->find->unblessed (Temporary, should be a Koha::Item instead) +=item C<$item> is a Koha::Item object =item C<$branch> is the branchcode where the return is taking place @@ -1147,15 +1147,15 @@ sub CanBookBeReturned { my $message; # identify all cases where return is forbidden - if ($allowreturntobranch eq 'homebranch' && $branch ne $item->{'homebranch'}) { + if ($allowreturntobranch eq 'homebranch' && $branch ne $item->homebranch) { $allowed = 0; - $message = $item->{'homebranch'}; - } elsif ($allowreturntobranch eq 'holdingbranch' && $branch ne $item->{'holdingbranch'}) { + $message = $item->homebranch; + } elsif ($allowreturntobranch eq 'holdingbranch' && $branch ne $item->holdingbranch) { $allowed = 0; - $message = $item->{'holdingbranch'}; - } elsif ($allowreturntobranch eq 'homeorholdingbranch' && $branch ne $item->{'homebranch'} && $branch ne $item->{'holdingbranch'}) { + $message = $item->holdingbranch; + } elsif ($allowreturntobranch eq 'homeorholdingbranch' && $branch ne $item->homebranch && $branch ne $item->holdingbranch) { $allowed = 0; - $message = $item->{'homebranch'}; # FIXME: choice of homebranch is arbitrary + $message = $item->homebranch; # FIXME: choice of homebranch is arbitrary } return ($allowed, $message); @@ -1361,7 +1361,7 @@ sub AddIssue { if ( $actualissue and not $switch_onsite_checkout ) { # This book is currently on loan, but not to the person # who wants to borrow it now. mark it returned before issuing to the new borrower - my ( $allowed, $message ) = CanBookBeReturned( $item_unblessed, C4::Context->userenv->{branch} ); + my ( $allowed, $message ) = CanBookBeReturned( $item_object, C4::Context->userenv->{branch} ); return unless $allowed; AddReturn( $item_object->barcode, C4::Context->userenv->{'branch'} ); } @@ -1924,7 +1924,7 @@ sub AddReturn { } # check if the return is allowed at this branch - my ($returnallowed, $message) = CanBookBeReturned($item_unblessed, $branch); + my ($returnallowed, $message) = CanBookBeReturned($item, $branch); unless ($returnallowed){ $messages->{'Wrongbranch'} = { Wrongbranch => $branch, -- 2.17.1