From 1a738278da31787c517a07503f5b470b02f32b5c Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Thu, 5 Feb 2026 08:14:51 +0000 Subject: [PATCH] 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. --- Koha/Checkout.pm | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/Koha/Checkout.pm b/Koha/Checkout.pm index 63d657a67e6..7c95a5d2a5f 100644 --- a/Koha/Checkout.pm +++ b/Koha/Checkout.pm @@ -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 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). -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. +B +- 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 A branchcode (string) or C if no branch can be determined. + +B Returning C 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; } -- 2.52.0