From ece8de4957b649662fca51216700f91362c7e6b0 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 | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/Koha/Library/FloatLimits.pm b/Koha/Library/FloatLimits.pm index 189c67d6cfe..7f8161c80a2 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,37 @@ 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 canditates + if ( $hbr && $hbr eq 'returnbylibrarygroup' ) { + my @allowed_branchcodes = (); + + my @current_groups = Koha::Libraries->find($branchcode)->library_groups->as_list; + for my $group (@current_groups) { + my $parent_id = $group->parent_id; + + if ($parent_id) { + my @sibling_groups = $schema->resultset('LibraryGroup')->search( + { + parent_id => $parent_id, + branchcode => { '!=' => undef } + } + )->all; + + for my $sibling (@sibling_groups) { + push @allowed_branchcodes, $sibling->get_column('branchcode'); + } + } + } + + if (@allowed_branchcodes) { + 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 +192,15 @@ 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