Bug 43346: MarkIssueReturned with no userenv

Since it is not clear what checkin_library signifies when marking an
issue on a lost item as returned we might as well fallback on setting
it to the issuing library when there is no userenv.

Test plan

* Run the unit test t/db_dependent/Koha/Account/Line.t

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Jason Robb <jrobb@sekls.org>
Signed-off-by: Pedro Amorim <pedro.amorim@openfifth.co.uk>
This commit is contained in:
Andreas Jonsson 2026-08-20 12:08:20 +02:00 committed by Pedro Amorim
parent 7dbc37e187
commit efb310cda0
No known key found for this signature in database
GPG Key ID: 06B75BA7F3894D55
1 changed files with 4 additions and 2 deletions

View File

@ -3002,7 +3002,7 @@ sub MarkIssueReturned {
my $schema = Koha::Database->schema;
# FIXME Improve the return value and handle it from callers
$schema->txn_do(
my $rv = $schema->txn_do(
sub {
my $patron = Koha::Patrons->find($borrowernumber);
@ -3014,7 +3014,9 @@ sub MarkIssueReturned {
$issue->returndate( \'NOW()' )->store->discard_changes; # update and refetch
}
$issue->checkin_library( C4::Context->userenv->{'branch'} );
my $checkin_library = defined C4::Context->userenv
&& exists C4::Context->userenv->{'branch'} ? C4::Context->userenv->{'branch'} : $issue->branchcode;
$issue->checkin_library($checkin_library);
# Create the old_issues entry
my $old_checkout = Koha::Old::Checkout->new( $issue->unblessed )->store;