Bugzilla – Attachment 182931 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: Use DBIC query and return library object
Bug-28530-Use-DBIC-query-and-return-library-object.patch (text/plain), 5.08 KB, created by
Lucas Gass (lukeg)
on 2025-06-03 23:21:32 UTC
(
hide
)
Description:
Bug 28530: Use DBIC query and return library object
Filename:
MIME Type:
Creator:
Lucas Gass (lukeg)
Created:
2025-06-03 23:21:32 UTC
Size:
5.08 KB
patch
obsolete
>From 7f1b4cd8fa28ee2c09e5f95dffed7073f854a815 Mon Sep 17 00:00:00 2001 >From: Lucas Gass <lucas@bywatersolutions.com> >Date: Tue, 3 Jun 2025 23:19:10 +0000 >Subject: [PATCH] Bug 28530: Use DBIC query and return library object > >--- > C4/Circulation.pm | 6 +-- > Koha/Library/FloatLimits.pm | 76 ++++++++++++++++++++++++++----------- > 2 files changed, 57 insertions(+), 25 deletions(-) > >diff --git a/C4/Circulation.pm b/C4/Circulation.pm >index 0b2d2adad20..d6f86c7e276 100644 >--- a/C4/Circulation.pm >+++ b/C4/Circulation.pm >@@ -2272,9 +2272,9 @@ sub AddReturn { > if ($limit) { > my $count = Koha::Items->count( { itype => $limit->itemtype, holdingbranch => $branch } ); > if ( $count >= $limit->float_limit ) { >- my $transfer_branchcode = Koha::Library::FloatLimits->lowest_ratio_library( $item, $branch ); >- if ( $transfer_branchcode ne $branch ) { >- $returnbranch = $transfer_branchcode; >+ my $transfer_library = Koha::Library::FloatLimits->lowest_ratio_library( $item, $branch ); >+ if ( $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 5697b38b1c5..611b9eb4437 100644 >--- a/Koha/Library/FloatLimits.pm >+++ b/Koha/Library/FloatLimits.pm >@@ -24,6 +24,7 @@ use Modern::Perl; > use Koha::Database; > > use Koha::Library::FloatLimit; >+use Koha::Libraries; > use C4::Circulation qw(IsBranchTransferAllowed); > > use base qw(Koha::Objects); >@@ -43,40 +44,71 @@ Koha::Library::FloatLimits - Koha Library::FloatLimit object set class > sub lowest_ratio_library { > my ( $self, $item, $branchcode ) = @_; > >- my $field = C4::Context->preference('item-level_itypes') ? 'items.itype' : 'biblioitems.itemtype'; >- my $query = qq{ >- SELECT branchcode >- FROM library_float_limits >- LEFT JOIN items ON ( items.itype = library_float_limits.itemtype AND items.holdingbranch = library_float_limits.branchcode ) >- LEFT JOIN biblioitems ON ( items.biblioitemnumber = biblioitems.biblioitemnumber ) >- WHERE library_float_limits.itemtype = ? >- AND ( $field = ? OR $field IS NULL ) >- AND library_float_limits.float_limit != 0 >- GROUP BY branchcode >- ORDER BY COUNT(items.holdingbranch)/library_float_limits.float_limit ASC, library_float_limits.float_limit DESC; >- }; >- >- my $results = C4::Context->dbh->selectall_arrayref( >- $query, { Slice => {} }, $item->effective_itemtype, >- $item->effective_itemtype >- ); >+ my $schema = Koha::Database->new->schema; >+ >+ my @float_limits = $schema->resultset('LibraryFloatLimit')->search( >+ { >+ itemtype => $item->effective_itemtype, >+ float_limit => { '!=' => 0 } >+ } >+ )->all; >+ >+ return unless @float_limits; >+ >+ my @candidates; >+ my $use_item_level = C4::Context->preference('item-level_itypes'); >+ >+ foreach my $limit (@float_limits) { >+ my $branch = $limit->get_column('branchcode'); >+ my $float_limit_val = $limit->get_column('float_limit'); >+ >+ my $item_count; >+ >+ if ($use_item_level) { >+ $item_count = Koha::Items->search( >+ { >+ itype => $item->effective_itemtype, >+ holdingbranch => $branch >+ } >+ )->count; >+ } else { >+ $item_count = Koha::Items->search( >+ { >+ holdingbranch => $branch, >+ 'biblioitem.itemtype' => $item->effective_itemtype >+ }, >+ { join => 'biblioitem' } >+ )->count; >+ } >+ >+ my $ratio = $item_count / $float_limit_val; >+ push @candidates, { >+ branchcode => $branch, >+ ratio => $ratio, >+ float_limit => $float_limit_val >+ }; >+ } >+ >+ @candidates = sort { $a->{ratio} <=> $b->{ratio} || $b->{float_limit} <=> $a->{float_limit} } @candidates; > > my $UseBranchTransferLimits = C4::Context->preference("UseBranchTransferLimits"); > my $BranchTransferLimitsType = > C4::Context->preference("BranchTransferLimitsType") eq 'itemtype' ? 'effective_itemtype' : 'ccode'; > >- foreach my $r (@$results) { >+ for my $candidate (@candidates) { > if ($UseBranchTransferLimits) { > my $allowed = C4::Circulation::IsBranchTransferAllowed( >- $r->{branchcode}, # to >- $branchcode, # from >+ $candidate->{branchcode}, >+ $branchcode, > $item->$BranchTransferLimitsType > ); >- return $r->{branchcode} if $allowed; >+ return Koha::Libraries->find( $candidate->{branchcode} ) if $allowed; > } else { >- return $r->{branchcode}; >+ return Koha::Libraries->find( $candidate->{branchcode} ); > } > } >+ >+ return; > } > > =head3 _type >-- >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