Bug 35612: (QA follow-up) Document undef handling in branch_for_fee_context

Improves POD documentation for branch_for_fee_context to:
- Document all parameters (patron, item, issue objects)
- Explain the resolution logic for each control preference
- Clarify that returning undef is acceptable behavior
- Note how undef is handled by calling code

Adds inline comment explaining that undef return value is
gracefully handled by Koha::Account->add_debit.

This addresses concerns about unclear undef handling and
improves maintainability.

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
This commit is contained in:
Martin Renvoize 2026-02-05 08:14:51 +00:00 committed by Lucas Gass
parent 73ae8a15db
commit 30510e1d0a
No known key found for this signature in database
GPG Key ID: 60B447398B0D36CA
1 changed files with 29 additions and 3 deletions

View File

@ -344,10 +344,33 @@ sub claim_returned {
=head2 branch_for_fee_context
my $branchcode = Koha::Checkout->branch_for_fee_context(
fee_type => 'OVERDUE' | 'LOST' | 'PROCESSING',
);
fee_type => 'OVERDUE' | 'LOST' | 'PROCESSING',
patron => $patron_obj, # Koha::Patron object or hashref
item => $item_obj, # Koha::Item object or hashref
issue => $issue_obj, # Koha::Checkout object or hashref (optional)
);
Determines which branch’s rules should apply to a fee based on system preferences and available context. For LOST/PROCESSING it honors LostChargesControl; for OVERDUE it honors CircControl. It also respects HomeOrHoldingBranch when choosing the item’s branch. Returns a branchcode (string) or undef if it cannot be determined.
Determines which branch's rules should apply to a fee based on system preferences
and available context.
For LOST/PROCESSING fees, honors LostChargesControl preference:
- PatronLibrary: Uses patron's home branch
- PickupLibrary: Uses checkout branch (falls back to patron, then item)
- ItemHomeLibrary: Uses item's home or holding branch (per HomeOrHoldingBranch pref)
For OVERDUE fees, honors CircControl preference (same values as above).
B<Parameters:>
- fee_type: 'OVERDUE', 'LOST', or 'PROCESSING' (defaults to 'OVERDUE')
- patron: Koha::Patron object or hashref with branchcode
- item: Koha::Item object or hashref with homebranch/holdingbranch
- issue: Koha::Checkout object or hashref with branchcode (optional)
B<Returns:> A branchcode (string) or C<undef> if no branch can be determined.
B<Note:> Returning C<undef> is acceptable - calling code should handle this gracefully.
When passed to Koha::Account->add_debit as library_id, undef indicates no specific
branch context is available for the fee.
=cut
@ -384,6 +407,9 @@ sub branch_for_fee_context {
: ( defined $control_pref && $control_pref eq 'PickupLibrary' )
? ( $issuing_branch // $patron_branch // $item_branch )
: $item_branch; # ItemLibrary (default)
# May return undef if no branch context is available - this is acceptable
# and handled gracefully by Koha::Account->add_debit
return $resolved;
}