Bugzilla – Attachment 193567 Details for
Bug 38924
Introduce an organization level loan 'Quota' system for Koha
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 38924: Add option to enable/disable quotas
Bug-38924-Add-option-to-enabledisable-quotas.patch (text/plain), 14.11 KB, created by
Jacob O'Mara
on 2026-02-20 13:41:06 UTC
(
hide
)
Description:
Bug 38924: Add option to enable/disable quotas
Filename:
MIME Type:
Creator:
Jacob O'Mara
Created:
2026-02-20 13:41:06 UTC
Size:
14.11 KB
patch
obsolete
>From 455164c4caa49a38322678bc1191a5f27a151c79 Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@ptfs-europe.com> >Date: Tue, 11 Feb 2025 14:14:09 +0000 >Subject: [PATCH] Bug 38924: Add option to enable/disable quotas > >--- > C4/Circulation.pm | 113 ++++++++++-------- > .../atomicupdate/bug_38924-patron_quotas.pl | 28 +++-- > installer/data/mysql/mandatory/sysprefs.sql | 1 + > .../prog/en/includes/circ-menu.inc | 10 +- > .../admin/preferences/circulation.pref | 31 +++-- > 5 files changed, 107 insertions(+), 76 deletions(-) > >diff --git a/C4/Circulation.pm b/C4/Circulation.pm >index f38d6973a54..632f43e586a 100644 >--- a/C4/Circulation.pm >+++ b/C4/Circulation.pm >@@ -1376,26 +1376,28 @@ sub CanBookBeIssued { > } > > # CHECK FOR QUOTAS >- if ( my $quotas = $patron->all_quotas->filter_by_active ) { >- if ( $quotas->count > 1 ) { >- >- # Multiple available quotas found - need confirmation from user >- $needsconfirmation{QUOTA_SELECT} = $quotas; >- } elsif ( $quotas->count == 1 ) { >- my $quota = $quotas->next; >- if ( !$quota->has_available_quota ) { >- if ( C4::Context->preference("AllowQuotaOverride") ) { >- $needsconfirmation{QUOTA_EXCEEDED} = { >- available => $quota->available_quota, >- total => $quota->allocation, >- used => $quota->used, >- }; >- } else { >- $issuingimpossible{QUOTA_EXCEEDED} = { >- available => $quota->available_quota, >- total => $quota->allocation, >- used => $quota->used, >- }; >+ if ( C4::Context->preference('EnableCirculationQuotas') ) { >+ if ( my $quotas = $patron->all_quotas->filter_by_active ) { >+ if ( $quotas->count > 1 ) { >+ >+ # Multiple available quotas found - need confirmation from user >+ $needsconfirmation{QUOTA_SELECT} = $quotas; >+ } elsif ( $quotas->count == 1 ) { >+ my $quota = $quotas->next; >+ if ( !$quota->has_available_quota ) { >+ if ( C4::Context->preference("AllowQuotaOverride") ) { >+ $needsconfirmation{QUOTA_EXCEEDED} = { >+ available => $quota->available_quota, >+ total => $quota->allocation, >+ used => $quota->used, >+ }; >+ } else { >+ $issuingimpossible{QUOTA_EXCEEDED} = { >+ available => $quota->available_quota, >+ total => $quota->allocation, >+ used => $quota->used, >+ }; >+ } > } > } > } >@@ -2031,19 +2033,24 @@ sub AddIssue { > if C4::Context->preference('RealTimeHoldsQueue'); > > # Check quotas and record usage if needed >- my $quota; >- if ($selected_quota_id) { >- $quota = Koha::Patron::Quotas->find($selected_quota_id); >- } else { >- $quota = $patron->all_quotas->filter_by_active->single; >- } >+ if ( C4::Context->preference('EnableCirculationQuotas') ) { >+ my $quota; >+ if ($selected_quota_id) { >+ $quota = Koha::Patron::Quotas->find($selected_quota_id); >+ } else { >+ $quota = $patron->all_quotas->filter_by_active->single; >+ } >+ >+ if ($quota) { > >- if ($quota) { >- # Update patron's used quota value >- $quota->add_usage({ >- patron_id => $patron->patron_id, >- issue_id => $issue->issue_id, >- }); >+ # Update patron's used quota value >+ $quota->add_usage( >+ { >+ patron_id => $patron->borrowernumber, >+ issue_id => $issue->issue_id, >+ } >+ ); >+ } > } > } > } >@@ -3418,18 +3425,20 @@ sub CanBookBeRenewed { > } > } > >- # # CHECK FOR QUOTAS >- if ( my $quota_usage = Koha::Patron::Quota::Usages->find( { issue_id => $issue->issue_id } ) ) { >+ # # CHECK FOR QUOTAS >+ if ( C4::Context->preference('EnableCirculationQuotas') ) { >+ if ( my $quota_usage = Koha::Patron::Quota::Usages->find( { issue_id => $issue->issue_id } ) ) { > >- # Get current actives quota for the patron >- if ( my $active_quotas = $patron->all_quotas->filter_by_active ) { >- my $all_exceeded = 1; >- while ( my $active_quota = $active_quotas->next ) { >- if ( $active_quota->has_available_quota ) { >- $all_exceeded = 0; >+ # Get current actives quota for the patron >+ if ( my $active_quotas = $patron->all_quotas->filter_by_active ) { >+ my $all_exceeded = 1; >+ while ( my $active_quota = $active_quotas->next ) { >+ if ( $active_quota->has_available_quota ) { >+ $all_exceeded = 0; >+ } > } >+ return ( 0, "QUOTA_EXCEEDED" ) if $all_exceeded; > } >- return ( 0, "QUOTA_EXCEEDED" ) if $all_exceeded; > } > } > >@@ -3548,14 +3557,20 @@ sub AddRenewal { > my $circ_library = Koha::Libraries->find( _GetCircControlBranch( $item_object, $patron ) ); > > # Check quotas and record usage if needed >- if (my $quota_usage = Koha::Patron::Quota::Usages->find({ issue_id => $issue->issue_id })) { >- # Get current active quota for the patron >- if (my $active_quota = Koha::Patron::Quotas->find($quota_usage->patron_quota_id)) { >- # Update patron's used quota value >- $active_quota->add_usage({ >- patron_id => $patron->borrowernumber, >- issue_id => $issue->issue_id, >- }); >+ if ( C4::Context->preference('EnableCirculationQuotas') ) { >+ if ( my $quota_usage = Koha::Patron::Quota::Usages->find( { issue_id => $issue->issue_id } ) ) { >+ >+ # Get current active quota for the patron >+ if ( my $active_quota = Koha::Patron::Quotas->find( $quota_usage->patron_quota_id ) ) { >+ >+ # Update patron's used quota value >+ $active_quota->add_usage( >+ { >+ patron_id => $patron->borrowernumber, >+ issue_id => $issue->issue_id, >+ } >+ ); >+ } > } > } > >diff --git a/installer/data/mysql/atomicupdate/bug_38924-patron_quotas.pl b/installer/data/mysql/atomicupdate/bug_38924-patron_quotas.pl >index 7c1ae600b1a..67fea327011 100755 >--- a/installer/data/mysql/atomicupdate/bug_38924-patron_quotas.pl >+++ b/installer/data/mysql/atomicupdate/bug_38924-patron_quotas.pl >@@ -25,21 +25,23 @@ return { > ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; > } > ); >- >- $dbh->do(q{ >+ >+ $dbh->do( >+ q{ > INSERT IGNORE INTO permissions (module_bit, code, description) VALUES > (4, 'manage_borrower_quotas', 'Manage patron quotas'), > (4, 'view_borrower_quotas', 'View patron quotas') >- }); >- >+ } >+ ); >+ > say_success( $out, "Patron quota table and permissions created successfully" ); > } else { > say_info( $out, "Patron quota table already exists" ); > } > >- unless ( TableExists('patron_quota_usage') ) >- { >- $dbh->do(q{ >+ unless ( TableExists('patron_quota_usage') ) { >+ $dbh->do( >+ q{ > CREATE TABLE `patron_quota_usage` ( > `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'unique identifier for quota usage record', > `patron_quota_id` int(11) NOT NULL COMMENT 'foreign key linking to patron_quota.id', >@@ -54,19 +56,23 @@ return { > CONSTRAINT `patron_quota_usage_ibfk_1` FOREIGN KEY (`patron_quota_id`) REFERENCES `patron_quota` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, > CONSTRAINT `patron_quota_usage_ibfk_2` FOREIGN KEY (`patron_id`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE > ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; >- }); >+ } >+ ); > > say_success( $out, "Patron quota usage table created successfully" ); > } else { > say_info( $out, "Patron quota usage table already exists" ); > } > >- $dbh->do(q{ >+ $dbh->do( >+ q{ > INSERT IGNORE INTO systempreferences (variable, value, options, explanation, type) > VALUES > ('AllowQuotaOverride', '0', NULL, 'Allow staff to override and check out items to patrons who have exceeded their quota limit', 'YesNo'), >- ('UseGuarantorQuota', '0', NULL, 'Use guarantor quota instead of guarantee quota when checking out items', 'YesNo') >- }); >+ ('UseGuarantorQuota', '0', NULL, 'Use guarantor quota instead of guarantee quota when checking out items', 'YesNo'), >+ ('EnableCirculationQuotas','0','','Enable or disable the circulation quotas feature','YesNo') >+ } >+ ); > > say_success( $out, "Patron quota preferences added successfully" ); > }, >diff --git a/installer/data/mysql/mandatory/sysprefs.sql b/installer/data/mysql/mandatory/sysprefs.sql >index 254268e1d20..a8630be3454 100644 >--- a/installer/data/mysql/mandatory/sysprefs.sql >+++ b/installer/data/mysql/mandatory/sysprefs.sql >@@ -261,6 +261,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` > ('EnableAdvancedCatalogingEditor','0',NULL,'Enable the Rancor advanced cataloging editor','YesNo'), > ('EnableBooking','1',NULL,'If enabled, activate every functionalities related with Bookings module','YesNo'), > ('EnableBorrowerFiles','0',NULL,'If enabled, allows librarians to upload and attach arbitrary files to a borrower record.','YesNo'), >+('EnableCirculationQuotas','0','','Enable or disable the circulation quotas feature','YesNo'), > ('EnableExpiredPasswordReset', '0', NULL, 'Enable ability for patrons with expired password to reset their password directly', 'YesNo'), > ('EnableItemGroupHolds','0',NULL,'Enable item groups holds feature','YesNo'), > ('EnableItemGroups','0',NULL,'Enable the item groups feature','YesNo'), >diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/circ-menu.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/circ-menu.inc >index 2f0d1ca0fc2..4e72d08b5f5 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/includes/circ-menu.inc >+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/circ-menu.inc >@@ -211,10 +211,12 @@ > <a href="/cgi-bin/koha/members/holdshistory.pl?borrowernumber=[% patron.borrowernumber | uri %]">Holds history</a> > </li> > [% END %] >- [% IF patron.category.category_type == 'I' %] >- <li [% IF ( quotaview ) %]class="active"[% END %]> >- <a href="/cgi-bin/koha/members/circulation_quota.pl?borrowernumber=[% patron.borrowernumber | uri %]">Circulation quota</a> >- </li> >+ [% IF Koha.Preference('EnableCirculationQuotas') %] >+ [% IF patron.category.category_type == 'I' %] >+ <li [% IF ( quotaview ) %]class="active"[% END %]> >+ <a href="/cgi-bin/koha/members/circulation_quota.pl?borrowernumber=[% patron.borrowernumber | uri %]">Circulation quota</a> >+ </li> >+ [% END %] > [% END %] > [% IF ( CAN_user_tools_view_system_logs ) %] > <li [% IF logview %]class="active"[% END %]> >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref >index 7d92e725006..f46d99f7fbd 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref >@@ -402,18 +402,6 @@ Circulation: > 1: Allow > 0: "Don't allow" > - staff to check out an item with age restriction. >- - >- - pref: AllowQuotaOverride >- choices: >- 1: "Allow" >- 0: "Don't allow" >- - staff to check out items to patrons who have exceeded their quota limit. >- - >- - pref: UseGuarantorQuota >- choices: >- 1: "Use" >- 0: "Don't use" >- - guarantor's quota instead of guarantee's quota when checking out items if guarantor has an active quota and quota has enough availability. > - > - Prevent patrons from checking out items if they have more than > - pref: noissuescharge >@@ -1380,6 +1368,25 @@ Circulation: > - pref: SCOBatchCheckoutsValidCategories > choices: patron-categories > class: multiple >+ Quotas: >+ - >+ - pref: EnableCirculationQuotas >+ choices: >+ 1: "Enable" >+ 0: "Disable" >+ - circulation quotas for patrons. >+ - >+ - pref: AllowQuotaOverride >+ choices: >+ 1: "Allow" >+ 0: "Don't allow" >+ - staff to check out items to patrons who have exceeded their quota limit. >+ - >+ - pref: UseGuarantorQuota >+ choices: >+ 1: "Use" >+ 0: "Don't use" >+ - guarantor's quota instead of guarantee's quota when checking out items if guarantor has an active quota and quota has enough availability. > Course reserves: > - > - pref: UseCourseReserves >-- >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 38924
:
178582
|
178583
|
178584
|
178585
|
178586
|
178587
|
178588
|
178589
|
178590
|
178591
|
178592
|
178593
|
178594
|
178595
|
178596
|
178597
|
178598
|
178599
|
178600
|
178601
|
178602
|
178603
|
178604
|
178605
|
178606
|
178607
|
178608
|
185631
|
185632
|
185633
|
185634
|
185635
|
185636
|
185637
|
185638
|
185639
|
185640
|
185641
|
185642
|
185643
|
185644
|
185645
|
185646
|
185647
|
185648
|
185649
|
185650
|
185651
|
185652
|
185653
|
185654
|
185655
|
185656
|
185657
|
185675
|
185676
|
185677
|
185678
|
185679
|
185680
|
185681
|
185682
|
185683
|
185684
|
185685
|
185686
|
185687
|
185688
|
185689
|
185690
|
185691
|
185692
|
185693
|
185694
|
185695
|
185696
|
185697
|
185698
|
185699
|
185700
|
185701
|
185702
|
189266
|
189267
|
189268
|
189269
|
189270
|
189271
|
189272
|
189273
|
189274
|
189275
|
189276
|
189277
|
189278
|
189279
|
189280
|
189281
|
189282
|
189283
|
189284
|
189285
|
189286
|
189287
|
189288
|
189289
|
189290
|
189291
|
189292
|
193377
|
193378
|
193379
|
193380
|
193381
|
193382
|
193383
|
193384
|
193385
|
193386
|
193387
|
193388
|
193389
|
193390
|
193391
|
193392
|
193393
|
193394
|
193395
|
193396
|
193397
|
193398
|
193399
|
193400
|
193401
|
193402
|
193403
|
193404
|
193405
|
193406
|
193407
|
193408
|
193409
|
193410
|
193411
|
193412
|
193413
|
193414
|
193415
|
193416
|
193417
|
193418
|
193419
|
193420
|
193421
|
193422
|
193423
|
193424
|
193425
|
193426
|
193427
|
193428
|
193429
|
193430
|
193431
|
193432
|
193433
|
193434
|
193435
|
193436
|
193437
|
193438
|
193439
|
193440
|
193441
|
193442
|
193443
|
193444
|
193445
|
193446
|
193447
|
193448
|
193449
|
193450
|
193451
|
193452
|
193453
|
193454
|
193455
|
193456
|
193457
|
193458
|
193459
|
193460
|
193547
|
193548
|
193549
|
193550
|
193551
|
193552
|
193553
|
193554
|
193555
|
193556
|
193557
|
193558
|
193559
|
193560
|
193561
|
193562
|
193563
|
193564
|
193565
|
193566
| 193567 |
193568
|
193569
|
193570
|
193571
|
193572
|
193573
|
193574
|
193575
|
193576
|
193577