Koha-clms/opac
Martin Renvoize f1b20b645c
Bug 3492: Modernize hold fee system and migrate to circulation rules
This commit completely modernizes the hold fee system by migrating from
the deprecated categories.reservefee column to the circulation rules framework
and implementing modern Koha::Objects patterns.

WHAT CHANGED:

1. MIGRATION TO CIRCULATION RULES:
   - Moved hold fees from categories.reservefee to circulation_rules table
   - Added database migration script with atomic update
   - Maintains existing fee amounts during migration
   - Provides rule hierarchy: category+itemtype+branch specific rules

2. NEW SYSTEM PREFERENCE: TitleHoldFeeStrategy
   - Options: highest, lowest, most_common
   - Addresses inconsistent title-level hold fees when items have different fees
   - Default: 'highest' (safest approach for library revenue)

3. MODERN Koha::Objects API:
   - Koha::Item->holds_fee($patron): Calculate fee for specific item
   - Koha::Hold->calculate_hold_fee(): Enhanced item/title-level logic
   - Koha::Hold->should_charge($stage): Centralized charging logic
   - Koha::Hold->charge_hold_fee(): Modern fee charging with proper accounting
   - Removed C4::Reserves::GetReserveFee and ChargeReserveFee

4. ENHANCED FUNCTIONALITY:
   - Proper ReservesControlBranch logic (patron home vs item home library)
   - Complete HoldFeeMode implementation (placement/collection/not_always)
   - Clear OPAC messaging with "You will be charged..." commitment
   - Comprehensive test coverage for all fee scenarios

5. TECHNICAL IMPROVEMENTS:
   - Object-oriented design following Koha patterns
   - Proper error handling and edge case management
   - Modern test structure with comprehensive coverage
   - Clean separation between fee calculation and charging

TEST PLAN:

A) MIGRATION AND SETUP:
   1. Apply all patches and run database update
   2. Verify existing hold fees migrated to circulation rules:
      - Administration > Circulation and fine rules
      - Previous categories.reservefee values now in "Hold fee" column
   3. Confirm old categories.reservefee column no longer used

B) BASIC FEE CALCULATION:
   1. Set up patron categories with different hold fees in circulation rules
   2. Create items with different item types, each with different hold fees
   3. Test item-level holds charge correct fees based on specific item
   4. Test title-level holds use TitleHoldFeeStrategy preference

C) TITLE-LEVEL HOLD STRATEGIES:
   1. Set TitleHoldFeeStrategy to "highest":
      - Create title with items having fees $1.00, $2.00, $3.00
      - Verify title-level holds charge $3.00
   2. Set TitleHoldFeeStrategy to "lowest":
      - Verify same title charges $1.00
   3. Set TitleHoldFeeStrategy to "most_common":
      - Add multiple items with $2.00 fee
      - Verify title-level holds charge $2.00 (most common)

D) HOLDFEEMODE PREFERENCES:
   1. Set HoldFeeMode to "any_time_is_placed":
      - Place holds and verify immediate fee charging
      - Check patron account for correct hold fee debits
   2. Set HoldFeeMode to "any_time_is_collected":
      - Place holds, verify no immediate charges
      - Check out items to patron, verify fee charged on collection
   3. Set HoldFeeMode to "not_always":
      - With available items: verify no fee charged
      - With all items checked out but no other holds: verify no fee
      - With all items checked out and other holds exist: verify fee charged

E) RULE HIERARCHY TESTING:
   1. Set different fees for different category/itemtype/branch combinations
   2. Verify most specific rule applies:
      - Branch + Category + ItemType (most specific)
      - Category + ItemType
      - Category only (most general)
   3. Test with different patron categories and item types

F) USER INTERFACE TESTING:
   1. OPAC interface:
      - Verify "You will be charged..." messages display correct amounts
      - Test both item-level and title-level hold fee messages
      - Confirm fees match actual charges in patron account
   2. Staff interface:
      - Place holds for patrons and verify fee calculations
      - Check Administration > Circulation rules interface works correctly

G) EDGE CASES AND ERROR HANDLING:
   1. Test $0.00 fees (no charge scenarios)
   2. Test patrons with no applicable fee rules (should default to $0.00)
   3. Test items with no holdable copies (should return $0.00)
   4. Test invalid/missing itemtypes or categories
   5. Test holds on biblios with no items

H) REGRESSION TESTING:
   1. Verify existing hold placement workflows unchanged
   2. Check patron account charging remains accurate
   3. Confirm OPAC and staff interfaces display correctly
   4. Test that existing holds continue to work properly

I) UNIT TESTS:
   Run the following test suites to verify functionality:
   - prove t/db_dependent/Koha/Hold.t
   - prove t/db_dependent/Koha/Item.t
   - prove t/db_dependent/Reserves.t
   - prove t/db_dependent/Circulation.t

BACKWARDS COMPATIBILITY:
- All existing functionality preserved
- Hold fee amounts maintained during migration
- Existing workflows continue unchanged
- Legacy code updated to use new API seamlessly

Sponsored-by: OpenFifth <https://openfifth.co.uk>
Signed-off-by: Jackie Usher <jackie.usher@westsussex.gov.uk>
Signed-off-by: Tomás Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
2026-02-09 12:57:56 -07:00
..
clubs Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
errors Bug 28146: Respect ReplytoDefault in error pages 2025-10-09 14:58:41 -06:00
external/overdrive Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
sci Bug 34596: Add rebuild queue where needed for existing calls to AddReturn 2025-10-06 09:15:17 -06:00
sco Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
svc Bug 40163: (follow-up) Fix wrong GNU links and update test 2025-09-24 09:25:04 -06:00
ilsdi.pl Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
maintenance.pl Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
oai.pl Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
opac-ISBDdetail.pl Bug 38936: Use redirect_if_opac_suppressed() in opac-*detail.pl pages 2025-09-29 14:02:23 -06:00
opac-MARCdetail.pl Bug 38936: Use redirect_if_opac_suppressed() in opac-*detail.pl pages 2025-09-29 14:02:23 -06:00
opac-account-pay-return.pl Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
opac-account-pay.pl Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
opac-account.pl Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
opac-addbybiblionumber.pl Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
opac-alert-subscribe.pl Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
opac-alert-subscriptions.pl Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
opac-article-request-cancel.pl Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
opac-authorities-home.pl Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
opac-authoritiesdetail.pl Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
opac-basket.pl Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
opac-blocked.pl Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
opac-browse.pl Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
opac-browser.pl Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
opac-changelanguage.pl Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
opac-course-details.pl Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
opac-course-reserves.pl Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
opac-curbside-pickups.pl Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
opac-detail.pl Bug 39482: Correct the link to edit OpacLibraryInfo from library edit page 2025-12-29 09:56:16 -07:00
opac-discharge.pl Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
opac-dismiss-message.pl Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
opac-downloadcart.pl Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
opac-downloadshelf.pl Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
opac-export.pl Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
opac-holdshistory.pl Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
opac-ics.pl Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
opac-idref.pl Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
opac-illrequests-unauthenticated.pl Bug 36197: (QA follow-up): Adopt POST REDIRECT GET pattern 2025-04-25 08:47:11 +02:00
opac-illrequests.pl Bug 41204: Fallback to Standard earlier 2026-02-06 15:17:15 -07:00
opac-image.pl Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
opac-imageviewer.pl Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
opac-issue-note.pl Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
opac-library.pl Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
opac-main.pl Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
opac-memberentry.pl Bug 41076: Adjust our perl tidiness for v20250105 2026-02-05 09:03:51 -07:00
opac-messaging.pl Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
opac-modrequest-suspend.pl Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
opac-modrequest.pl Bug 40929: Add $hold test in opac-modrequest 2025-10-06 09:15:19 -06:00
opac-mymessages.pl Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
opac-news-rss.pl Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
opac-overdrive-search.pl Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
opac-page.pl Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
opac-passwd.pl Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
opac-password-recovery.pl Bug 39325: Automatic fix 2025-04-28 18:51:22 +02:00
opac-patron-consent.pl Bug 41662: Prevent CSRF on opac-patron-consent.pl 2026-01-29 15:11:21 -07:00
opac-patron-image.pl Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
opac-privacy.pl Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
opac-ratings.pl Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
opac-readingrecord.pl Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
opac-recall.pl Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
opac-recalls.pl Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
opac-registration-verify.pl Bug 41076: Adjust our perl tidiness for v20250105 2026-02-05 09:03:51 -07:00
opac-renew.pl Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
opac-reportproblem.pl Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
opac-request-article.pl Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
opac-reserve.pl Bug 3492: Modernize hold fee system and migrate to circulation rules 2026-02-09 12:57:56 -07:00
opac-reset-password.pl Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
opac-restrictedpage.pl Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
opac-retrieve-file.pl Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
opac-review.pl Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
opac-routing-lists.pl Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
opac-search-history.pl Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
opac-search.pl Bug 40966: Make sure 'whole_record' and 'weighted_fields' are passed around 2026-02-06 15:17:17 -07:00
opac-sendbasket.pl Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
opac-sendshelf.pl Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
opac-serial-issues.pl Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
opac-shareshelf.pl Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
opac-shelves.pl Bug 41655: Local OPAC covers are not displayed in OPAC lists 2026-02-06 15:17:14 -07:00
opac-showmarc.pl Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
opac-showreviews.pl Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
opac-suggestions.pl Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
opac-tags.pl Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
opac-tags_subject.pl Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
opac-topissues.pl Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
opac-user.pl Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
opac-virtual-card.pl Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
tracklinks.pl Bug 40163: Fix several http addresses in the code docs 2025-09-23 16:21:29 -06:00
unapi Bug 40872: (follow-up) Tidy opac/unapi 2025-09-24 09:25:06 -06:00