Bug 38924

Summary: Introduce an organization level loan 'Quota' system for Koha
Product: Koha Reporter: Martin Renvoize (ashimema) <martin.renvoize>
Component: CirculationAssignee: Jacob O'Mara <jacob.omara>
Status: Signed Off --- QA Contact: Testopia <testopia>
Severity: enhancement    
Priority: P5 - low CC: dcook, gmcharlt, kyle, sally.healey, victor
Version: Main   
Hardware: All   
OS: All   
GIT URL: Initiative type: ---
Sponsorship status: --- Comma delimited list of Sponsors:
Crowdfunding goal: 0 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
Bug 38924: DBIC Schema
Bug 38924: Add Koha::Patron::Quota(s) classes
Bug 38924: Add quotas permissions
Bug 38924: Add API endpoints for managing quotas
Bug 38924: Add patron quota management page
Bug 38924: Add patron_quota_usage table
Bug 38924: DBIC Schema
Bug 38924: Add Koha::Patron::Quota::Usage(s) classes
Bug 38924: Overload delete method in Koha::Old::Checkout
Bug 38924: Add AllowQuotaOverride and UseGuarantorQuota preferences
Bug 38924: Add get_patron_quotas method
Bug 38924: Hook quota check and allocation into checkout
Bug 38924: Hook quota check and allocation into renewals
Bug 38924: Add quota picker to checkout confirmation
Bug 38924: Add koha_object_class to Schema files
Bug 38924: Move from get_patron_quota to Koha::Patron relations
Bug 38924: Add quotas available on circuation screen
Bug 38924: Add relations after the hash in DBIC
Bug 38924: Add type and timestamp to usage table
Bug 38924: DBIC Dump
Bug 38924: Add quota accessor to Koha::Checkout and use on checkouts page
Bug 38924: Display quota used at checkout
Bug 38924: Add issue and old_issue relations to Schema
Bug 38924: Add quota usage api endpoint
Bug 38924: Add quota usage details modal
Bug 38924: Add option to enable/disable quotas
Bug 38924: Add patron_quotas table
Bug 38924: DBIC Schema
Bug 38924: Add Koha::Patron::Quota(s) classes
Bug 38924: Add quotas permissions
Bug 38924: Add API endpoints for managing quotas
Bug 38924: Add patron quota management page
Bug 38924: Add patron_quota_usage table
Bug 38924: DBIC Schema
Bug 38924: Add Koha::Patron::Quota::Usage(s) classes
Bug 38924: Overload delete method in Koha::Old::Checkout
Bug 38924: Add AllowQuotaOverride and UseGuarantorQuota preferences
Bug 38924: Add get_patron_quotas method
Bug 38924: Hook quota check and allocation into checkout
Bug 38924: Hook quota check and allocation into renewals
Bug 38924: Add quota picker to checkout confirmation
Bug 38924: Add koha_object_class to Schema files
Bug 38924: Move from get_patron_quota to Koha::Patron relations
Bug 38924: Add quotas available on circuation screen
Bug 38924: Add relations after the hash in DBIC
Bug 38924: Add type and timestamp to usage table
Bug 38924: DBIC Dump
Bug 38924: Add quota accessor to Koha::Checkout and use on checkouts page
Bug 38924: Display quota used at checkout
Bug 38924: Add issue and old_issue relations to Schema
Bug 38924: Add quota usage api endpoint
Bug 38924: Add quota usage details modal
Bug 38924: Add option to enable/disable quotas
Bug 38924: Add patron_quotas table
Bug 38924: DBIC Schema
Bug 38924: Add Koha::Patron::Quota(s) classes
Bug 38924: Add quotas permissions
Bug 38924: Add API endpoints for managing quotas
Bug 38924: Add patron quota management page
Bug 38924: Add patron_quota_usage table
Bug 38924: DBIC Schema
Bug 38924: Add Koha::Patron::Quota::Usage(s) classes
Bug 38924: Overload delete method in Koha::Old::Checkout
Bug 38924: Add AllowQuotaOverride and UseGuarantorQuota preferences
Bug 38924: Add get_patron_quotas method
Bug 38924: Hook quota check and allocation into checkout
Bug 38924: Hook quota check and allocation into renewals
Bug 38924: Add quota picker to checkout confirmation
Bug 38924: Add koha_object_class to Schema files
Bug 38924: Move from get_patron_quota to Koha::Patron relations
Bug 38924: Add quotas available on circuation screen
Bug 38924: Add relations after the hash in DBIC
Bug 38924: Add type and timestamp to usage table
Bug 38924: DBIC Dump
Bug 38924: Add quota accessor to Koha::Checkout and use on checkouts page
Bug 38924: Display quota used at checkout
Bug 38924: Add issue and old_issue relations to Schema
Bug 38924: Add quota usage api endpoint
Bug 38924: Add quota usage details modal
Bug 38924: Add option to enable/disable quotas
Bug 38924: Remove duplicate sub
Bug 38924: Add patron_quotas table
Bug 38924: Add Koha::Patron::Quota(s) classes
Bug 38924: Add quotas permissions
Bug 38924: Add API endpoints for managing quotas
Bug 38924: Add patron quota management page
Bug 38924: Add patron_quota_usage table
Bug 38924: Add Koha::Patron::Quota::Usage(s) classes
Bug 38924: Overload delete method in Koha::Old::Checkout
Bug 38924: Add Usage relations to Quota objects
Bug 38924: Add AllowQuotaOverride and UseGuarantorQuota preferences
Bug 38924: Add get_patron_quotas method
Bug 38924: Hook quota check and allocation into checkout
Bug 38924: Hook quota check and allocation into renewals
Bug 38924: Add quota picker to checkout confirmation
Bug 38924: Move from get_patron_quota to Koha::Patron relations
Bug 38924: Add quotas available on circuation screen
Bug 38924: Add type and timestamp to usage table
Bug 38924: Add quota accessor to Koha::Checkout and use on checkouts page
Bug 38924: Display quota used at checkout
Bug 38924: Add quota usage details modal
Bug 38924: Add option to enable/disable quotas
Bug 38924: DBIC - DO NOT PUSH
Bug 38924: Add relations after the hash in DBIC
Bug 38924: Add issue and old_issue relations to Schema
Bug 38924: Add koha_object_class to Schema files
Bug 38924: Add quota usage api endpoint
Bug 38924: (follow-up) Minor QOL quota modal fixes
Bug 38924: Add patron_quotas table
Bug 38924: Add Koha::Patron::Quota(s) classes
Bug 38924: Add quotas permissions
Bug 38924: Add API endpoints for managing quotas
Bug 38924: Add patron quota management page
Bug 38924: Add patron_quota_usage table
Bug 38924: Add Koha::Patron::Quota::Usage(s) classes
Bug 38924: Overload delete method in Koha::Old::Checkout
Bug 38924: Add Usage relations to Quota objects
Bug 38924: Add AllowQuotaOverride and UseGuarantorQuota preferences
Bug 38924: Add get_patron_quotas method
Bug 38924: Hook quota check and allocation into checkout
Bug 38924: Hook quota check and allocation into renewals
Bug 38924: Add quota picker to checkout confirmation
Bug 38924: Move from get_patron_quota to Koha::Patron relations
Bug 38924: Add quotas available on circuation screen
Bug 38924: Add type and timestamp to usage table
Bug 38924: Add quota accessor to Koha::Checkout and use on checkouts page
Bug 38924: Display quota used at checkout
Bug 38924: Add quota usage details modal
Bug 38924: Add option to enable/disable quotas
Bug 38924: Add patron_quotas table
Bug 38924: Add Koha::Patron::Quota(s) classes
Bug 38924: Add quotas permissions
Bug 38924: Add API endpoints for managing quotas
Bug 38924: Add patron quota management page
Bug 38924: Add patron_quotas table
Bug 38924: Add Koha::Patron::Quota(s) classes
Bug 38924: Add quotas permissions
Bug 38924: Add API endpoints for managing quotas
Bug 38924: Add patron quota management page
Bug 38924: Add patron_quota_usage table
Bug 38924: Add Koha::Patron::Quota::Usage(s) classes
Bug 38924: Overload delete method in Koha::Old::Checkout
Bug 38924: Add Usage relations to Quota objects
Bug 38924: Add AllowQuotaOverride and UseGuarantorQuota preferences
Bug 38924: Add get_patron_quotas method
Bug 38924: Hook quota check and allocation into checkout
Bug 38924: Hook quota check and allocation into renewals
Bug 38924: Add quota picker to checkout confirmation
Bug 38924: Move from get_patron_quota to Koha::Patron relations
Bug 38924: Add quotas available on circuation screen
Bug 38924: Add type and timestamp to usage table
Bug 38924: Add quota accessor to Koha::Checkout and use on checkouts page
Bug 38924: Display quota used at checkout
Bug 38924: Add quota usage details modal
Bug 38924: Add option to enable/disable quotas
Bug 38924: Add tests for quotas object classes and api endpoints
Bug 38924: DBIC - DO NOT PUSH
Bug 38924: Add relations after the hash in DBIC
Bug 38924: Add issue and old_issue relations to Schema
Bug 38924: Add koha_object_class to Schema files
Bug 38924: Add quota usage api endpoint
Bug 38924: (follow-up) Minor QOL quota modal fixes
Bug 38924: (follow-up) Fix edit modal not autofilling end date
Bug 38924: Add patron_quotas table
Bug 38924: Add Koha::Patron::Quota(s) classes
Bug 38924: Add quotas permissions
Bug 38924: Add API endpoints for managing quotas
Bug 38924: Add patron quota management page
Bug 38924: Add patron_quota_usage table
Bug 38924: Add Koha::Patron::Quota::Usage(s) classes
Bug 38924: Overload delete method in Koha::Old::Checkout
Bug 38924: Add Usage relations to Quota objects
Bug 38924: Add AllowQuotaOverride and UseGuarantorQuota preferences
Bug 38924: Add get_patron_quotas method
Bug 38924: Hook quota check and allocation into checkout
Bug 38924: Hook quota check and allocation into renewals
Bug 38924: Add quota picker to checkout confirmation
Bug 38924: Move from get_patron_quota to Koha::Patron relations
Bug 38924: Add quotas available on circuation screen
Bug 38924: Add type and timestamp to usage table
Bug 38924: Add quota accessor to Koha::Checkout and use on checkouts page
Bug 38924: Display quota used at checkout
Bug 38924: Add quota usage details modal
Bug 38924: Add option to enable/disable quotas
Bug 38924: Add tests for quotas object classes and api endpoints
Bug 38924: DBIC - DO NOT PUSH
Bug 38924: Add relations after the hash in DBIC
Bug 38924: Add issue and old_issue relations to Schema
Bug 38924: Add koha_object_class to Schema files
Bug 38924: Add quota usage api endpoint
Bug 38924: (follow-up) Minor QOL quota modal fixes
Bug 38924: (follow-up) Fix edit modal not autofilling end date
Bug 38924: Add patron_quotas table
Bug 38924: Add Koha::Patron::Quota(s) classes
Bug 38924: Add quotas permissions
Bug 38924: Add API endpoints for managing quotas
Bug 38924: Add patron quota management page
Bug 38924: Add patron_quota_usage table
Bug 38924: Add Koha::Patron::Quota::Usage(s) classes
Bug 38924: Overload delete method in Koha::Old::Checkout
Bug 38924: Add Usage relations to Quota objects
Bug 38924: Add AllowQuotaOverride and UseGuarantorQuota preferences
Bug 38924: Add get_patron_quotas method
Bug 38924: Hook quota check and allocation into checkout
Bug 38924: Hook quota check and allocation into renewals
Bug 38924: Add quota picker to checkout confirmation
Bug 38924: Move from get_patron_quota to Koha::Patron relations
Bug 38924: Add quotas available on circuation screen
Bug 38924: Add type and timestamp to usage table
Bug 38924: Add quota accessor to Koha::Checkout and use on checkouts page
Bug 38924: Display quota used at checkout
Bug 38924: Add quota usage details modal
Bug 38924: Add option to enable/disable quotas
Bug 38924: Add tests for quotas object classes and api endpoints
Bug 38924: DBIC - DO NOT PUSH
Bug 38924: Add relations after the hash in DBIC
Bug 38924: Add issue and old_issue relations to Schema
Bug 38924: Add koha_object_class to Schema files
Bug 38924: Add quota usage api endpoint
Bug 38924: (follow-up) Minor QOL quota modal fixes
Bug 38924: (follow-up) Fix edit modal not autofilling end date
Bug 38924: (follow-up) Record RENEW usage type for renewals
Bug 38924: (follow-up) Exclude QUOTA_SELECT from session remember
Bug 38924: Add patron_quotas table
Bug 38924: Add Koha::Patron::Quota(s) classes
Bug 38924: Add quotas permissions
Bug 38924: Add API endpoints for managing quotas
Bug 38924: Add patron quota management page
Bug 38924: Add patron_quota_usage table
Bug 38924: Add Koha::Patron::Quota::Usage(s) classes
Bug 38924: Overload delete method in Koha::Old::Checkout
Bug 38924: Add Usage relations to Quota objects
Bug 38924: Add AllowQuotaOverride and UseGuarantorQuota preferences
Bug 38924: Add get_patron_quotas method
Bug 38924: Hook quota check and allocation into checkout
Bug 38924: Hook quota check and allocation into renewals
Bug 38924: Add quota picker to checkout confirmation
Bug 38924: Move from get_patron_quota to Koha::Patron relations
Bug 38924: Add quotas available on circuation screen
Bug 38924: Add type and timestamp to usage table
Bug 38924: Add quota accessor to Koha::Checkout and use on checkouts page
Bug 38924: Display quota used at checkout
Bug 38924: Add quota usage details modal
Bug 38924: Add option to enable/disable quotas
Bug 38924: Add tests for quotas object classes and api endpoints
Bug 38924: DBIC - DO NOT PUSH
Bug 38924: Add relations after the hash in DBIC
Bug 38924: Add issue and old_issue relations to Schema
Bug 38924: Add koha_object_class to Schema files
Bug 38924: Add quota usage api endpoint
Bug 38924: (follow-up) Minor QOL quota modal fixes
Bug 38924: (follow-up) Fix edit modal not autofilling end date
Bug 38924: (follow-up) Record RENEW usage type for renewals
Bug 38924: (follow-up) Exclude QUOTA_SELECT from session remember

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
Comment 30 Victor Grousset/tuxayo 2025-08-21 17:24:49 UTC Comment hidden (obsolete)
Comment 31 Victor Grousset/tuxayo 2025-08-21 17:24:51 UTC Comment hidden (obsolete)
Comment 32 Victor Grousset/tuxayo 2025-08-21 17:24:54 UTC Comment hidden (obsolete)
Comment 33 Victor Grousset/tuxayo 2025-08-21 17:24:57 UTC Comment hidden (obsolete)
Comment 34 Victor Grousset/tuxayo 2025-08-21 17:24:59 UTC Comment hidden (obsolete)
Comment 35 Victor Grousset/tuxayo 2025-08-21 17:25:02 UTC Comment hidden (obsolete)
Comment 36 Victor Grousset/tuxayo 2025-08-21 17:25:05 UTC Comment hidden (obsolete)
Comment 37 Victor Grousset/tuxayo 2025-08-21 17:25:08 UTC Comment hidden (obsolete)
Comment 38 Victor Grousset/tuxayo 2025-08-21 17:25:11 UTC Comment hidden (obsolete)
Comment 39 Victor Grousset/tuxayo 2025-08-21 17:25:14 UTC Comment hidden (obsolete)
Comment 40 Victor Grousset/tuxayo 2025-08-21 17:25:17 UTC Comment hidden (obsolete)
Comment 41 Victor Grousset/tuxayo 2025-08-21 17:25:20 UTC Comment hidden (obsolete)
Comment 42 Victor Grousset/tuxayo 2025-08-21 17:25:22 UTC Comment hidden (obsolete)
Comment 43 Victor Grousset/tuxayo 2025-08-21 17:25:25 UTC Comment hidden (obsolete)
Comment 44 Victor Grousset/tuxayo 2025-08-21 17:25:28 UTC Comment hidden (obsolete)
Comment 45 Victor Grousset/tuxayo 2025-08-21 17:25:31 UTC Comment hidden (obsolete)
Comment 46 Victor Grousset/tuxayo 2025-08-21 17:25:34 UTC Comment hidden (obsolete)
Comment 47 Victor Grousset/tuxayo 2025-08-21 17:25:37 UTC Comment hidden (obsolete)
Comment 48 Victor Grousset/tuxayo 2025-08-21 17:25:40 UTC Comment hidden (obsolete)
Comment 49 Victor Grousset/tuxayo 2025-08-21 17:25:43 UTC Comment hidden (obsolete)
Comment 50 Victor Grousset/tuxayo 2025-08-21 17:25:45 UTC Comment hidden (obsolete)
Comment 51 Victor Grousset/tuxayo 2025-08-21 17:25:48 UTC Comment hidden (obsolete)
Comment 52 Victor Grousset/tuxayo 2025-08-21 17:25:51 UTC Comment hidden (obsolete)
Comment 53 Victor Grousset/tuxayo 2025-08-21 17:25:54 UTC Comment hidden (obsolete)
Comment 54 Victor Grousset/tuxayo 2025-08-21 17:25:56 UTC Comment hidden (obsolete)
Comment 55 Victor Grousset/tuxayo 2025-08-21 17:25:59 UTC Comment hidden (obsolete)
Comment 56 Victor Grousset/tuxayo 2025-08-21 17:26:02 UTC Comment hidden (obsolete)
Comment 57 Victor Grousset/tuxayo 2025-08-21 22:53:01 UTC
Created attachment 185675 [details] [review]
Bug 38924: Add patron_quotas table

Add the new patron_quotas table for storing circulation quotas
Comment 58 Victor Grousset/tuxayo 2025-08-21 22:53:04 UTC
Created attachment 185676 [details] [review]
Bug 38924: DBIC Schema

DBIC update
Comment 59 Victor Grousset/tuxayo 2025-08-21 22:53:07 UTC
Created attachment 185677 [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 60 Victor Grousset/tuxayo 2025-08-21 22:53:10 UTC
Created attachment 185678 [details] [review]
Bug 38924: Add quotas permissions

This patch adds the new quotas permissions to the system

Rebased-by: Victor Grousset/tuxayo <victor@tuxayo.net>
Comment 61 Victor Grousset/tuxayo 2025-08-21 22:53:13 UTC
Created attachment 185679 [details] [review]
Bug 38924: Add API endpoints for managing quotas

This commit adds the api endpoints for administering circulation quotas
Comment 62 Victor Grousset/tuxayo 2025-08-21 22:53:16 UTC
Created attachment 185680 [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 63 Victor Grousset/tuxayo 2025-08-21 22:53:18 UTC
Created attachment 185681 [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 64 Victor Grousset/tuxayo 2025-08-21 22:53:21 UTC
Created attachment 185682 [details] [review]
Bug 38924: DBIC Schema
Comment 65 Victor Grousset/tuxayo 2025-08-21 22:53:24 UTC
Created attachment 185683 [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 66 Victor Grousset/tuxayo 2025-08-21 22:53:27 UTC
Created attachment 185684 [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 67 Victor Grousset/tuxayo 2025-08-21 22:53:30 UTC
Created attachment 185685 [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 68 Victor Grousset/tuxayo 2025-08-21 22:53:33 UTC
Created attachment 185686 [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 69 Victor Grousset/tuxayo 2025-08-21 22:53:36 UTC
Created attachment 185687 [details] [review]
Bug 38924: Hook quota check and allocation into checkout
Comment 70 Victor Grousset/tuxayo 2025-08-21 22:53:39 UTC
Created attachment 185688 [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 71 Victor Grousset/tuxayo 2025-08-21 22:53:42 UTC
Created attachment 185689 [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 72 Victor Grousset/tuxayo 2025-08-21 22:53:45 UTC
Created attachment 185690 [details] [review]
Bug 38924: Add koha_object_class to Schema files
Comment 73 Victor Grousset/tuxayo 2025-08-21 22:53:48 UTC
Created attachment 185691 [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 74 Victor Grousset/tuxayo 2025-08-21 22:53:51 UTC
Created attachment 185692 [details] [review]
Bug 38924: Add quotas available on circuation screen
Comment 75 Victor Grousset/tuxayo 2025-08-21 22:53:54 UTC
Created attachment 185693 [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

Rebased-by: Victor Grousset/tuxayo <victor@tuxayo.net>
Comment 76 Victor Grousset/tuxayo 2025-08-21 22:53:57 UTC
Created attachment 185694 [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 77 Victor Grousset/tuxayo 2025-08-21 22:54:00 UTC
Created attachment 185695 [details] [review]
Bug 38924: DBIC Dump
Comment 78 Victor Grousset/tuxayo 2025-08-21 22:54:03 UTC
Created attachment 185696 [details] [review]
Bug 38924: Add quota accessor to Koha::Checkout and use on checkouts page
Comment 79 Victor Grousset/tuxayo 2025-08-21 22:54:06 UTC
Created attachment 185697 [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

Rebased-by: Victor Grousset/tuxayo <victor@tuxayo.net>
Comment 80 Victor Grousset/tuxayo 2025-08-21 22:54:09 UTC
Created attachment 185698 [details] [review]
Bug 38924: Add issue and old_issue relations to Schema
Comment 81 Victor Grousset/tuxayo 2025-08-21 22:54:12 UTC
Created attachment 185699 [details] [review]
Bug 38924: Add quota usage api endpoint
Comment 82 Victor Grousset/tuxayo 2025-08-21 22:54:15 UTC
Created attachment 185700 [details] [review]
Bug 38924: Add quota usage details modal
Comment 83 Victor Grousset/tuxayo 2025-08-21 22:54:18 UTC
Created attachment 185701 [details] [review]
Bug 38924: Add option to enable/disable quotas
Comment 84 Victor Grousset/tuxayo 2025-08-21 22:54:21 UTC
Created attachment 185702 [details] [review]
Bug 38924: Remove duplicate sub

It also made the tests fail
Comment 85 Victor Grousset/tuxayo 2025-08-22 02:12:09 UTC
Rebased. Compared old patches to new patches to ensure no unintended introduced changes.

There are some differences. But it seems it's not from solving conflicts but more the other changes in Koha somehow causing a change generated schema code to move from one commit to another. Anyway, same final state.
https://gitlab.com/tuxayo/Koha/-/commit/a8314615be7286edde4f00338f91d3143606cbca#31b1f86aafa41bf560774c2daa7af732818260e1_47_47
https://gitlab.com/tuxayo/Koha/-/commit/17092c96432275b77e8297a9e388e8a76e2f28f7#47

https://gitlab.com/tuxayo/Koha/-/commit/acedb3f90e07d6ed2b26ab0427ad8dadc86e3183#31b1f86aafa41bf560774c2daa7af732818260e1_0_47
https://gitlab.com/tuxayo/Koha/-/commit/49afbbcb06d0b19e35dc8c0df543c3594f9b4121#31b1f86aafa41bf560774c2daa7af732818260e1_0_47


Tests pass. Anything else to run than t/Koha/Auth/Permissions.t ?
Doesn't mean everything works as on 2025-02-24.
In case it's needed later, relevant branch: https://gitlab.com/tuxayo/Koha/-/commits/bug_38924-old-2025-02-24

Any test plan besides following the high level user stories of the document in comment 1?
If it's that, at least that should be mentioned in a commit message in a test plan section. Or copy the user story there.
Comment 86 Victor Grousset/tuxayo 2025-08-22 02:19:33 UTC
There are 3 DBIC generation commits (which generate 3 times conflicts VS having one).
And they don't have DO NOT PUSH in the name. https://wiki.koha-community.org/wiki/Database_updates#Files_to_change

--

Since February, bug 39367 landed, providing that test:

kohadev-koha@kohadevbox:koha(bug_38924-rebase-wip)$ time prove xt/author/pod_coverage.t
xt/author/pod_coverage.t .. 864/1249
#   Failed test 'POD coverage for Koha/Schema/Result/PatronQuota.pm'
#   at xt/author/pod_coverage.t line 35.
#          got: '1'
#     expected: '0'
# koha_objects_class

#   Failed test 'POD coverage for Koha/Schema/Result/PatronQuotaUsage.pm'
#   at xt/author/pod_coverage.t line 35.
#          got: '2'
#     expected: '0'
# koha_objects_class, koha_object_class
xt/author/pod_coverage.t .. 1241/1249 # Looks like you failed 2 tests of 1249.
xt/author/pod_coverage.t .. Dubious, test returned 2 (wstat 512, 0x200)
Failed 2/1249 subtests

Test Summary Report
-------------------
xt/author/pod_coverage.t (Wstat: 512 (exited 2) Tests: 1249 Failed: 2)
  Failed tests:  1015-1016
  Non-zero exit status: 2
Files=1, Tests=1249,  8 wallclock secs ( 0.23 usr  0.02 sys +  6.43 cusr  0.63 csys =  7.31 CPU)
Result: FAIL
Comment 87 Jacob O'Mara 2025-11-07 12:12:46 UTC
Created attachment 189266 [details] [review]
Bug 38924: Add patron_quotas table

Add the new patron_quotas table for storing circulation quotas
Comment 88 Jacob O'Mara 2025-11-07 12:12:48 UTC
Created attachment 189267 [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 89 Jacob O'Mara 2025-11-07 12:12:51 UTC
Created attachment 189268 [details] [review]
Bug 38924: Add quotas permissions

This patch adds the new quotas permissions to the system
Comment 90 Jacob O'Mara 2025-11-07 12:12:54 UTC
Created attachment 189269 [details] [review]
Bug 38924: Add API endpoints for managing quotas

This commit adds the api endpoints for administering circulation quotas
Comment 91 Jacob O'Mara 2025-11-07 12:12:58 UTC
Created attachment 189270 [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 92 Jacob O'Mara 2025-11-07 12:13:01 UTC
Created attachment 189271 [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 93 Jacob O'Mara 2025-11-07 12:13:04 UTC
Created attachment 189272 [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.
Comment 94 Jacob O'Mara 2025-11-07 12:13:07 UTC
Created attachment 189273 [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 95 Jacob O'Mara 2025-11-07 12:13:09 UTC
Created attachment 189274 [details] [review]
Bug 38924: Add Usage relations to Quota objects
Comment 96 Jacob O'Mara 2025-11-07 12:13:12 UTC
Created attachment 189275 [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 97 Jacob O'Mara 2025-11-07 12:13:15 UTC
Created attachment 189276 [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 98 Jacob O'Mara 2025-11-07 12:13:17 UTC
Created attachment 189277 [details] [review]
Bug 38924: Hook quota check and allocation into checkout
Comment 99 Jacob O'Mara 2025-11-07 12:13:20 UTC
Created attachment 189278 [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 100 Jacob O'Mara 2025-11-07 12:13:23 UTC
Created attachment 189279 [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 101 Jacob O'Mara 2025-11-07 12:13:26 UTC
Created attachment 189280 [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 102 Jacob O'Mara 2025-11-07 12:13:28 UTC
Created attachment 189281 [details] [review]
Bug 38924: Add quotas available on circuation screen
Comment 103 Jacob O'Mara 2025-11-07 12:13:31 UTC
Created attachment 189282 [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 104 Jacob O'Mara 2025-11-07 12:13:34 UTC
Created attachment 189283 [details] [review]
Bug 38924: Add quota accessor to Koha::Checkout and use on checkouts page
Comment 105 Jacob O'Mara 2025-11-07 12:13:36 UTC
Created attachment 189284 [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 106 Jacob O'Mara 2025-11-07 12:13:39 UTC
Created attachment 189285 [details] [review]
Bug 38924: Add quota usage details modal
Comment 107 Jacob O'Mara 2025-11-07 12:13:42 UTC
Created attachment 189286 [details] [review]
Bug 38924: Add option to enable/disable quotas
Comment 108 Jacob O'Mara 2025-11-07 12:13:45 UTC
Created attachment 189287 [details] [review]
Bug 38924: DBIC - DO NOT PUSH
Comment 109 Jacob O'Mara 2025-11-07 12:13:47 UTC
Created attachment 189288 [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 110 Jacob O'Mara 2025-11-07 12:13:50 UTC
Created attachment 189289 [details] [review]
Bug 38924: Add issue and old_issue relations to Schema
Comment 111 Jacob O'Mara 2025-11-07 12:13:53 UTC
Created attachment 189290 [details] [review]
Bug 38924: Add koha_object_class to Schema files
Comment 112 Jacob O'Mara 2025-11-07 12:13:56 UTC
Created attachment 189291 [details] [review]
Bug 38924: Add quota usage api endpoint
Comment 113 Jacob O'Mara 2025-11-07 12:13:59 UTC
Created attachment 189292 [details] [review]
Bug 38924: (follow-up) Minor QOL quota modal fixes

This patch:
 - Makes sure that the quotas modal displays the error message for why
the submit failed, instead of a generic message
 - Clears the modal data on modal close to remove persistent data
 - Get dates directly from flatpickr selectedDates for API requests to
ensure sync.
Comment 114 Victor Grousset/tuxayo 2025-12-04 20:24:16 UTC
After comparing the diffs, "Bug 38924: DBIC - DO NOT PUSH" include all changes from the 3 duplicates. The patches weren't marked as obsolete so they would have conflicted.

--

The content of "Bug 38924: Remove duplicate sub" seem to have been done inline. So I obsoleted my follow-up that was hanging in the ticket.

--

Any test plan besides following the high level user stories of the document in comment 1?
If it's that, at least that should be mentioned in a commit message in a test plan section. Or copy the user story there.

--

New Test failure:
kohadev-koha@kohadevbox:koha(testing-SO-QA)$ prove t/Koha/Auth/Permissions.t
t/Koha/Auth/Permissions.t .. 1/4 
    #   Failed test 'Expected permissions generated for superlibrarian'
    #   at t/Koha/Auth/Permissions.t line 308.
    #     Structures begin differing at:
    #          $got->{CAN_user_borrowers_manage_borrower_quotas} = Does not exist
    #     $expected->{CAN_user_borrowers_manage_borrower_quotas} = '1'
    # Looks like you failed 1 test of 1.

#   Failed test 'superlibrarian tests'
#   at t/Koha/Auth/Permissions.t line 309.
Comment 115 Jacob O'Mara 2026-02-19 12:04:57 UTC
Created attachment 193377 [details] [review]
Bug 38924: Add patron_quotas table

Setup:
1. Enable EnableCirculationQuotas, AllowQuotaOverride, and UseGuarantorQuota in system preferences
2. Create an Institutional patron (ORG) and a second Institutional patron (MEMBER) as guarantee of ORG
3. Create a non-institutional patron (NORELATION) with no relationships

Quota management:
4. Open ORG's detail page → verify "Circulation quota" tab visible in sidebar
5. Open NORELATION's detail page → verify no quota tab
6. Disable EnableCirculationQuotas → open ORG → verify no quota tab. Re-enable before continuing
7. Add a quota for ORG: Q1 2026, allocation 10 → verify it appears in the table
8. Add a second quota with overlapping dates → verify rejected with clash error
9. Edit the quota → verify modal prefills all fields including end date, save updates correctly
10. Add a future non-overlapping quota with no usage → verify Delete button appears. Delete it. Verify Delete button is absent on quotas that have usage

Checkout with single quota:
11. Checkout an item to ORG → verify checkout succeeds, quota used increments, ISSUE usage record visible in details
12. Exhaust ORG's quota, set AllowQuotaOverride ON → attempt checkout → verify confirmation prompt, can override
13. With quota still exhausted, set AllowQuotaOverride OFF → attempt checkout → verify blocked, cannot proceed

Checkout with guarantor quotas:
14. Give MEMBER their own active quota (allocation 5).
15. Checkout to MEMBER → verify QUOTA_SELECT prompt to choose between own and guarantor quota

Renewals and returns:
16. Renew an existing checkout that has quota usage → verify used increments and new RENEW usage record created
17. Return a checked-out item → verify quota used value is unchanged

Add the new patron_quotas table for storing circulation quotas
Comment 116 Jacob O'Mara 2026-02-19 12:05:00 UTC
Created attachment 193378 [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 117 Jacob O'Mara 2026-02-19 12:05:03 UTC
Created attachment 193379 [details] [review]
Bug 38924: Add quotas permissions

This patch adds the new quotas permissions to the system
Comment 118 Jacob O'Mara 2026-02-19 12:05:06 UTC
Created attachment 193380 [details] [review]
Bug 38924: Add API endpoints for managing quotas

This commit adds the api endpoints for administering circulation quotas
Comment 119 Jacob O'Mara 2026-02-19 12:05:09 UTC
Created attachment 193381 [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 120 Jacob O'Mara 2026-02-19 12:05:12 UTC
Created attachment 193382 [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 121 Jacob O'Mara 2026-02-19 12:05:15 UTC
Created attachment 193383 [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.
Comment 122 Jacob O'Mara 2026-02-19 12:05:18 UTC
Created attachment 193384 [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 123 Jacob O'Mara 2026-02-19 12:05:21 UTC
Created attachment 193385 [details] [review]
Bug 38924: Add Usage relations to Quota objects
Comment 124 Jacob O'Mara 2026-02-19 12:05:23 UTC
Created attachment 193386 [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 125 Jacob O'Mara 2026-02-19 12:05:26 UTC
Created attachment 193387 [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 126 Jacob O'Mara 2026-02-19 12:05:29 UTC
Created attachment 193388 [details] [review]
Bug 38924: Hook quota check and allocation into checkout
Comment 127 Jacob O'Mara 2026-02-19 12:05:32 UTC
Created attachment 193389 [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 128 Jacob O'Mara 2026-02-19 12:05:35 UTC
Created attachment 193390 [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 129 Jacob O'Mara 2026-02-19 12:05:38 UTC
Created attachment 193391 [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 130 Jacob O'Mara 2026-02-19 12:05:41 UTC
Created attachment 193392 [details] [review]
Bug 38924: Add quotas available on circuation screen
Comment 131 Jacob O'Mara 2026-02-19 12:05:44 UTC
Created attachment 193393 [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 132 Jacob O'Mara 2026-02-19 12:05:47 UTC
Created attachment 193394 [details] [review]
Bug 38924: Add quota accessor to Koha::Checkout and use on checkouts page
Comment 133 Jacob O'Mara 2026-02-19 12:05:50 UTC
Created attachment 193395 [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 134 Jacob O'Mara 2026-02-19 12:05:53 UTC
Created attachment 193396 [details] [review]
Bug 38924: Add quota usage details modal
Comment 135 Jacob O'Mara 2026-02-19 12:05:56 UTC
Created attachment 193397 [details] [review]
Bug 38924: Add option to enable/disable quotas
Comment 136 Jacob O'Mara 2026-02-19 12:09:11 UTC
Created attachment 193398 [details] [review]
Bug 38924: Add patron_quotas table

Add the new patron_quotas table for storing circulation quotas
Comment 137 Jacob O'Mara 2026-02-19 12:09:14 UTC
Created attachment 193399 [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 138 Jacob O'Mara 2026-02-19 12:09:17 UTC
Created attachment 193400 [details] [review]
Bug 38924: Add quotas permissions

This patch adds the new quotas permissions to the system
Comment 139 Jacob O'Mara 2026-02-19 12:09:20 UTC
Created attachment 193401 [details] [review]
Bug 38924: Add API endpoints for managing quotas

This commit adds the api endpoints for administering circulation quotas
Comment 140 Jacob O'Mara 2026-02-19 12:09:23 UTC
Created attachment 193402 [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 141 Jacob O'Mara 2026-02-19 12:10:10 UTC
Created attachment 193403 [details] [review]
Bug 38924: Add patron_quotas table

Add the new patron_quotas table for storing circulation quotas

Setup:
1. Enable EnableCirculationQuotas, AllowQuotaOverride, and UseGuarantorQuota in system preferences
2. Create an Institutional patron (ORG) and a second Institutional patron (MEMBER) as guarantee of ORG
3. Create a non-institutional patron (NORELATION) with no relationships

Quota management:
4. Open ORG's detail page → verify "Circulation quota" tab visible in sidebar
5. Open NORELATION's detail page → verify no quota tab
6. Disable EnableCirculationQuotas → open ORG → verify no quota tab. Re-enable before continuing
7. Add a quota for ORG: Q1 2026, allocation 10 → verify it appears in the table
8. Add a second quota with overlapping dates → verify rejected with clash error
9. Edit the quota → verify modal prefills all fields including end date, save updates correctly
10. Add a future non-overlapping quota with no usage → verify Delete button appears. Delete it. Verify Delete button is absent on quotas that have usage

Checkout with single quota:
11. Checkout an item to ORG → verify checkout succeeds, quota used increments, ISSUE usage record visible in details
12. Exhaust ORG's quota, set AllowQuotaOverride ON → attempt checkout → verify confirmation prompt, can override
13. With quota still exhausted, set AllowQuotaOverride OFF → attempt checkout → verify blocked, cannot proceed

Checkout with guarantor quotas:
14. Give MEMBER their own active quota (allocation 5).
15. Checkout to MEMBER → verify QUOTA_SELECT prompt to choose between own and guarantor quota

Renewals and returns:
16. Renew an existing checkout that has quota usage → verify used increments and new RENEW usage record created
17. Return a checked-out item → verify quota used value is unchanged
Comment 142 Jacob O'Mara 2026-02-19 12:10:13 UTC
Created attachment 193404 [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 143 Jacob O'Mara 2026-02-19 12:10:17 UTC
Created attachment 193405 [details] [review]
Bug 38924: Add quotas permissions

This patch adds the new quotas permissions to the system
Comment 144 Jacob O'Mara 2026-02-19 12:10:21 UTC
Created attachment 193406 [details] [review]
Bug 38924: Add API endpoints for managing quotas

This commit adds the api endpoints for administering circulation quotas
Comment 145 Jacob O'Mara 2026-02-19 12:10:25 UTC
Created attachment 193407 [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 146 Jacob O'Mara 2026-02-19 12:10:29 UTC
Created attachment 193408 [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 147 Jacob O'Mara 2026-02-19 12:10:33 UTC
Created attachment 193409 [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.
Comment 148 Jacob O'Mara 2026-02-19 12:10:36 UTC
Created attachment 193410 [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 149 Jacob O'Mara 2026-02-19 12:10:40 UTC
Created attachment 193411 [details] [review]
Bug 38924: Add Usage relations to Quota objects
Comment 150 Jacob O'Mara 2026-02-19 12:10:43 UTC
Created attachment 193412 [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 151 Jacob O'Mara 2026-02-19 12:10:47 UTC
Created attachment 193413 [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 152 Jacob O'Mara 2026-02-19 12:10:50 UTC
Created attachment 193414 [details] [review]
Bug 38924: Hook quota check and allocation into checkout
Comment 153 Jacob O'Mara 2026-02-19 12:10:54 UTC
Created attachment 193415 [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 154 Jacob O'Mara 2026-02-19 12:10:57 UTC
Created attachment 193416 [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 155 Jacob O'Mara 2026-02-19 12:11:01 UTC
Created attachment 193417 [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 156 Jacob O'Mara 2026-02-19 12:11:04 UTC
Created attachment 193418 [details] [review]
Bug 38924: Add quotas available on circuation screen
Comment 157 Jacob O'Mara 2026-02-19 12:11:08 UTC
Created attachment 193419 [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 158 Jacob O'Mara 2026-02-19 12:11:12 UTC
Created attachment 193420 [details] [review]
Bug 38924: Add quota accessor to Koha::Checkout and use on checkouts page
Comment 159 Jacob O'Mara 2026-02-19 12:11:17 UTC
Created attachment 193421 [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 160 Jacob O'Mara 2026-02-19 12:11:21 UTC
Created attachment 193422 [details] [review]
Bug 38924: Add quota usage details modal
Comment 161 Jacob O'Mara 2026-02-19 12:11:25 UTC
Created attachment 193423 [details] [review]
Bug 38924: Add option to enable/disable quotas
Comment 162 Jacob O'Mara 2026-02-19 12:11:29 UTC
Created attachment 193424 [details] [review]
Bug 38924: Add tests for quotas object classes and api endpoints
Comment 163 Jacob O'Mara 2026-02-19 12:11:33 UTC
Created attachment 193425 [details] [review]
Bug 38924: DBIC - DO NOT PUSH
Comment 164 Jacob O'Mara 2026-02-19 12:11:37 UTC
Created attachment 193426 [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 165 Jacob O'Mara 2026-02-19 12:11:41 UTC
Created attachment 193427 [details] [review]
Bug 38924: Add issue and old_issue relations to Schema
Comment 166 Jacob O'Mara 2026-02-19 12:11:45 UTC
Created attachment 193428 [details] [review]
Bug 38924: Add koha_object_class to Schema files
Comment 167 Jacob O'Mara 2026-02-19 12:11:49 UTC
Created attachment 193429 [details] [review]
Bug 38924: Add quota usage api endpoint
Comment 168 Jacob O'Mara 2026-02-19 12:11:52 UTC
Created attachment 193430 [details] [review]
Bug 38924: (follow-up) Minor QOL quota modal fixes

- Makes sure that the quotas modal displays the error message for why
the submit failed, instead of a generic message
 - Clears the modal data on modal close to remove persistent data
 - Get dates directly from flatpickr selectedDates for API requests to
ensure sync.
Comment 169 Jacob O'Mara 2026-02-19 12:11:56 UTC
Created attachment 193431 [details] [review]
Bug 38924: (follow-up) Fix edit modal not autofilling end date

The flatpickr setDate calls were passing triggerChange=1 which
caused the start picker's hooks to interfere with the end picker
before its value could be set. Remove triggerChange to match the
pattern used by other Koha date pickers (members.js, datatables.js).
Comment 170 Jacob O'Mara 2026-02-19 12:13:56 UTC
Test plan is hidden in the ~200 comments so posting at the bottom as well for easier finding!


Setup:
1. Enable EnableCirculationQuotas, AllowQuotaOverride, and UseGuarantorQuota in system preferences
2. Create an Institutional patron (ORG) and a second Institutional patron (MEMBER) as guarantee of ORG
3. Create a non-institutional patron (NORELATION) with no relationships

Quota management:
4. Open ORG's detail page → verify "Circulation quota" tab visible in sidebar
5. Open NORELATION's detail page → verify no quota tab
6. Disable EnableCirculationQuotas → open ORG → verify no quota tab. Re-enable before continuing
7. Add a quota for ORG: Q1 2026, allocation 10 → verify it appears in the table
8. Add a second quota with overlapping dates → verify rejected with clash error
9. Edit the quota → verify modal prefills all fields including end date, save updates correctly
10. Add a future non-overlapping quota with no usage → verify Delete button appears. Delete it. Verify Delete button is absent on quotas that have usage

Checkout with single quota:
11. Checkout an item to ORG → verify checkout succeeds, quota used increments, ISSUE usage record visible in details
12. Exhaust ORG's quota, set AllowQuotaOverride ON → attempt checkout → verify confirmation prompt, can override
13. With quota still exhausted, set AllowQuotaOverride OFF → attempt checkout → verify blocked, cannot proceed

Checkout with guarantor quotas:
14. Give MEMBER their own active quota (allocation 5).
15. Checkout to MEMBER → verify QUOTA_SELECT prompt to choose between own and guarantor quota

Renewals and returns:
16. Renew an existing checkout that has quota usage → verify used increments and new RENEW usage record created
17. Return a checked-out item → verify quota used value is unchanged

Add the new patron_quotas table for storing circulation quotas
Comment 171 Jacob O'Mara 2026-02-19 12:29:20 UTC
Created attachment 193432 [details] [review]
Bug 38924: Add patron_quotas table

Add the new patron_quotas table for storing circulation quotas

Setup:
1. Enable EnableCirculationQuotas, AllowQuotaOverride, and UseGuarantorQuota in system preferences
2. Create an Institutional patron (ORG) and a second Institutional patron (MEMBER) as guarantee of ORG
3. Create a non-institutional patron (NORELATION) with no relationships

Quota management:
4. Open ORG's detail page → verify "Circulation quota" tab visible in sidebar
5. Open NORELATION's detail page → verify no quota tab
6. Disable EnableCirculationQuotas → open ORG → verify no quota tab. Re-enable before continuing
7. Add a quota for ORG: Q1 2026, allocation 10 → verify it appears in the table
8. Add a second quota with overlapping dates → verify rejected with clash error
9. Edit the quota → verify modal prefills all fields including end date, save updates correctly
10. Add a future non-overlapping quota with no usage → verify Delete button appears. Delete it. Verify Delete button is absent on quotas that have usage

Checkout with single quota:
11. Checkout an item to ORG → verify checkout succeeds, quota used increments, ISSUE usage record visible in details
12. Exhaust ORG's quota, set AllowQuotaOverride ON → attempt checkout → verify confirmation prompt, can override
13. With quota still exhausted, set AllowQuotaOverride OFF → attempt checkout → verify blocked, cannot proceed

Checkout with guarantor quotas:
14. Give MEMBER their own active quota (allocation 5).
15. Checkout to MEMBER → verify QUOTA_SELECT prompt to choose between own and guarantor quota

Renewals and returns:
16. Renew an existing checkout that has quota usage → verify used increments and new RENEW usage record created
17. Return a checked-out item → verify quota used value is unchanged


Signed-off-by: Jacob O'Mara <jacob.omara@openfifth.co.uk>
Comment 172 Jacob O'Mara 2026-02-19 12:29:24 UTC
Created attachment 193433 [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

Signed-off-by: Jacob O'Mara <jacob.omara@openfifth.co.uk>
Comment 173 Jacob O'Mara 2026-02-19 12:29:27 UTC
Created attachment 193434 [details] [review]
Bug 38924: Add quotas permissions

This patch adds the new quotas permissions to the system

Signed-off-by: Jacob O'Mara <jacob.omara@openfifth.co.uk>
Comment 174 Jacob O'Mara 2026-02-19 12:29:30 UTC
Created attachment 193435 [details] [review]
Bug 38924: Add API endpoints for managing quotas

This commit adds the api endpoints for administering circulation quotas

Signed-off-by: Jacob O'Mara <jacob.omara@openfifth.co.uk>
Comment 175 Jacob O'Mara 2026-02-19 12:29:34 UTC
Created attachment 193436 [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.

Signed-off-by: Jacob O'Mara <jacob.omara@openfifth.co.uk>
Comment 176 Jacob O'Mara 2026-02-19 12:29:37 UTC
Created attachment 193437 [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.

Signed-off-by: Jacob O'Mara <jacob.omara@openfifth.co.uk>
Comment 177 Jacob O'Mara 2026-02-19 12:29:41 UTC
Created attachment 193438 [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.

Signed-off-by: Jacob O'Mara <jacob.omara@openfifth.co.uk>
Comment 178 Jacob O'Mara 2026-02-19 12:29:46 UTC
Created attachment 193439 [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.

Signed-off-by: Jacob O'Mara <jacob.omara@openfifth.co.uk>
Comment 179 Jacob O'Mara 2026-02-19 12:29:50 UTC
Created attachment 193440 [details] [review]
Bug 38924: Add Usage relations to Quota objects

Signed-off-by: Jacob O'Mara <jacob.omara@openfifth.co.uk>
Comment 180 Jacob O'Mara 2026-02-19 12:29:54 UTC
Created attachment 193441 [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

Signed-off-by: Jacob O'Mara <jacob.omara@openfifth.co.uk>
Comment 181 Jacob O'Mara 2026-02-19 12:29:58 UTC
Created attachment 193442 [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

Signed-off-by: Jacob O'Mara <jacob.omara@openfifth.co.uk>
Comment 182 Jacob O'Mara 2026-02-19 12:30:01 UTC
Created attachment 193443 [details] [review]
Bug 38924: Hook quota check and allocation into checkout

Signed-off-by: Jacob O'Mara <jacob.omara@openfifth.co.uk>
Comment 183 Jacob O'Mara 2026-02-19 12:30:04 UTC
Created attachment 193444 [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

Signed-off-by: Jacob O'Mara <jacob.omara@openfifth.co.uk>
Comment 184 Jacob O'Mara 2026-02-19 12:30:08 UTC
Created attachment 193445 [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

Signed-off-by: Jacob O'Mara <jacob.omara@openfifth.co.uk>
Comment 185 Jacob O'Mara 2026-02-19 12:30:11 UTC
Created attachment 193446 [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

Signed-off-by: Jacob O'Mara <jacob.omara@openfifth.co.uk>
Comment 186 Jacob O'Mara 2026-02-19 12:30:15 UTC
Created attachment 193447 [details] [review]
Bug 38924: Add quotas available on circuation screen

Signed-off-by: Jacob O'Mara <jacob.omara@openfifth.co.uk>
Comment 187 Jacob O'Mara 2026-02-19 12:30:18 UTC
Created attachment 193448 [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

Signed-off-by: Jacob O'Mara <jacob.omara@openfifth.co.uk>
Comment 188 Jacob O'Mara 2026-02-19 12:30:22 UTC
Created attachment 193449 [details] [review]
Bug 38924: Add quota accessor to Koha::Checkout and use on checkouts page

Signed-off-by: Jacob O'Mara <jacob.omara@openfifth.co.uk>
Comment 189 Jacob O'Mara 2026-02-19 12:30:25 UTC
Created attachment 193450 [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

Signed-off-by: Jacob O'Mara <jacob.omara@openfifth.co.uk>
Comment 190 Jacob O'Mara 2026-02-19 12:30:29 UTC
Created attachment 193451 [details] [review]
Bug 38924: Add quota usage details modal

Signed-off-by: Jacob O'Mara <jacob.omara@openfifth.co.uk>
Comment 191 Jacob O'Mara 2026-02-19 12:30:32 UTC
Created attachment 193452 [details] [review]
Bug 38924: Add option to enable/disable quotas

Signed-off-by: Jacob O'Mara <jacob.omara@openfifth.co.uk>
Comment 192 Jacob O'Mara 2026-02-19 12:30:35 UTC
Created attachment 193453 [details] [review]
Bug 38924: Add tests for quotas object classes and api endpoints

Signed-off-by: Jacob O'Mara <jacob.omara@openfifth.co.uk>
Comment 193 Jacob O'Mara 2026-02-19 12:30:39 UTC
Created attachment 193454 [details] [review]
Bug 38924: DBIC - DO NOT PUSH

Signed-off-by: Jacob O'Mara <jacob.omara@openfifth.co.uk>
Comment 194 Jacob O'Mara 2026-02-19 12:30:42 UTC
Created attachment 193455 [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

Signed-off-by: Jacob O'Mara <jacob.omara@openfifth.co.uk>
Comment 195 Jacob O'Mara 2026-02-19 12:30:45 UTC
Created attachment 193456 [details] [review]
Bug 38924: Add issue and old_issue relations to Schema

Signed-off-by: Jacob O'Mara <jacob.omara@openfifth.co.uk>
Comment 196 Jacob O'Mara 2026-02-19 12:30:49 UTC
Created attachment 193457 [details] [review]
Bug 38924: Add koha_object_class to Schema files

Signed-off-by: Jacob O'Mara <jacob.omara@openfifth.co.uk>
Comment 197 Jacob O'Mara 2026-02-19 12:30:52 UTC
Created attachment 193458 [details] [review]
Bug 38924: Add quota usage api endpoint

Signed-off-by: Jacob O'Mara <jacob.omara@openfifth.co.uk>
Comment 198 Jacob O'Mara 2026-02-19 12:30:55 UTC
Created attachment 193459 [details] [review]
Bug 38924: (follow-up) Minor QOL quota modal fixes

- Makes sure that the quotas modal displays the error message for why
the submit failed, instead of a generic message
 - Clears the modal data on modal close to remove persistent data
 - Get dates directly from flatpickr selectedDates for API requests to
ensure sync.

Signed-off-by: Jacob O'Mara <jacob.omara@openfifth.co.uk>
Comment 199 Jacob O'Mara 2026-02-19 12:30:59 UTC
Created attachment 193460 [details] [review]
Bug 38924: (follow-up) Fix edit modal not autofilling end date

The flatpickr setDate calls were passing triggerChange=1 which
caused the start picker's hooks to interfere with the end picker
before its value could be set. Remove triggerChange to match the
pattern used by other Koha date pickers (members.js, datatables.js).

Signed-off-by: Jacob O'Mara <jacob.omara@openfifth.co.uk>
Comment 200 Jacob O'Mara 2026-02-19 12:33:03 UTC
This has been on one of our Customer's sites for around a year at this point with no issues, going to call that an implicit sign off that it works as expected. 
Added sign-off line and moved to needs QA

Here is the test plan as it's once again buried:


Setup:
1. Enable EnableCirculationQuotas, AllowQuotaOverride, and UseGuarantorQuota in system preferences
2. Create an Institutional patron (ORG) and a second Institutional patron (MEMBER) as guarantee of ORG
3. Create a non-institutional patron (NORELATION) with no relationships

Quota management:
4. Open ORG's detail page → verify "Circulation quota" tab visible in sidebar
5. Open NORELATION's detail page → verify no quota tab
6. Disable EnableCirculationQuotas → open ORG → verify no quota tab. Re-enable before continuing
7. Add a quota for ORG: Q1 2026, allocation 10 → verify it appears in the table
8. Add a second quota with overlapping dates → verify rejected with clash error
9. Edit the quota → verify modal prefills all fields including end date, save updates correctly
10. Add a future non-overlapping quota with no usage → verify Delete button appears. Delete it. Verify Delete button is absent on quotas that have usage

Checkout with single quota:
11. Checkout an item to ORG → verify checkout succeeds, quota used increments, ISSUE usage record visible in details
12. Exhaust ORG's quota, set AllowQuotaOverride ON → attempt checkout → verify confirmation prompt, can override
13. With quota still exhausted, set AllowQuotaOverride OFF → attempt checkout → verify blocked, cannot proceed

Checkout with guarantor quotas:
14. Give MEMBER their own active quota (allocation 5).
15. Checkout to MEMBER → verify QUOTA_SELECT prompt to choose between own and guarantor quota

Renewals and returns:
16. Renew an existing checkout that has quota usage → verify used increments and new RENEW usage record created
17. Return a checked-out item → verify quota used value is unchanged
Comment 201 Jacob O'Mara 2026-02-20 13:40:01 UTC
Created attachment 193547 [details] [review]
Bug 38924: Add patron_quotas table

Add the new patron_quotas table for storing circulation quotas

Setup:
1. Enable EnableCirculationQuotas, AllowQuotaOverride, and UseGuarantorQuota in system preferences
2. Create an Institutional patron (ORG) and a second Institutional patron (MEMBER) as guarantee of ORG
3. Create a non-institutional patron (NORELATION) with no relationships

Quota management:
4. Open ORG's detail page → verify "Circulation quota" tab visible in sidebar
5. Open NORELATION's detail page → verify no quota tab
6. Disable EnableCirculationQuotas → open ORG → verify no quota tab. Re-enable before continuing
7. Add a quota for ORG: Q1 2026, allocation 10 → verify it appears in the table
8. Add a second quota with overlapping dates → verify rejected with clash error
9. Edit the quota → verify modal prefills all fields including end date, save updates correctly
10. Add a future non-overlapping quota with no usage → verify Delete button appears. Delete it. Verify Delete button is absent on quotas that have usage

Checkout with single quota:
11. Checkout an item to ORG → verify checkout succeeds, quota used increments, ISSUE usage record visible in details
12. Exhaust ORG's quota, set AllowQuotaOverride ON → attempt checkout → verify confirmation prompt, can override
13. With quota still exhausted, set AllowQuotaOverride OFF → attempt checkout → verify blocked, cannot proceed

Checkout with guarantor quotas:
14. Give MEMBER their own active quota (allocation 5).
15. Checkout to MEMBER → verify QUOTA_SELECT prompt to choose between own and guarantor quota

Renewals and returns:
16. Renew an existing checkout that has quota usage → verify used increments and new RENEW usage record created
17. Return a checked-out item → verify quota used value is unchanged
Comment 202 Jacob O'Mara 2026-02-20 13:40:05 UTC
Created attachment 193548 [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 203 Jacob O'Mara 2026-02-20 13:40:08 UTC
Created attachment 193549 [details] [review]
Bug 38924: Add quotas permissions

This patch adds the new quotas permissions to the system
Comment 204 Jacob O'Mara 2026-02-20 13:40:11 UTC
Created attachment 193550 [details] [review]
Bug 38924: Add API endpoints for managing quotas

This commit adds the api endpoints for administering circulation quotas
Comment 205 Jacob O'Mara 2026-02-20 13:40:15 UTC
Created attachment 193551 [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 206 Jacob O'Mara 2026-02-20 13:40:18 UTC
Created attachment 193552 [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 207 Jacob O'Mara 2026-02-20 13:40:21 UTC
Created attachment 193553 [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.
Comment 208 Jacob O'Mara 2026-02-20 13:40:24 UTC
Created attachment 193554 [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 209 Jacob O'Mara 2026-02-20 13:40:27 UTC
Created attachment 193555 [details] [review]
Bug 38924: Add Usage relations to Quota objects
Comment 210 Jacob O'Mara 2026-02-20 13:40:30 UTC
Created attachment 193556 [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 211 Jacob O'Mara 2026-02-20 13:40:34 UTC
Created attachment 193557 [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 212 Jacob O'Mara 2026-02-20 13:40:37 UTC
Created attachment 193558 [details] [review]
Bug 38924: Hook quota check and allocation into checkout
Comment 213 Jacob O'Mara 2026-02-20 13:40:40 UTC
Created attachment 193559 [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 214 Jacob O'Mara 2026-02-20 13:40:43 UTC
Created attachment 193560 [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 215 Jacob O'Mara 2026-02-20 13:40:46 UTC
Created attachment 193561 [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 216 Jacob O'Mara 2026-02-20 13:40:50 UTC
Created attachment 193562 [details] [review]
Bug 38924: Add quotas available on circuation screen
Comment 217 Jacob O'Mara 2026-02-20 13:40:53 UTC
Created attachment 193563 [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 218 Jacob O'Mara 2026-02-20 13:40:56 UTC
Created attachment 193564 [details] [review]
Bug 38924: Add quota accessor to Koha::Checkout and use on checkouts page
Comment 219 Jacob O'Mara 2026-02-20 13:40:59 UTC
Created attachment 193565 [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 220 Jacob O'Mara 2026-02-20 13:41:03 UTC
Created attachment 193566 [details] [review]
Bug 38924: Add quota usage details modal
Comment 221 Jacob O'Mara 2026-02-20 13:41:06 UTC
Created attachment 193567 [details] [review]
Bug 38924: Add option to enable/disable quotas
Comment 222 Jacob O'Mara 2026-02-20 13:41:09 UTC
Created attachment 193568 [details] [review]
Bug 38924: Add tests for quotas object classes and api endpoints
Comment 223 Jacob O'Mara 2026-02-20 13:41:12 UTC
Created attachment 193569 [details] [review]
Bug 38924: DBIC - DO NOT PUSH
Comment 224 Jacob O'Mara 2026-02-20 13:41:16 UTC
Created attachment 193570 [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 225 Jacob O'Mara 2026-02-20 13:41:19 UTC
Created attachment 193571 [details] [review]
Bug 38924: Add issue and old_issue relations to Schema
Comment 226 Jacob O'Mara 2026-02-20 13:41:22 UTC
Created attachment 193572 [details] [review]
Bug 38924: Add koha_object_class to Schema files
Comment 227 Jacob O'Mara 2026-02-20 13:41:26 UTC
Created attachment 193573 [details] [review]
Bug 38924: Add quota usage api endpoint
Comment 228 Jacob O'Mara 2026-02-20 13:41:29 UTC
Created attachment 193574 [details] [review]
Bug 38924: (follow-up) Minor QOL quota modal fixes

- Makes sure that the quotas modal displays the error message for why
the submit failed, instead of a generic message
 - Clears the modal data on modal close to remove persistent data
 - Get dates directly from flatpickr selectedDates for API requests to
ensure sync.
Comment 229 Jacob O'Mara 2026-02-20 13:41:32 UTC
Created attachment 193575 [details] [review]
Bug 38924: (follow-up) Fix edit modal not autofilling end date

The flatpickr setDate calls were passing triggerChange=1 which
caused the start picker's hooks to interfere with the end picker
before its value could be set. Remove triggerChange to match the
pattern used by other Koha date pickers (members.js, datatables.js).
Comment 230 Jacob O'Mara 2026-02-20 13:41:35 UTC
Created attachment 193576 [details] [review]
Bug 38924: (follow-up) Record RENEW usage type for renewals

Pass explicit type param to add_usage: ISSUE for checkouts,
RENEW for renewals. Default to ISSUE in add_usage for safety.
Comment 231 Jacob O'Mara 2026-02-20 13:41:39 UTC
Created attachment 193577 [details] [review]
Bug 38924: (follow-up) Exclude QUOTA_SELECT from session remember

Prevents quota selection from being stored in or skipped by the
session confirmation cookie. Hides the remember checkbox when quota
is the only confirmation shown.
Comment 232 OpenFifth Sandboxes 2026-02-27 17:32:26 UTC
Created attachment 194119 [details] [review]
Bug 38924: Add patron_quotas table

Add the new patron_quotas table for storing circulation quotas

Signed-off-by: Sally <sally.healey@cheshiresharedservices.gov.uk>
Comment 233 OpenFifth Sandboxes 2026-02-27 17:32:29 UTC
Created attachment 194120 [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

Signed-off-by: Sally <sally.healey@cheshiresharedservices.gov.uk>
Comment 234 OpenFifth Sandboxes 2026-02-27 17:32:32 UTC
Created attachment 194121 [details] [review]
Bug 38924: Add quotas permissions

This patch adds the new quotas permissions to the system

Signed-off-by: Sally <sally.healey@cheshiresharedservices.gov.uk>
Comment 235 OpenFifth Sandboxes 2026-02-27 17:32:35 UTC
Created attachment 194122 [details] [review]
Bug 38924: Add API endpoints for managing quotas

This commit adds the api endpoints for administering circulation quotas

Signed-off-by: Sally <sally.healey@cheshiresharedservices.gov.uk>
Comment 236 OpenFifth Sandboxes 2026-02-27 17:32:38 UTC
Created attachment 194123 [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.

Signed-off-by: Sally <sally.healey@cheshiresharedservices.gov.uk>
Comment 237 OpenFifth Sandboxes 2026-02-27 17:32:41 UTC
Created attachment 194124 [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.

Signed-off-by: Sally <sally.healey@cheshiresharedservices.gov.uk>
Comment 238 OpenFifth Sandboxes 2026-02-27 17:32:44 UTC
Created attachment 194125 [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.

Signed-off-by: Sally <sally.healey@cheshiresharedservices.gov.uk>
Comment 239 OpenFifth Sandboxes 2026-02-27 17:32:47 UTC
Created attachment 194126 [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.

Signed-off-by: Sally <sally.healey@cheshiresharedservices.gov.uk>
Comment 240 OpenFifth Sandboxes 2026-02-27 17:32:50 UTC
Created attachment 194127 [details] [review]
Bug 38924: Add Usage relations to Quota objects

Signed-off-by: Sally <sally.healey@cheshiresharedservices.gov.uk>
Comment 241 OpenFifth Sandboxes 2026-02-27 17:32:53 UTC
Created attachment 194128 [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

Signed-off-by: Sally <sally.healey@cheshiresharedservices.gov.uk>
Comment 242 OpenFifth Sandboxes 2026-02-27 17:32:56 UTC
Created attachment 194129 [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

Signed-off-by: Sally <sally.healey@cheshiresharedservices.gov.uk>
Comment 243 OpenFifth Sandboxes 2026-02-27 17:32:58 UTC
Created attachment 194130 [details] [review]
Bug 38924: Hook quota check and allocation into checkout

Signed-off-by: Sally <sally.healey@cheshiresharedservices.gov.uk>
Comment 244 OpenFifth Sandboxes 2026-02-27 17:33:01 UTC
Created attachment 194131 [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

Signed-off-by: Sally <sally.healey@cheshiresharedservices.gov.uk>
Comment 245 OpenFifth Sandboxes 2026-02-27 17:33:04 UTC
Created attachment 194132 [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

Signed-off-by: Sally <sally.healey@cheshiresharedservices.gov.uk>
Comment 246 OpenFifth Sandboxes 2026-02-27 17:33:08 UTC
Created attachment 194133 [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

Signed-off-by: Sally <sally.healey@cheshiresharedservices.gov.uk>
Comment 247 OpenFifth Sandboxes 2026-02-27 17:33:11 UTC
Created attachment 194134 [details] [review]
Bug 38924: Add quotas available on circuation screen

Signed-off-by: Sally <sally.healey@cheshiresharedservices.gov.uk>
Comment 248 OpenFifth Sandboxes 2026-02-27 17:33:14 UTC
Created attachment 194135 [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

Signed-off-by: Sally <sally.healey@cheshiresharedservices.gov.uk>
Comment 249 OpenFifth Sandboxes 2026-02-27 17:33:17 UTC
Created attachment 194136 [details] [review]
Bug 38924: Add quota accessor to Koha::Checkout and use on checkouts page

Signed-off-by: Sally <sally.healey@cheshiresharedservices.gov.uk>
Comment 250 OpenFifth Sandboxes 2026-02-27 17:33:20 UTC
Created attachment 194137 [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

Signed-off-by: Sally <sally.healey@cheshiresharedservices.gov.uk>
Comment 251 OpenFifth Sandboxes 2026-02-27 17:33:23 UTC
Created attachment 194138 [details] [review]
Bug 38924: Add quota usage details modal

Signed-off-by: Sally <sally.healey@cheshiresharedservices.gov.uk>
Comment 252 OpenFifth Sandboxes 2026-02-27 17:33:26 UTC
Created attachment 194139 [details] [review]
Bug 38924: Add option to enable/disable quotas

Signed-off-by: Sally <sally.healey@cheshiresharedservices.gov.uk>
Comment 253 OpenFifth Sandboxes 2026-02-27 17:33:29 UTC
Created attachment 194140 [details] [review]
Bug 38924: Add tests for quotas object classes and api endpoints

Signed-off-by: Sally <sally.healey@cheshiresharedservices.gov.uk>
Comment 254 OpenFifth Sandboxes 2026-02-27 17:33:32 UTC
Created attachment 194141 [details] [review]
Bug 38924: DBIC - DO NOT PUSH

Signed-off-by: Sally <sally.healey@cheshiresharedservices.gov.uk>
Comment 255 OpenFifth Sandboxes 2026-02-27 17:33:35 UTC
Created attachment 194142 [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

Signed-off-by: Sally <sally.healey@cheshiresharedservices.gov.uk>
Comment 256 OpenFifth Sandboxes 2026-02-27 17:33:38 UTC
Created attachment 194143 [details] [review]
Bug 38924: Add issue and old_issue relations to Schema

Signed-off-by: Sally <sally.healey@cheshiresharedservices.gov.uk>
Comment 257 OpenFifth Sandboxes 2026-02-27 17:33:41 UTC
Created attachment 194144 [details] [review]
Bug 38924: Add koha_object_class to Schema files

Signed-off-by: Sally <sally.healey@cheshiresharedservices.gov.uk>
Comment 258 OpenFifth Sandboxes 2026-02-27 17:33:44 UTC
Created attachment 194145 [details] [review]
Bug 38924: Add quota usage api endpoint

Signed-off-by: Sally <sally.healey@cheshiresharedservices.gov.uk>
Comment 259 OpenFifth Sandboxes 2026-02-27 17:33:48 UTC
Created attachment 194146 [details] [review]
Bug 38924: (follow-up) Minor QOL quota modal fixes

- Makes sure that the quotas modal displays the error message for why
the submit failed, instead of a generic message
 - Clears the modal data on modal close to remove persistent data
 - Get dates directly from flatpickr selectedDates for API requests to
ensure sync.

Signed-off-by: Sally <sally.healey@cheshiresharedservices.gov.uk>
Comment 260 OpenFifth Sandboxes 2026-02-27 17:33:51 UTC
Created attachment 194147 [details] [review]
Bug 38924: (follow-up) Fix edit modal not autofilling end date

The flatpickr setDate calls were passing triggerChange=1 which
caused the start picker's hooks to interfere with the end picker
before its value could be set. Remove triggerChange to match the
pattern used by other Koha date pickers (members.js, datatables.js).

Signed-off-by: Sally <sally.healey@cheshiresharedservices.gov.uk>
Comment 261 OpenFifth Sandboxes 2026-02-27 17:33:54 UTC
Created attachment 194148 [details] [review]
Bug 38924: (follow-up) Record RENEW usage type for renewals

Pass explicit type param to add_usage: ISSUE for checkouts,
RENEW for renewals. Default to ISSUE in add_usage for safety.

Signed-off-by: Sally <sally.healey@cheshiresharedservices.gov.uk>
Comment 262 OpenFifth Sandboxes 2026-02-27 17:33:57 UTC
Created attachment 194149 [details] [review]
Bug 38924: (follow-up) Exclude QUOTA_SELECT from session remember

Prevents quota selection from being stored in or skipped by the
session confirmation cookie. Hides the remember checkbox when quota
is the only confirmation shown.

Signed-off-by: Sally <sally.healey@cheshiresharedservices.gov.uk>
Comment 263 Sally 2026-02-27 17:34:44 UTC
(In reply to Jacob O'Mara from comment #201)
> Created attachment 193547 [details] [review] [review]
> Bug 38924: Add patron_quotas table
> 
> Add the new patron_quotas table for storing circulation quotas
> 
> Setup:
> 1. Enable EnableCirculationQuotas, AllowQuotaOverride, and UseGuarantorQuota
> in system preferences
> 2. Create an Institutional patron (ORG) and a second Institutional patron
> (MEMBER) as guarantee of ORG
> 3. Create a non-institutional patron (NORELATION) with no relationships
> 
> Quota management:
> 4. Open ORG's detail page → verify "Circulation quota" tab visible in sidebar
> 5. Open NORELATION's detail page → verify no quota tab
> 6. Disable EnableCirculationQuotas → open ORG → verify no quota tab.
> Re-enable before continuing
> 7. Add a quota for ORG: Q1 2026, allocation 10 → verify it appears in the
> table
> 8. Add a second quota with overlapping dates → verify rejected with clash
> error
> 9. Edit the quota → verify modal prefills all fields including end date,
> save updates correctly
> 10. Add a future non-overlapping quota with no usage → verify Delete button
> appears. Delete it. Verify Delete button is absent on quotas that have usage
> 
> Checkout with single quota:
> 11. Checkout an item to ORG → verify checkout succeeds, quota used
> increments, ISSUE usage record visible in details
> 12. Exhaust ORG's quota, set AllowQuotaOverride ON → attempt checkout →
> verify confirmation prompt, can override
> 13. With quota still exhausted, set AllowQuotaOverride OFF → attempt
> checkout → verify blocked, cannot proceed
> 
> Checkout with guarantor quotas:
> 14. Give MEMBER their own active quota (allocation 5).
> 15. Checkout to MEMBER → verify QUOTA_SELECT prompt to choose between own
> and guarantor quota
> 
> Renewals and returns:
> 16. Renew an existing checkout that has quota usage → verify used increments
> and new RENEW usage record created
> 17. Return a checked-out item → verify quota used value is unchanged

Works as described in this test plan; signed off.