Bug 38924 - Introduce an organization level loan 'Quota' system for Koha
Summary: Introduce an organization level loan 'Quota' system for Koha
Status: Needs Signoff
Alias: None
Product: Koha
Classification: Unclassified
Component: Circulation (show other bugs)
Version: Main
Hardware: All All
: P5 - low enhancement
Assignee: Jacob O'Mara
QA Contact: Testopia
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2025-01-19 07:41 UTC by Martin Renvoize (ashimema)
Modified: 2025-02-24 16:31 UTC (History)
3 users (show)

See Also:
Change sponsored?: ---
Patch complexity: ---
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:
Circulation function:


Attachments
Bug 38924: Add patron_quotas table (4.17 KB, patch)
2025-02-24 16:29 UTC, Martin Renvoize (ashimema)
Details | Diff | Splinter Review
Bug 38924: DBIC Schema (4.23 KB, patch)
2025-02-24 16:29 UTC, Martin Renvoize (ashimema)
Details | Diff | Splinter Review
Bug 38924: Add Koha::Patron::Quota(s) classes (5.71 KB, patch)
2025-02-24 16:29 UTC, Martin Renvoize (ashimema)
Details | Diff | Splinter Review
Bug 38924: Add quotas permissions (4.81 KB, patch)
2025-02-24 16:29 UTC, Martin Renvoize (ashimema)
Details | Diff | Splinter Review
Bug 38924: Add API endpoints for managing quotas (12.95 KB, patch)
2025-02-24 16:29 UTC, Martin Renvoize (ashimema)
Details | Diff | Splinter Review
Bug 38924: Add patron quota management page (20.83 KB, patch)
2025-02-24 16:29 UTC, Martin Renvoize (ashimema)
Details | Diff | Splinter Review
Bug 38924: Add patron_quota_usage table (4.34 KB, patch)
2025-02-24 16:29 UTC, Martin Renvoize (ashimema)
Details | Diff | Splinter Review
Bug 38924: DBIC Schema (5.62 KB, patch)
2025-02-24 16:29 UTC, Martin Renvoize (ashimema)
Details | Diff | Splinter Review
Bug 38924: Add Koha::Patron::Quota::Usage(s) classes (4.63 KB, patch)
2025-02-24 16:29 UTC, Martin Renvoize (ashimema)
Details | Diff | Splinter Review
Bug 38924: Overload delete method in Koha::Old::Checkout (1.36 KB, patch)
2025-02-24 16:29 UTC, Martin Renvoize (ashimema)
Details | Diff | Splinter Review
Bug 38924: Add AllowQuotaOverride and UseGuarantorQuota preferences (4.58 KB, patch)
2025-02-24 16:29 UTC, Martin Renvoize (ashimema)
Details | Diff | Splinter Review
Bug 38924: Add get_patron_quotas method (4.06 KB, patch)
2025-02-24 16:29 UTC, Martin Renvoize (ashimema)
Details | Diff | Splinter Review
Bug 38924: Hook quota check and allocation into checkout (3.77 KB, patch)
2025-02-24 16:29 UTC, Martin Renvoize (ashimema)
Details | Diff | Splinter Review
Bug 38924: Hook quota check and allocation into renewals (1.52 KB, patch)
2025-02-24 16:29 UTC, Martin Renvoize (ashimema)
Details | Diff | Splinter Review
Bug 38924: Add quota picker to checkout confirmation (13.39 KB, patch)
2025-02-24 16:29 UTC, Martin Renvoize (ashimema)
Details | Diff | Splinter Review
Bug 38924: Add koha_object_class to Schema files (2.26 KB, patch)
2025-02-24 16:29 UTC, Martin Renvoize (ashimema)
Details | Diff | Splinter Review
Bug 38924: Move from get_patron_quota to Koha::Patron relations (11.53 KB, patch)
2025-02-24 16:29 UTC, Martin Renvoize (ashimema)
Details | Diff | Splinter Review
Bug 38924: Add quotas available on circuation screen (3.72 KB, patch)
2025-02-24 16:29 UTC, Martin Renvoize (ashimema)
Details | Diff | Splinter Review
Bug 38924: Add relations after the hash in DBIC (1.17 KB, patch)
2025-02-24 16:29 UTC, Martin Renvoize (ashimema)
Details | Diff | Splinter Review
Bug 38924: Add type and timestamp to usage table (3.79 KB, patch)
2025-02-24 16:30 UTC, Martin Renvoize (ashimema)
Details | Diff | Splinter Review
Bug 38924: DBIC Dump (1.84 KB, patch)
2025-02-24 16:30 UTC, Martin Renvoize (ashimema)
Details | Diff | Splinter Review
Bug 38924: Add quota accessor to Koha::Checkout and use on checkouts page (1.70 KB, patch)
2025-02-24 16:30 UTC, Martin Renvoize (ashimema)
Details | Diff | Splinter Review
Bug 38924: Display quota used at checkout (2.26 KB, patch)
2025-02-24 16:30 UTC, Martin Renvoize (ashimema)
Details | Diff | Splinter Review
Bug 38924: Add issue and old_issue relations to Schema (2.10 KB, patch)
2025-02-24 16:30 UTC, Martin Renvoize (ashimema)
Details | Diff | Splinter Review
Bug 38924: Add quota usage api endpoint (10.92 KB, patch)
2025-02-24 16:30 UTC, Martin Renvoize (ashimema)
Details | Diff | Splinter Review
Bug 38924: Add quota usage details modal (22.69 KB, patch)
2025-02-24 16:30 UTC, Martin Renvoize (ashimema)
Details | Diff | Splinter Review
Bug 38924: Add option to enable/disable quotas (14.10 KB, patch)
2025-02-24 16:30 UTC, Martin Renvoize (ashimema)
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Renvoize (ashimema) 2025-01-19 07:41:18 UTC
Some libraries work based on the number of allowed issues in a time period as opposed to the number of simultaneous issues.

This enhancement intends to add a per-user, including guarantee/guarantor relations, quota option for setting a fixed number of issues a user is allowed within a specified period.
Comment 1 Martin Renvoize (ashimema) 2025-01-19 07:42:18 UTC
Initial proposed specification: https://docs.google.com/document/d/1YbEuWbt2ELNbFv36T0qlMscofhMI2wwyhjhhLYAM2X8/edit?usp=sharing
Comment 2 Martin Renvoize (ashimema) 2025-02-24 16:29:14 UTC
Created attachment 178582 [details] [review]
Bug 38924: Add patron_quotas table

Add the new patron_quotas table for storing circulation quotas
Comment 3 Martin Renvoize (ashimema) 2025-02-24 16:29:17 UTC
Created attachment 178583 [details] [review]
Bug 38924: DBIC Schema

DBIC update
Comment 4 Martin Renvoize (ashimema) 2025-02-24 16:29:19 UTC
Created attachment 178584 [details] [review]
Bug 38924: Add Koha::Patron::Quota(s) classes

Add initial Koha::Patron::Quota(s) classes for working with circulation
quotas, including an overloaded store method to prevent overlapping
quota periods. Additionally added a definition for the custom exception
for if you are trying to store a quota whos active period overlaps with
another for this patron
Comment 5 Martin Renvoize (ashimema) 2025-02-24 16:29:21 UTC
Created attachment 178585 [details] [review]
Bug 38924: Add quotas permissions

This patch adds the new quotas permissions to the system
Comment 6 Martin Renvoize (ashimema) 2025-02-24 16:29:24 UTC
Created attachment 178586 [details] [review]
Bug 38924: Add API endpoints for managing quotas

This commit adds the api endpoints for administering circulation quotas
Comment 7 Martin Renvoize (ashimema) 2025-02-24 16:29:26 UTC
Created attachment 178587 [details] [review]
Bug 38924: Add patron quota management page

Add a new patron quota management tab under the members area for patrons
of the organization category type.

FIXME: Tie into permissions for 'add', 'edit'

Depending on permissions, we will need display only options including
guarantor and guarantee usage against quotas and also the options to add
and edit quota.
Comment 8 Martin Renvoize (ashimema) 2025-02-24 16:29:29 UTC
Created attachment 178588 [details] [review]
Bug 38924: Add patron_quota_usage table

Add the new patron_quota_usage table for recording usage of quota
allocations against user issues.
Comment 9 Martin Renvoize (ashimema) 2025-02-24 16:29:31 UTC
Created attachment 178589 [details] [review]
Bug 38924: DBIC Schema
Comment 10 Martin Renvoize (ashimema) 2025-02-24 16:29:34 UTC
Created attachment 178590 [details] [review]
Bug 38924: Add Koha::Patron::Quota::Usage(s) classes

Add ::Usage(s) classes for working with quota allocation usage.

We overload store to ensure data consistency for the checkout_id field
which is linked to either the issue or old_issue table appropriatly.

We include a checkout relationship that handles the lack of foreign key
due to issues/old_issues.

We also add the Usage relations to Quota objects
Comment 11 Martin Renvoize (ashimema) 2025-02-24 16:29:37 UTC
Created attachment 178591 [details] [review]
Bug 38924: Overload delete method in Koha::Old::Checkout

This overloads the delete method for old::checkouts to ensure that the
issue_id for quotas usage is nulled in the event that an old_checkout is
deleted.
Would like to make this the standard for all the tables we have had to
handle issue/old_issues for but is currently just hard-coded for quotas
as many of the other tables with issue_id columns are not nullable.
Comment 12 Martin Renvoize (ashimema) 2025-02-24 16:29:39 UTC
Created attachment 178592 [details] [review]
Bug 38924: Add AllowQuotaOverride and UseGuarantorQuota preferences

Add a system preferences to allow/dissallow quota overflow at checkout
and enable/disable the use of guarantor quotas against guarantees
Comment 13 Martin Renvoize (ashimema) 2025-02-24 16:29:41 UTC
Created attachment 178593 [details] [review]
Bug 38924: Add get_patron_quotas method

This commit adds the ability to return the guarantor's quota when
searching for a patron's quota at checkout. This will only occur if the
related syspref is enabled "UseGuaratorQuota" and will return in this
order or priority:
guarantor's quota with availability
patrons's quota with availability
guarantor's quota with no availability
patron's quota with no availibility
null
Comment 14 Martin Renvoize (ashimema) 2025-02-24 16:29:44 UTC
Created attachment 178594 [details] [review]
Bug 38924: Hook quota check and allocation into checkout
Comment 15 Martin Renvoize (ashimema) 2025-02-24 16:29:46 UTC
Created attachment 178595 [details] [review]
Bug 38924: Hook quota check and allocation into renewals

This adds the checks for quotas and allocates a usage for a renewal of a
book, should a quota exist for this patron
Comment 16 Martin Renvoize (ashimema) 2025-02-24 16:29:49 UTC
Created attachment 178596 [details] [review]
Bug 38924: Add quota picker to checkout confirmation

This patch adds the quota selector to the checkout confirmation for if
multiple eligable quotas are available

Bug 38924: Return all eligable quotas so that the staff user can pick

This patch adds the logic to return multiple eligable quotas if there
are more than 1, allowing the staff user to pick which to assign an item
to.

Bug 38924: Add searcher method for currently active quota for patron

Bug 38924: amend circ logic to handle multiple eligable quotas

This amends the circulations logic to handle the fact that we can return
multiple eligable quotas now. This ensures that the same quotas as was
used for the checkout will be used for the renewal (both check and
assignment) and that we use the selected quota from our confirmation
dropdown for checkout of new item

Bug 38924: add better name display for quota select at checkout
Comment 17 Martin Renvoize (ashimema) 2025-02-24 16:29:52 UTC
Created attachment 178597 [details] [review]
Bug 38924: Add koha_object_class to Schema files
Comment 18 Martin Renvoize (ashimema) 2025-02-24 16:29:54 UTC
Created attachment 178598 [details] [review]
Bug 38924: Move from get_patron_quota to Koha::Patron relations

Bug 38924: Deal with multiple quota options in QUOTA_EXCEEDED handling

Bug 38924: Deal with using the same quota for renewals
Comment 19 Martin Renvoize (ashimema) 2025-02-24 16:29:57 UTC
Created attachment 178599 [details] [review]
Bug 38924: Add quotas available on circuation screen
Comment 20 Martin Renvoize (ashimema) 2025-02-24 16:29:59 UTC
Created attachment 178600 [details] [review]
Bug 38924: Add relations after the hash in DBIC

This adds additional relations to our DBIC classes to allow relation
traversal in our Koha::Objects
Comment 21 Martin Renvoize (ashimema) 2025-02-24 16:30:02 UTC
Created attachment 178601 [details] [review]
Bug 38924: Add type and timestamp to usage table

This allows us to more easily audit what actions incremented the usage
and when.

We will use this later in display
Comment 22 Martin Renvoize (ashimema) 2025-02-24 16:30:04 UTC
Created attachment 178602 [details] [review]
Bug 38924: DBIC Dump
Comment 23 Martin Renvoize (ashimema) 2025-02-24 16:30:07 UTC
Created attachment 178603 [details] [review]
Bug 38924: Add quota accessor to Koha::Checkout and use on checkouts page
Comment 24 Martin Renvoize (ashimema) 2025-02-24 16:30:09 UTC
Created attachment 178604 [details] [review]
Bug 38924: Display quota used at checkout

Use the quota relation added to Koha::Checkout to display an info alert
message that quota allocation has been used by the checkout that just
took place
Comment 25 Martin Renvoize (ashimema) 2025-02-24 16:30:12 UTC
Created attachment 178605 [details] [review]
Bug 38924: Add issue and old_issue relations to Schema
Comment 26 Martin Renvoize (ashimema) 2025-02-24 16:30:15 UTC
Created attachment 178606 [details] [review]
Bug 38924: Add quota usage api endpoint
Comment 27 Martin Renvoize (ashimema) 2025-02-24 16:30:17 UTC
Created attachment 178607 [details] [review]
Bug 38924: Add quota usage details modal
Comment 28 Martin Renvoize (ashimema) 2025-02-24 16:30:20 UTC
Created attachment 178608 [details] [review]
Bug 38924: Add option to enable/disable quotas
Comment 29 Martin Renvoize (ashimema) 2025-02-24 16:31:31 UTC
This was a team effort between Jacob and I