From d4d872d02364e9551f837f9e892f036e09e70a1e Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Tue, 4 Jan 2022 19:22:55 +0000 Subject: [PATCH] Bug 29792: Automatically send wrong transfers Bug 24434 reinstated the 'updateWrongTransfer' call here, but made the assertion that the transfer should not be sent until 'Ok' was clicked. I see how unsent transfers are useful for rotation, but I believe for wrong trasnfer we shouldn't require a confirm or print. If a library does want to, the 'transfersblockcirc' system preference will enforce clicking the button to continue To test: 1 - have an item in transit from Branch A to Branch B 2 - check the item in at Branch A 3 - get a Wrong Transfer message, click Print Slip or OK 4 - query the branchtransfers table, see that your original transfer was cancelled and a new one was made, confirm that new transfer has a datesent value 5 - repeat steps 1-3, but instead of clicking one of the buttons click outside of the modal to make it go away 6 - query the branchtransfers table, see that your original transfer was cancelled and a new one was made, confirm that new transfer DOES NOT HAVE a datesent value 7 - Apply patch 8 - Repeat the check in 9 - New transfer is generated and has 'datesent' set Signed-off-by: Andrew Fuerste-Henry --- C4/Circulation.pm | 3 ++- Koha/Item.pm | 1 + t/db_dependent/Circulation.t | 2 +- t/db_dependent/Koha/Item.t | 9 ++++++++- 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index c2edf81f94..b71284beae 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -3541,7 +3541,8 @@ sub updateWrongTransfer { reason => $transfer->reason, comment => $transfer->comments, ignore_limits => 1, - enqueue => 1 + enqueue => 1, + send_transfer => 1, } ); diff --git a/Koha/Item.pm b/Koha/Item.pm index d70fbc3f8f..b12578c556 100644 --- a/Koha/Item.pm +++ b/Koha/Item.pm @@ -464,6 +464,7 @@ sub request_transfer { { itemnumber => $self->itemnumber, daterequested => dt_from_string, + datesent => $params->{send_transfer} ? dt_from_string : undef, frombranch => $self->holdingbranch, tobranch => $params->{to}->branchcode, reason => $params->{reason}, diff --git a/t/db_dependent/Circulation.t b/t/db_dependent/Circulation.t index 3000753a92..e4a8662c5d 100755 --- a/t/db_dependent/Circulation.t +++ b/t/db_dependent/Circulation.t @@ -4912,7 +4912,7 @@ subtest "updateWrongTransfer tests" => sub { my $new_transfer = C4::Circulation::updateWrongTransfer($item->itemnumber, $library1->branchcode); is(ref($new_transfer), 'Koha::Item::Transfer', "updateWrongTransfer returns a 'Koha::Item::Transfer' object"); - ok( !$new_transfer->in_transit, "New transfer is NOT created as in transit (or cancelled)"); + ok( $new_transfer->in_transit, "New transfer is created as in transit"); my $original_transfer = $transfer->get_from_storage; ok( defined($original_transfer->datecancelled), "Original transfer was cancelled"); diff --git a/t/db_dependent/Koha/Item.t b/t/db_dependent/Koha/Item.t index db3ff9a987..68c653feea 100755 --- a/t/db_dependent/Koha/Item.t +++ b/t/db_dependent/Koha/Item.t @@ -489,7 +489,7 @@ subtest 'pickup_locations' => sub { }; subtest 'request_transfer' => sub { - plan tests => 13; + plan tests => 15; $schema->storage->txn_begin; my $library1 = $builder->build_object( { class => 'Koha::Libraries' } ); @@ -549,6 +549,13 @@ subtest 'request_transfer' => sub { is($transfers->count, 1, "There is only 1 live transfer in the queue"); $replaced_transfer->datearrived(dt_from_string)->store(); + $transfer = $item->request_transfer({ to => $library2, reason => 'Manual' }); + ok(!$transfer->datesent, "Transfer not marked as sent by default"); + $transfer->datearrived(dt_from_string)->store(); + $transfer = $item->request_transfer({ to => $library2, reason => 'Manual', send_transfer => 1 }); + ok($transfer->datesent, "Transfer marked as sent if send_transfer is passed"); + $transfer->datearrived(dt_from_string)->store(); + # BranchTransferLimits t::lib::Mocks::mock_preference('UseBranchTransferLimits', 1); t::lib::Mocks::mock_preference('BranchTransferLimitsType', 'itemtype'); -- 2.30.2