From 88a43c7b2ee4fe6ebd35b2e66d761ed432a29a0f Mon Sep 17 00:00:00 2001 From: Lucas Gass Date: Thu, 31 Jul 2025 22:46:36 +0000 Subject: [PATCH] Bug 28530: If return policy is set to float in library group, remove non group branches --- Koha/Library/FloatLimits.pm | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/Koha/Library/FloatLimits.pm b/Koha/Library/FloatLimits.pm index 189c67d6cfe..07aa5e934f1 100644 --- a/Koha/Library/FloatLimits.pm +++ b/Koha/Library/FloatLimits.pm @@ -41,7 +41,6 @@ Koha::Library::FloatLimits - Koha Library::FloatLimit object set class sub lowest_ratio_library { my ( $self, $item, $branchcode ) = @_; - my $schema = Koha::Database->new->schema; my @float_limits = $schema->resultset('LibraryFloatLimit')->search( @@ -51,6 +50,21 @@ sub lowest_ratio_library { } )->all; + # check the items return policy + my $hbr = Koha::CirculationRules->get_return_branch_policy($item); + + # if item only floats in the library group we must eliminate all other candidates + if ( $hbr && $hbr eq 'returnbylibrarygroup' ) { + my $current_library = Koha::Libraries->find($branchcode); + my $float_libraries = $current_library->get_float_libraries; + + if ( $float_libraries->count > 0 ) { + my @allowed_branchcodes = $float_libraries->get_column('branchcode'); + my %allowed_branches = map { $_ => 1 } @allowed_branchcodes; + @float_limits = grep { $allowed_branches{ $_->get_column('branchcode') } } @float_limits; + } + } + return unless @float_limits; my @candidates; @@ -162,12 +176,14 @@ sub lowest_ratio_library { my $transfer_branch; for my $candidate (@candidates) { + if ($UseBranchTransferLimits) { my $allowed = C4::Circulation::IsBranchTransferAllowed( $candidate->{branchcode}, $branchcode, $item->$BranchTransferLimitsType ); + $transfer_branch = Koha::Libraries->find( $candidate->{branchcode} ) if $allowed; last; } else { -- 2.39.5