From e0b5542b077de94d53dc7049a0edbadae5a06ca8 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Fri, 20 May 2022 11:46:12 -0300 Subject: [PATCH] Bug 30825: Add Koha::Item->holds_control_library This simple method takes care of calculating the control branch for an item and a patron, depending on a syspref. It targets replacing C4::Reserves::GetReservesControlBranch To test: 1. Apply this patch 2. Run: $ kshell k$ prove t/db_dependent/Koha/Item.t => SUCCESS: Tests pass! 3. Sign off :-D Signed-off-by: Tomas Cohen Arazi Signed-off-by: Martin Renvoize Signed-off-by: Kyle M Hall Signed-off-by: David Nind Signed-off-by: Tomas Cohen Arazi --- Koha/Item.pm | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/Koha/Item.pm b/Koha/Item.pm index 8be3082f4d..935f33ceb2 100644 --- a/Koha/Item.pm +++ b/Koha/Item.pm @@ -483,6 +483,25 @@ sub holds { return Koha::Holds->_new_from_dbic( $holds_rs ); } +=head3 holds_control_library + + my $control_library = $item->holds_control_library( $patron ); + +Given a I object, this method returns a library id, for +the library that is to be used for calculating circulation rules. It relies +on the B system preference. + +=cut + +sub holds_control_library { + my ( $self, $patron ) = @_; + + return ( + C4::Context->preference('ReservesControlBranch') eq 'ItemHomeLibrary' ) + ? $self->homebranch + : $patron->branchcode; +} + =head3 request_transfer my $transfer = $item->request_transfer( @@ -740,8 +759,7 @@ sub pickup_locations { my $patron = $params->{patron}; - my $circ_control_branch = - C4::Reserves::GetReservesControlBranch( $self->unblessed(), $patron->unblessed ); + my $circ_control_branch = $self->holds_control_library( $patron ); my $branchitemrule = C4::Circulation::GetBranchItemRule( $circ_control_branch, $self->itype ); -- 2.39.5