From 4807c4926c997c7788207efe7050834a90c17749 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Mon, 13 May 2024 13:32:17 +0100 Subject: [PATCH] Bug 22421: (follow-up) Check issue during add_debit We need additional handling for the case where a debt may be added with an issue_id after the issue is returned. This patch tries to fix that at a low level, but introduces new test failures in t/db_dependent/Circulation.t to be investigated. --- Koha/Account.pm | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/Koha/Account.pm b/Koha/Account.pm index 3d0fcee854b..e3a2ef7f376 100644 --- a/Koha/Account.pm +++ b/Koha/Account.pm @@ -486,6 +486,17 @@ sub add_debit { my $item_id = $params->{item_id}; my $issue_id = $params->{issue_id}; + my $old_issue_id; + if ( $issue_id ) { + my $issue = Koha::Checkouts->find($issue_id); + unless ( $issue ) { + my $old_issue = Koha::Old::Checkouts->find($issue_id); + $issue_id = undef; + $old_issue_id = $old_issue->id; + } + } + + my $line; my $schema = Koha::Database->new->schema; try { @@ -506,9 +517,18 @@ sub add_debit { manager_id => $user_id, interface => $interface, itemnumber => $item_id, - issue_id => $issue_id, - branchcode => $library_id, - register_id => $cash_register, + ( + $issue_id + ? ( issue_id => $issue_id ) + : () + ), + ( + $old_issue_id + ? ( old_issue_id => $old_issue_id ) + : () + ), + branchcode => $library_id, + register_id => $cash_register, ( $debit_type eq 'OVERDUE' ? ( status => 'UNRETURNED' ) -- 2.45.0