From 394665d42c900398d68b2e580c09ae00c407e174 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 --- Koha/Item.pm | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/Koha/Item.pm b/Koha/Item.pm index dba357e6800..e98387cecb5 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.25.1