From 268b41a13dba26cbc61afec10a6b78e2b575cadc 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 Signed-off-by: Arthur Suzuki --- C4/Circulation.pm | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index 2fe1dcdede..579911e159 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -879,7 +879,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; @@ -1131,7 +1131,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 @@ -1158,15 +1158,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); @@ -1379,7 +1379,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'} ); } @@ -1953,7 +1953,8 @@ 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.11.0