From ab035974a1364f145d095ce37dc9def16e51fc89 Mon Sep 17 00:00:00 2001 From: Lucas Gass Date: Tue, 7 Oct 2025 13:52:11 +0000 Subject: [PATCH] Bug 28530: Increment and decrement item count before calculation --- C4/Circulation.pm | 3 ++- Koha/Library/FloatLimits.pm | 31 ++++++++++++++++++++++++++++++- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index 1e3c83e66c3..c1d935e1fd6 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -2412,7 +2412,8 @@ sub AddReturn { my $effective_itemtype = $item->effective_itemtype; my $limit = Koha::Library::FloatLimits->find( { itemtype => $effective_itemtype, branchcode => $branch } ); if ($limit) { - my $transfer_library = Koha::Library::FloatLimits->lowest_ratio_library( $item, $branch ); + my $transfer_library = + Koha::Library::FloatLimits->lowest_ratio_library( $item, $branch, $item->holdingbranch ); 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 913f3a65779..14ea1bbf511 100644 --- a/Koha/Library/FloatLimits.pm +++ b/Koha/Library/FloatLimits.pm @@ -40,7 +40,7 @@ Koha::Library::FloatLimits - Koha Library::FloatLimit object set class =cut sub lowest_ratio_library { - my ( $self, $item, $branchcode ) = @_; + my ( $self, $item, $branchcode, $from_branch ) = @_; my $schema = Koha::Database->new->schema; my @float_limits = $schema->resultset('LibraryFloatLimit')->search( @@ -116,6 +116,21 @@ sub lowest_ratio_library { } )->count; $item_count = $at_branch_count + $in_transit_to_count - $in_transit_from_count; + + # artifically adjust counts for the item being checked in + if ($from_branch) { + + # This is the checkin branch - artifically add 1 + if ( $branch eq $branchcode ) { + $item_count++; + } + + # This is where the item came from - artifically subtract 1 + if ( $branch eq $from_branch ) { + $item_count--; + } + } + } else { my $at_branch_count = Koha::Items->search( { @@ -156,6 +171,20 @@ sub lowest_ratio_library { } )->count; $item_count = $at_branch_count + $in_transit_to_count - $in_transit_from_count; + + # artifically adjust counts for the item being checked in + if ($from_branch) { + + # This is the checkin branch - artifically add 1 + if ( $branch eq $branchcode ) { + $item_count++; + } + + # This is where the item came from - artifically subtract 1 + if ( $branch eq $from_branch ) { + $item_count--; + } + } } my $ratio = $item_count / $float_limit_val; -- 2.39.5