Bugzilla – Attachment 184755 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: Count incoming transfers against the float limit
Bug-28530-Count-incoming-transfers-against-the-flo.patch (text/plain), 7.16 KB, created by
Lucas Gass (lukeg)
on 2025-07-28 17:49:56 UTC
(
hide
)
Description:
Bug 28530: Count incoming transfers against the float limit
Filename:
MIME Type:
Creator:
Lucas Gass (lukeg)
Created:
2025-07-28 17:49:56 UTC
Size:
7.16 KB
patch
obsolete
>From ad69e459caa66bc9bb407b391997d9fa1c21eeb7 Mon Sep 17 00:00:00 2001 >From: Lucas Gass <lucas@bywatersolutions.com> >Date: Mon, 28 Jul 2025 17:48:53 +0000 >Subject: [PATCH] Bug 28530: Count incoming transfers against the float limit > >--- > Koha/Library/FloatLimits.pm | 42 ++++++++- > t/db_dependent/Koha/Library/FloatLimits.t | 109 +++++++++++++++++++++- > 2 files changed, 146 insertions(+), 5 deletions(-) > >diff --git a/Koha/Library/FloatLimits.pm b/Koha/Library/FloatLimits.pm >index 07b009e9a4d..066d88ca96d 100644 >--- a/Koha/Library/FloatLimits.pm >+++ b/Koha/Library/FloatLimits.pm >@@ -1,5 +1,3 @@ >-## Please see file perltidy.ERR >-## Please see file perltidy.ERR > package Koha::Library::FloatLimits; > > # Copyright ByWater Solutions 2016 >@@ -65,21 +63,57 @@ sub lowest_ratio_library { > my $item_count; > > if ($use_item_level) { >- $item_count = Koha::Items->search( >+ my $at_branch_count = Koha::Items->search( > { > itype => $item->effective_itemtype, > holdingbranch => $branch, > onloan => undef > }, > )->count; >+ >+ # Count items in transit TO this branch >+ my $in_transit_count = Koha::Items->search( >+ { >+ itype => $item->effective_itemtype, >+ >+ # Join with active transfers where this branch is the destination >+ }, >+ { >+ join => 'branchtransfers', >+ where => { >+ 'branchtransfers.tobranch' => $branch, >+ 'branchtransfers.datearrived' => undef, # Still in transit >+ 'branchtransfers.datecancelled' => undef, #Not cancelled >+ }, >+ distinct => 1 >+ } >+ )->count; >+ $item_count = $at_branch_count + $in_transit_count; > } else { >- $item_count = Koha::Items->search( >+ my $at_branch_count = Koha::Items->search( > { > holdingbranch => $branch, > 'biblioitem.itemtype' => $item->effective_itemtype, > onloan => undef > }, > )->count; >+ >+ # Count items in transit TO this branch >+ my $in_transit_count = Koha::Items->search( >+ { >+ itype => $item->effective_itemtype, >+ }, >+ { >+ join => 'branchtransfers', >+ where => { >+ 'branchtransfers.tobranch' => $branch, >+ 'branchtransfers.datearrived' => undef, # Still in transit >+ 'branchtransfers.datecancelled' => undef, #Not cancelled >+ }, >+ distinct => 1 >+ } >+ )->count; >+ $item_count = $at_branch_count + $in_transit_count; > } > > my $ratio = $item_count / $float_limit_val; >diff --git a/t/db_dependent/Koha/Library/FloatLimits.t b/t/db_dependent/Koha/Library/FloatLimits.t >index bd54b110053..edc59fd7646 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 => 6; >+use Test::More tests => 7; > > use Koha::Database; > use C4::Circulation qw(CreateBranchTransferLimit); >@@ -199,4 +199,111 @@ subtest 'onloan items excluded from ratio calculation' => sub { > ); > }; > >+subtest 'items in transit counted toward destination branch' => sub { >+ plan tests => 6; >+ >+ # Reset transfer limits for clean test >+ t::lib::Mocks::mock_preference( 'UseBranchTransferLimits', '0' ); >+ >+ Koha::Items->search( >+ { >+ holdingbranch => $library3->{branchcode}, >+ itype => $itemtype->itemtype, >+ onloan => { '!=' => undef } >+ } >+ )->update( { onloan => undef } ); >+ >+ # Verify initial counts >+ my $library2_initial = Koha::Items->search( >+ { >+ holdingbranch => $library2->{branchcode}, >+ itype => $itemtype->itemtype, >+ onloan => undef >+ } >+ )->count; >+ >+ my $library3_initial = Koha::Items->search( >+ { >+ holdingbranch => $library3->{branchcode}, >+ itype => $itemtype->itemtype, >+ onloan => undef >+ } >+ )->count; >+ >+ is( $library2_initial, 10, "Library2 initially has 10 available items" ); >+ is( $library3_initial, 15, "Library3 initially has 15 available items" ); >+ >+ # Initial selection should be library3 >+ is( >+ Koha::Library::FloatLimits->lowest_ratio_library( $item, $library1->{branchcode} )->branchcode, >+ $library3->{branchcode}, >+ "Library3 initially selected (ratio: 15/1000 = 0.015)" >+ ); >+ >+ # Create items in transit TO library2 >+ my @transit_items; >+ for ( 1 .. 2 ) { >+ my $transit_item = $builder->build_sample_item( >+ { >+ biblionumber => $biblio->biblionumber, >+ homebranch => $library1->{branchcode}, >+ holdingbranch => $library1->{branchcode}, >+ itype => $itemtype->itemtype, >+ } >+ ); >+ push @transit_items, $transit_item; >+ } >+ >+ # Create active transfers to library2 >+ my $transfer_date = dt_from_string(); >+ for my $transit_item (@transit_items) { >+ Koha::Item::Transfer->new( >+ { >+ itemnumber => $transit_item->itemnumber, >+ frombranch => $library1->{branchcode}, >+ tobranch => $library2->{branchcode}, >+ daterequested => $transfer_date, >+ datesent => $transfer_date, >+ reason => 'LibraryFloatLimit' >+ } >+ )->store; >+ } >+ >+ # Verify that items in transit are counted toward destination >+ my $in_transit_count = Koha::Items->search( >+ { >+ itype => $itemtype->itemtype, >+ }, >+ { >+ join => 'branchtransfers', >+ where => { >+ 'branchtransfers.tobranch' => $library2->{branchcode}, >+ 'branchtransfers.datearrived' => undef, >+ 'branchtransfers.datecancelled' => undef, >+ }, >+ distinct => 1 >+ } >+ )->count; >+ >+ is( $in_transit_count, 2, "2 items are in transit to library2" ); >+ >+ # Test 5: Library2's physical count should still be 10 >+ my $library2_physical = Koha::Items->search( >+ { >+ holdingbranch => $library2->{branchcode}, >+ itype => $itemtype->itemtype, >+ onloan => undef >+ } >+ )->count; >+ >+ is( $library2_physical, 10, "Library2 still has 10 physical items" ); >+ >+ # Library2's count should now be 10 + 2 = 12 >+ is( >+ Koha::Library::FloatLimits->lowest_ratio_library( $item, $library1->{branchcode} )->branchcode, >+ $library3->{branchcode}, >+ "Library3 still selected after items in transit to library2" >+ ); >+}; >+ > $schema->storage->txn_rollback; >-- >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