From a4050b46d7f21efc63c59acaab4169ace48c3144 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Mon, 18 Dec 2023 14:21:57 -0500 Subject: [PATCH] Bug 28530: Implement float limits Test Plan: 1) Apply this patch set 2) Run updatedatabase.pl 3) Restart all the things! 4) Enable UseLibraryFloatLimits 5) Verify items float correctly as per your circulation rules 6) Set some float limits from the Library Float Limits configuration page in the Administration section The simplest solution is to set the float limit from one branch to 1 item, a second to 100 items, and a third to 300 items for a single itemtype 7) Verify checked in items that should have floated at this branch are now transfered to the branch with the best float ratio Signed-off-by: Andrew Fuerste-Henry --- C4/Circulation.pm | 17 ++++++++++ circ/returns.pl | 31 +++++++++++++------ .../prog/en/modules/admin/admin-home.tt | 2 ++ .../prog/en/modules/circ/returns.tt | 3 +- 4 files changed, 43 insertions(+), 10 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index 8ad7cfa08c2..80e041752b8 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -50,6 +50,7 @@ use Koha::Patrons; use Koha::Patron::Debarments qw( DelUniqueDebarment AddUniqueDebarment ); use Koha::Database; use Koha::Libraries; +use Koha::Library::FloatLimits; use Koha::Account::Lines; use Koha::Holds; use Koha::Account::Lines; @@ -2199,6 +2200,22 @@ sub AddReturn { # if $hbr was "noreturn" or any other non-item table value, then it should 'float' (i.e. stay at this branch) my $transfer_trigger = $hbr eq 'homebranch' ? 'ReturnToHome' : $hbr eq 'holdingbranch' ? 'ReturnToHolding' : undef; + # check library float limits if enabled if the item isn't being transferred away + if ( ( $returnbranch eq $branch ) && C4::Context->preference('UseLibraryFloatLimits') ) { + 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 } ); + if ( $count >= $limit->float_limit ) { + my $transfer_branchcode = Koha::Library::FloatLimits->lowest_ratio_library( $item, $branch ); + if ( $transfer_branchcode ne $branch ) { + $returnbranch = $transfer_branchcode; + $transfer_trigger = 'LibraryFloatLimit'; + } + } + } + } + my $borrowernumber = $patron ? $patron->borrowernumber : undef; # we don't know if we had a borrower or not my $patron_unblessed = $patron ? $patron->unblessed : {}; diff --git a/circ/returns.pl b/circ/returns.pl index 019d8e36c84..2f606b3b864 100755 --- a/circ/returns.pl +++ b/circ/returns.pl @@ -331,7 +331,6 @@ if ($barcode && $op eq 'cud-checkin') { my $biblio = $item->biblio; $template->param( title => $biblio->title, - returnbranch => $returnbranch, author => $biblio->author, itembiblionumber => $biblio->biblionumber, biblionumber => $biblio->biblionumber, @@ -451,6 +450,8 @@ if ($barcode && $op eq 'cud-checkin') { ); } + $returnbranch = $messages->{NeedsTransfer} if $messages->{NeedsTransfer}; + # Mark missing bundle items as lost and report unexpected items if ( $item && $item->is_bundle && $query->param('confirm_items_bundle_return') && !$query->param('do_not_verify_items_bundle_contents') ) { my $BundleLostValue = C4::Context->preference('BundleLostValue'); @@ -538,6 +539,13 @@ my $recalled = 0; # new op dev : we check if the document must be returned to his homebranch directly, # if the document is transferred, we have warning message . +if ( $messages->{'LibraryFloatLimitTransferRequest'} ) { + $template->param( + LibraryFloatLimitTransferRequest => 1, + itemnumber => $itemnumber, + ); +} + if ( $messages->{'WasTransfered'} ) { $template->param( found => 1, @@ -771,6 +779,8 @@ foreach my $code ( keys %$messages ) { ; } elsif ( $code eq 'TransferredRecall' ) { ; + } elsif ( $code eq 'LibraryFloatLimitTransferRequest' ) { + ; } elsif ( $code eq 'InBundle' ) { $template->param( InBundle => $messages->{InBundle} ); } else { @@ -854,14 +864,14 @@ foreach ( sort { $a <=> $b } keys %returneditems ) { } $template->param( - riloop => \@riloop, - errmsgloop => \@errmsgloop, - exemptfine => $exemptfine, - dropboxmode => $dropboxmode, - dropboxdate => $dropboxdate, + riloop => \@riloop, + errmsgloop => \@errmsgloop, + exemptfine => $exemptfine, + dropboxmode => $dropboxmode, + dropboxdate => $dropboxdate, forgivemanualholdsexpire => $forgivemanualholdsexpire, - overduecharges => $overduecharges, - AudioAlerts => C4::Context->preference("AudioAlerts"), + overduecharges => $overduecharges, + AudioAlerts => C4::Context->preference("AudioAlerts"), ); if ( $barcode ) { @@ -882,7 +892,10 @@ if ( $barcode ) { } } -$template->param( itemnumber => $itemnumber ); +$template->param( + itemnumber => $itemnumber, + returnbranch => $returnbranch, +); # Checking if there is a Fast Cataloging Framework $template->param( fast_cataloging => 1 ) if Koha::BiblioFrameworks->find( 'FA' ); diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/admin-home.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/admin-home.tt index 000f4f0956a..981ffaf17bd 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/admin-home.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/admin-home.tt @@ -108,6 +108,8 @@
Limit the ability to transfer items between libraries based on the library sending, the library receiving, and the item type involved. These rules only go into effect if the preference UseBranchTransferLimits is set to ON
Transport cost matrix
Define transport costs between branches
+
Library float limits
+
Define when items should be transferred to other libraries on checkin to balance floating collections
[% END %] [% IF ( CAN_user_parameters_manage_item_circ_alerts ) %]
Item circulation alerts
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/returns.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/returns.tt index 7091e5ef8e7..bcb8c199834 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/returns.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/returns.tt @@ -127,6 +127,7 @@

Reason for transfer

[%- SWITCH trigger -%] + [%- CASE 'LibraryFloatLimit' -%]Library has exceeded float limit for this item type [%- CASE 'Manual' -%]Manual [%- CASE 'StockrotationAdvance' -%]Stock rotation advance [%- CASE 'StockrotationRepatriation' -%]Stock rotation repatriation @@ -754,7 +755,7 @@