From 2140e49df58615574c8c2f0ee295dd71547ca487 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Wed, 25 Oct 2017 14:24:18 -0400 Subject: [PATCH] Bug 19530: Prevent multiple transfers from existing for one item We have found multiple open branch transfers for a given item. While I'm not sure how it is happening at this point, it seems that it would make sense to cancel any existing branch transfers when initiating a new one. Test Plan: 1) prove t/db_dependent/Circulation/transfers.t Signed-off-by: Mark Tompsett Signed-off-by: Josef Moravec --- C4/Items.pm | 2 ++ t/db_dependent/Circulation/transfers.t | 19 ++++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/C4/Items.pm b/C4/Items.pm index a7154be..241aae0 100644 --- a/C4/Items.pm +++ b/C4/Items.pm @@ -622,6 +622,8 @@ sub ModItemTransfer { # Remove the 'shelving cart' location status if it is being used. CartToShelf( $itemnumber ) if ( C4::Context->preference("ReturnToShelvingCart") ); + $dbh->do("UPDATE branchtransfers SET datearrived = NOW(), comments = ? WHERE itemnumber = ?", undef, "Canceled, new transfer from $frombranch to $tobranch created", $itemnumber); + #new entry in branchtransfers.... my $sth = $dbh->prepare( "INSERT INTO branchtransfers (itemnumber, frombranch, datesent, tobranch) diff --git a/t/db_dependent/Circulation/transfers.t b/t/db_dependent/Circulation/transfers.t index df63437..dc3a9e8 100644 --- a/t/db_dependent/Circulation/transfers.t +++ b/t/db_dependent/Circulation/transfers.t @@ -23,10 +23,11 @@ use C4::Circulation; use Koha::Database; use Koha::DateUtils; use DateTime::Duration; +use Koha::Item::Transfers; use t::lib::TestBuilder; -use Test::More tests => 22; +use Test::More tests => 24; use Test::Deep; BEGIN { @@ -192,5 +193,21 @@ cmp_deeply( "Barcode and itemnumber for same item both generate same TransferSlip" ); +$dbh->do("DELETE FROM branchtransfers"); +ModItemTransfer( + $item_id1, + $branchcode_1, + $branchcode_2 +); +my $transfer = Koha::Item::Transfers->search()->next(); +ModItemTransfer( + $item_id1, + $branchcode_1, + $branchcode_2 +); +$transfer->{_result}->discard_changes; +ok( $transfer->datearrived, 'Date arrived is set when new transfer is initiated' ); +is( $transfer->comments, "Canceled, new transfer from $branchcode_1 to $branchcode_2 created" ); + $schema->storage->txn_rollback; -- 2.1.4