Bug 35612 - Record branch context in accountlines.branchcode for OVERDUE, LOST, and PROCESSING fees
Summary: Record branch context in accountlines.branchcode for OVERDUE, LOST, and PROCE...
Status: ASSIGNED
Alias: None
Product: Koha
Classification: Unclassified
Component: Fines and fees (show other bugs)
Version: Main
Hardware: All All
: P5 - low enhancement
Assignee: Laura Escamilla
QA Contact: Testopia
URL:
Keywords:
Depends on: 36506 39802
Blocks:
  Show dependency treegraph
 
Reported: 2023-12-20 11:18 UTC by Pirkko-Liisa Lauhikari
Modified: 2025-10-02 20:17 UTC (History)
2 users (show)

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


Attachments
Bug 35612: Added new AccountLinesBranchSource system preference (1.58 KB, patch)
2025-09-18 17:20 UTC, Laura Escamilla
Details | Diff | Splinter Review
Bug 35612: Added branch code logic (2.44 KB, patch)
2025-09-18 17:20 UTC, Laura Escamilla
Details | Diff | Splinter Review
Bug 35612: sysprefs.sql updates (2.35 KB, patch)
2025-09-18 17:20 UTC, Laura Escamilla
Details | Diff | Splinter Review
Bug 35612: Added the system preference within the Circulation and Fines policy in Administration (3.13 KB, patch)
2025-09-18 17:20 UTC, Laura Escamilla
Details | Diff | Splinter Review
Bug 35612: Tests (2.62 KB, patch)
2025-09-18 17:20 UTC, Laura Escamilla
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Pirkko-Liisa Lauhikari 2023-12-20 11:18:34 UTC
We would like to have branchcode recorded to the OVERDUE fees in accountlines table. Configurability is desired, so that it is possible to choose which library is recorded. Options could be customer's home library, issuing library and item's home library.
Comment 1 Pirkko-Liisa Lauhikari 2024-09-27 08:17:23 UTC
We hope also, that branchcode information for all customer fees lines.
Comment 2 Andrew Fuerste-Henry 2025-05-01 13:58:21 UTC
Agreed it would be helpful to consistently populate the branchcode for accountlines.

For overdues fines, I believe the branch used to calculate the fine is determined by the CircControl and HomeOrHoldingBranch system preferences. Accountlines should record the branch used to calculate the fine.

The longoverdue cron also follows CircControl but fails to record that branch in accountlines. It should do so.
Comment 3 Laura Escamilla 2025-09-18 17:20:06 UTC
Created attachment 186567 [details] [review]
Bug 35612: Added new AccountLinesBranchSource system preference
Comment 4 Laura Escamilla 2025-09-18 17:20:09 UTC
Created attachment 186568 [details] [review]
Bug 35612: Added branch code logic
Comment 5 Laura Escamilla 2025-09-18 17:20:12 UTC
Created attachment 186569 [details] [review]
Bug 35612: sysprefs.sql updates
Comment 6 Laura Escamilla 2025-09-18 17:20:14 UTC
Created attachment 186570 [details] [review]
Bug 35612: Added the system preference within the Circulation and Fines policy in Administration

To test:

1. Set system preferences:
    * FinesMode: Calculate and Charge
    * AccountLinesBranchSource: (this will be tested with different values later)
2. Set circulation rules:
    * Ensure a circulation rule exists that charges overdue fines for the item type and branch you're testing with.
3. Check out an item to a test patron with a due date in the past (to trigger overdue).
4.  Run the fines cronjob: perl /usr/share/koha/bin/cronjobs/fines.pl
5. Verify fines appear on the patron’s Accounting tab in the staff interface.
6. Confirm branchcode is NULL in the database:
    * SELECT accountlines_id, branchcode, debit_type_code FROM accountlines ORDER BY accountlines_id DESC LIMIT 10;
    * Expect to see branchcode = NULL for the OVERDUE debit.
7.  Apply the patch to your Koha instance.
8.  Run updatedatabase
9. Run restart_all
10. In the staff interface, go to Administration → System Preferences, search for AccountLinesBranchSource, and set it to: "the library the item was checked out from" (checkoutbranch)
11.  Repeat steps 3–6.
12.  Confirm that in the SQL output, the branchcode now matches the checkout branch of the item.
13. Repeat steps 10–12 with each of the following AccountLinesBranchSource values:
    * itemhomebranch: The item’s home library
    * patronhomebranch: The patron’s home library
    * checkoutbranch: The checkout library (already tested)
    * none: Should result in NULL branchcode
    * Confirm that: The correct branch is recorded in the branchcode field of accountlines. When set to none, branchcode is again NULL.
Comment 7 Laura Escamilla 2025-09-18 17:20:17 UTC
Created attachment 186571 [details] [review]
Bug 35612: Tests

run perl t/db_dependent/Koha/Account.t
Comment 8 Andrew Fuerste-Henry 2025-09-18 18:56:17 UTC
Rather than adding a system preference to determine which branch is used or recorded for a debit, the goal here is to allow the existing system preferences  -- CircControl, LostChargesControl (see bug 39802) -- to determine which branch's rules should be used to calculate the fee and then record that context in accountlines.
Comment 10 Andrew Fuerste-Henry 2025-10-02 20:17:00 UTC
I got so busy thinking about lost items I forgot that Pirkko-Liisa started this bug with OVERDUEs. OVERDUEs also fail to record the branch used to determine the fee and should also be covered in this work.