From bd459d908928c1a37f1d181923157d7c4a04d785 Mon Sep 17 00:00:00 2001 From: Lucas Gass Date: Thu, 18 Jan 2024 19:14:48 +0000 Subject: [PATCH] Bug 16122: AddReturn unit tests and small fix in sub AddReturn Signed-off-by: Andrew Fuerste-Henry --- C4/Circulation.pm | 2 +- t/db_dependent/Circulation.t | 20 +++++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index 0e0a6d0a68..deeb737ee3 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -2159,7 +2159,7 @@ sub AddReturn { my $itemnumber = $item->itemnumber; my $itemtype = $item->effective_itemtype; - my $localuse_count = $item->localuse; + my $localuse_count = $item->localuse || 0; my $issue = $item->checkout; if ( $issue ) { diff --git a/t/db_dependent/Circulation.t b/t/db_dependent/Circulation.t index 5095afde73..35e795f075 100755 --- a/t/db_dependent/Circulation.t +++ b/t/db_dependent/Circulation.t @@ -6116,21 +6116,39 @@ subtest 'Tests for transfer not in transit' => sub { subtest 'Tests for RecordLocalUseOnReturn' => sub { - plan tests => 2; + plan tests => 5; t::lib::Mocks::mock_preference('RecordLocalUseOnReturn', 0); my $item = $builder->build_sample_item(); + my $item_2 = $builder->build_sample_item( + { + onloan => undef, + } + ); + $item->withdrawn(1)->itemlost(1)->store; my @return = AddReturn( $item->barcode, $item->homebranch, 0, undef ); is_deeply( \@return, [ 0, { NotIssued => $item->barcode, withdrawn => 1 }, undef, {} ], "RecordLocalUSeOnReturn is off, no local use recorded"); + AddReturn( $item_2->barcode, $item_2->homebranch ); + $item_2->discard_changes; # refresh + is( $item_2->localuse, undef , 'Without RecordLocalUseOnReturn no localuse is recorded.'); + t::lib::Mocks::mock_preference('RecordLocalUseOnReturn', 1); my @return2 = AddReturn( $item->barcode, $item->homebranch, 0, undef ); is_deeply( \@return2, [ 0, { NotIssued => $item->barcode, withdrawn => 1, LocalUse => 1 }, undef, {} ], "Local use is recorded"); + + AddReturn( $item_2->barcode, $item_2->homebranch ); + $item_2->discard_changes; # refresh + is( $item_2->localuse, 1 , 'With RecordLocalUseOnReturn localuse is recorded.'); + + AddReturn( $item_2->barcode, $item_2->homebranch ); + $item_2->discard_changes; # refresh + is( $item_2->localuse, 2 , 'With RecordLocalUseOnReturn localuse is recorded.'); }; subtest 'Test CanBookBeIssued param ignore_reserves (Bug 35322)' => sub { -- 2.30.2