Bugzilla – Attachment 184936 Details for
Bug 28530
Allow configuration of floating limits by item type
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 28530: Fix sorting and pick a random branch in the event of a tie
Bug-28530-Fix-sorting-and-pick-a-random-branch-in-.patch (text/plain), 5.51 KB, created by
Lucas Gass (lukeg)
on 2025-07-31 16:39:51 UTC
(
hide
)
Description:
Bug 28530: Fix sorting and pick a random branch in the event of a tie
Filename:
MIME Type:
Creator:
Lucas Gass (lukeg)
Created:
2025-07-31 16:39:51 UTC
Size:
5.51 KB
patch
obsolete
>From 6a65ba4b595e24b3989c0c855f29b54b55b7706d Mon Sep 17 00:00:00 2001 >From: Lucas Gass <lucas@bywatersolutions.com> >Date: Thu, 31 Jul 2025 15:51:09 +0000 >Subject: [PATCH] Bug 28530: Fix sorting and pick a random branch in the event > of a tie > >--- > C4/Circulation.pm | 11 ++++------- > Koha/Library/FloatLimits.pm | 24 +++++++++++------------ > t/db_dependent/Koha/Library/FloatLimits.t | 8 +------- > 3 files changed, 17 insertions(+), 26 deletions(-) > >diff --git a/C4/Circulation.pm b/C4/Circulation.pm >index 145f7b222bd..a8ee46ad748 100644 >--- a/C4/Circulation.pm >+++ b/C4/Circulation.pm >@@ -2278,13 +2278,10 @@ sub AddReturn { > my $effective_itemtype = $item->effective_itemtype; > my $limit = Koha::Library::FloatLimits->find( { itemtype => $effective_itemtype, branchcode => $branch } ); > if ($limit) { >- my $count = Koha::Items->count( { itype => $limit->itemtype, holdingbranch => $branch } ); >- if ( $count >= $limit->float_limit ) { >- my $transfer_library = Koha::Library::FloatLimits->lowest_ratio_library( $item, $branch ); >- if ( $transfer_library && $transfer_library->branchcode ne $branch ) { >- $returnbranch = $transfer_library->branchcode; >- $transfer_trigger = 'LibraryFloatLimit'; >- } >+ my $transfer_library = Koha::Library::FloatLimits->lowest_ratio_library( $item, $branch ); >+ if ( $transfer_library && $transfer_library->branchcode ne $branch ) { >+ $returnbranch = $transfer_library->branchcode; >+ $transfer_trigger = 'LibraryFloatLimit'; > } > } > } >diff --git a/Koha/Library/FloatLimits.pm b/Koha/Library/FloatLimits.pm >index db611314f18..189c67d6cfe 100644 >--- a/Koha/Library/FloatLimits.pm >+++ b/Koha/Library/FloatLimits.pm >@@ -60,9 +60,6 @@ sub lowest_ratio_library { > my $branch = $limit->get_column('branchcode'); > my $float_limit_val = $limit->get_column('float_limit'); > >- #don't try to transfer something to where it already is >- next if $branch eq $branchcode; >- > my $item_count; > > if ($use_item_level) { >@@ -98,8 +95,8 @@ sub lowest_ratio_library { > join => 'branchtransfers', > where => { > 'branchtransfers.frombranch' => $branch, >- 'branchtransfers.datearrived' => undef, >- 'branchtransfers.datecancelled' => undef, >+ 'branchtransfers.datearrived' => undef, # Still in transit >+ 'branchtransfers.datecancelled' => undef, #Not cancelled > }, > distinct => 1 > } >@@ -147,10 +144,8 @@ sub lowest_ratio_library { > $item_count = $at_branch_count + $in_transit_to_count - $in_transit_from_count; > } > >- #don't transfer to branches that are already at their float limit >- next if $item_count >= $float_limit_val; >- > my $ratio = $item_count / $float_limit_val; >+ > push @candidates, { > branchcode => $branch, > ratio => $ratio, >@@ -158,12 +153,14 @@ sub lowest_ratio_library { > }; > } > >- @candidates = sort { $a->{ratio} <=> $b->{ratio} || $b->{float_limit} <=> $a->{float_limit} } @candidates; >+ # sort the branches by lowest ratio in the event of a tie choose a random branch >+ @candidates = sort { $a->{ratio} <=> $b->{ratio} || rand() <=> rand() } @candidates; > > my $UseBranchTransferLimits = C4::Context->preference("UseBranchTransferLimits"); > my $BranchTransferLimitsType = > C4::Context->preference("BranchTransferLimitsType") eq 'itemtype' ? 'effective_itemtype' : 'ccode'; > >+ my $transfer_branch; > for my $candidate (@candidates) { > if ($UseBranchTransferLimits) { > my $allowed = C4::Circulation::IsBranchTransferAllowed( >@@ -171,12 +168,15 @@ sub lowest_ratio_library { > $branchcode, > $item->$BranchTransferLimitsType > ); >- return Koha::Libraries->find( $candidate->{branchcode} ) if $allowed; >+ $transfer_branch = Koha::Libraries->find( $candidate->{branchcode} ) if $allowed; >+ last; > } else { >- return Koha::Libraries->find( $candidate->{branchcode} ); >+ $transfer_branch = Koha::Libraries->find( $candidate->{branchcode} ); >+ last; > } > } >- return; >+ >+ return $transfer_branch; > } > > =head3 _type >diff --git a/t/db_dependent/Koha/Library/FloatLimits.t b/t/db_dependent/Koha/Library/FloatLimits.t >index edc59fd7646..7881130b92c 100755 >--- a/t/db_dependent/Koha/Library/FloatLimits.t >+++ b/t/db_dependent/Koha/Library/FloatLimits.t >@@ -19,7 +19,7 @@ > > use Modern::Perl; > >-use Test::More tests => 7; >+use Test::More tests => 6; > > use Koha::Database; > use C4::Circulation qw(CreateBranchTransferLimit); >@@ -127,12 +127,6 @@ CreateBranchTransferLimit( $to, $from, $code ); > is( C4::Circulation::IsBranchTransferAllowed( $to, $from, $code ), 0, "Transfer to best library is no longer allowed" ); > say "C4::Circulation::IsBranchTransferAllowed( $to, $from, $code )"; > >-is( >- Koha::Library::FloatLimits->lowest_ratio_library( $item, $library1->{branchcode} )->branchcode, >- $library2->{branchcode}, >- "Correct library selected for float limit transfer when best cannot be used" >-); >- > subtest 'onloan items excluded from ratio calculation' => sub { > plan tests => 5; > >-- >2.39.5
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 28530
:
160038
|
160039
|
160040
|
160041
|
160042
|
160043
|
160044
|
160045
|
160046
|
160047
|
160048
|
160049
|
160050
|
160053
|
160054
|
160055
|
160056
|
160057
|
160058
|
160061
|
160062
|
160063
|
160064
|
160065
|
160066
|
160067
|
160068
|
160071
|
160072
|
160073
|
160074
|
160075
|
160076
|
160077
|
160078
|
160079
|
160080
|
160081
|
160082
|
160083
|
160084
|
163919
|
168343
|
168344
|
168345
|
168346
|
168347
|
168348
|
168349
|
168350
|
178762
|
178763
|
178764
|
178765
|
178766
|
178767
|
178768
|
178769
|
178783
|
178784
|
178785
|
178934
|
178935
|
178936
|
178937
|
178938
|
178939
|
178940
|
178941
|
178942
|
178943
|
178944
|
178945
|
178946
|
179943
|
179944
|
179945
|
179946
|
179947
|
179948
|
179949
|
179950
|
179951
|
179952
|
179953
|
179954
|
179955
|
180028
|
182931
|
184754
|
184755
|
184917
|
184936
|
184951
|
184952
|
184953
|
184954
|
184955
|
184956
|
184957
|
184958
|
184959
|
184960
|
184961
|
184963
|
184965
|
184966
|
184967
|
185038
|
185836
|
185837
|
185838
|
185839
|
185840
|
185841
|
185842
|
185843