Bug 28530: (QA follow-up) Fix branch transfer limits not checking alternate libraries

Fixed a pre-existing bug where branch transfer limits would prevent ANY
transfer if the optimal library was blocked, instead of trying the next
best candidate.

Original behavior:
- Sort candidates by best ratio
- Check if transfer to best candidate is allowed
- If not allowed: exit loop immediately (bug!) and return undef
- Result: No transfer created even if other valid candidates exist

Fixed behavior:
- Sort candidates by best ratio
- Check if transfer to best candidate is allowed
- If allowed: use that library and exit loop
- If not allowed: continue to next candidate
- Result: Uses the best ALLOWED candidate

This fix ensures that when branch transfer limits block the optimal
destination, the system will try the next-best option instead of
giving up entirely.

Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
This commit is contained in:
Martin Renvoize 2026-02-04 17:59:24 +00:00 committed by Lucas Gass
parent 7076f57bd8
commit 4a658430a3
No known key found for this signature in database
GPG Key ID: 60B447398B0D36CA
1 changed files with 6 additions and 2 deletions

View File

@ -234,8 +234,12 @@ sub lowest_ratio_library {
$item->$BranchTransferLimitsType
);
$transfer_branch = Koha::Libraries->find( $candidate->{branchcode} ) if $allowed;
last;
if ($allowed) {
$transfer_branch = Koha::Libraries->find( $candidate->{branchcode} );
last; # Found an allowed transfer, exit loop
}
# If not allowed, continue to next candidate
} else {
$transfer_branch = Koha::Libraries->find( $candidate->{branchcode} );
last;