Bug 40331: Return existing transfer if requesting a new transfer that is identical

Currently request_transfer checks for the existence of a current transfer on the item, and a new one can either be
enqueued or replace this transfer. This patch adds a check to see if the requested transfer matches an existing transfer
on the item. In the case that it does we simply return that transfer rather than create a new transfer.

This has the effect of eliminating 'WrongTransfer' generation if an item is checked in twice at the same branch, which feels correct.

To test:
 1 - place a hold on an item that is currently at branch A, for pickup at branch B
 2 - check your item in at Branch A, click to confirm the hold and transfer (print slip if you want to)
 3 - sudo koha-mysql kohadev: SELECT * FROM branchtransfers -- See one transfer
 4 - check your item in at Branch A again, get a message that the item is supposed to go to Branch B. Don't click on the modal yet
 5 - repeat 3 -- See two transfers, one cancelled as WrongTransfer, one pending
 6 - Click 'Confirm and transfer' on the modal
 7 - repeat 3 -- See three tranfers - the two from before and a new active transfer
 8 - DELETE FROM branchtransfers
 9 - Apply patch, restart all
10 - repeat 3 - no transfers
11 - Check item in at branch A again and confirm
12 - repeat 3, one transfer
13 - Check item in, don't confirm the modal
14 - repeat 3, one transfer
15 - Confirm the modal
16 - repeat 3, one transfer
17 - Check the item in at branch C
18 - repeat 3, two transfers - one cancelled WrongTransfer, one active
19 - Confirm modal
20 - repeat 3, two transfers
21 - Check item in at branch B
22 - repeat 3, two transfers, one cancelled, one completed

Signed-off-by: Christine Lee <chlee@pascolibraries.org>
Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
(cherry picked from commit acdc512cea)
Signed-off-by: Paul Derscheid <paul.derscheid@lmscloud.de>
This commit is contained in:
Nick Clemens 2025-07-25 13:36:33 +00:00 committed by Paul Derscheid
parent b71d4d3e94
commit 93b5d837cf
No known key found for this signature in database
GPG Key ID: C25F9FD44CED595B
2 changed files with 24 additions and 1 deletions

View File

@ -814,6 +814,18 @@ sub request_transfer {
}
}
my $matching_transfers = Koha::Item::Transfers->search(
{
tobranch => $params->{to}->branchcode,
frombranch => $self->holdingbranch,
itemnumber => $self->itemnumber,
reason => $params->{reason},
datearrived => undef,
datecancelled => undef
}
);
return $matching_transfers->next if $matching_transfers->count;
Koha::Exceptions::Item::Transfer::Limit->throw()
unless ( $params->{ignore_limits}
|| $self->can_be_transferred( { to => $params->{to} } ) );

View File

@ -1119,7 +1119,7 @@ subtest 'pickup_locations() tests' => sub {
subtest 'request_transfer() tests' => sub {
plan tests => 18;
plan tests => 20;
$schema->storage->txn_begin;
@ -1174,6 +1174,17 @@ subtest 'request_transfer() tests' => sub {
my $original_transfer = $transfer->get_from_storage;
# Duplicated request
$transfer = $item->request_transfer( { to => $library1, reason => 'Manual' } );
is(
ref($transfer), 'Koha::Item::Transfer',
'Koha::Item->request_transfer should return a Koha::Item::Transfer object'
);
is(
$transfer->branchtransfer_id, $original_transfer->branchtransfer_id,
"When a matching transfer is requested we update the existing one"
);
# Transfer already in progress
throws_ok { $item->request_transfer( { to => $library2, reason => 'Manual' } ) }
'Koha::Exceptions::Item::Transfer::InQueue',