From c94b98bf94a2a05d7d5a5bcb687541a5c77a4295 Mon Sep 17 00:00:00 2001 From: Emily Lamancusa Date: Thu, 24 Oct 2024 11:24:11 -0400 Subject: [PATCH] Bug 22421: (follow-up): Check issue during add_credit Additional handling for the case where a credit is added with an issue_id after the issue is returned. add_credit will keep the same method signature, where the issue_id parameter may now refer to a current issue or an old issue. It will then internally determine whether it is a current or old checkout and handle it appropriately. If the caller is updating an account line, or adding a credit to refund an existing debit, they may not need to know whether it is for a current checkout or an old checkout. In this case, they can use the account line's ->checkout accessor to pass in the appropriate issue_id regardless of whether it is a current or old checkout. Signed-off-by: Martin Renvoize --- Koha/Account.pm | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/Koha/Account.pm b/Koha/Account.pm index e3a2ef7f376..41be5dd8c28 100644 --- a/Koha/Account.pm +++ b/Koha/Account.pm @@ -224,6 +224,16 @@ sub add_credit { 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; + } + } + Koha::Exceptions::Account::RegisterRequired->throw() if ( C4::Context->preference("UseCashRegisters") && defined($payment_type) @@ -252,7 +262,16 @@ sub add_credit { branchcode => $library_id, register_id => $cash_register, itemnumber => $item_id, - issue_id => $issue_id, + ( + $issue_id + ? ( issue_id => $issue_id ) + : () + ), + ( + $old_issue_id + ? ( old_issue_id => $old_issue_id ) + : () + ), } )->store(); -- 2.47.0