From bd7f0e24215a237c9f4c1ca4c51839bfeb2a472c Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Thu, 14 Jun 2018 11:41:53 +0100 Subject: [PATCH] Bug 20271: (QA follow-up) Restore original GetItem functionality The return value of GetItem had been changed (as it would now return deleted items as well as current items). This patch restores the original functionality (as we've not catered for all calls to GetItem independantly), restores the original test as well as adding a further test to catch the correct setting of deleted_on by DelItem Signed-off-by: Josef Moravec --- C4/Circulation.pm | 3 --- C4/Items.pm | 3 +++ t/db_dependent/Items.t | 6 ++++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index ec2bd7d..8e1bdc4 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -1806,9 +1806,6 @@ sub AddReturn { unless ($item) { return ( 0, { BadBarcode => $barcode } ); # no barcode means no item or borrower. bail out. } - if ($item->{deleted_on}) { - return ( 0, { BadBarcode => $barcode } ); - } my $itemnumber = $item->{ itemnumber }; my $itemtype = $item->{itype}; # GetItem called effective_itemtype diff --git a/C4/Items.pm b/C4/Items.pm index f3f5d5e..0e93052 100644 --- a/C4/Items.pm +++ b/C4/Items.pm @@ -146,6 +146,8 @@ Return item information, for a given itemnumber or barcode. The return value is a hashref mapping item column names to values. If C<$serial> is true, include serial publication data. +This accessor will not return deleted items. + =cut sub GetItem { @@ -160,6 +162,7 @@ sub GetItem { } return unless ( $item ); + return if ( $item->deleted_on ); my $data = $item->unblessed(); $data->{itype} = $item->effective_itemtype(); # set the correct itype diff --git a/t/db_dependent/Items.t b/t/db_dependent/Items.t index c1d74c5..0e42d28 100755 --- a/t/db_dependent/Items.t +++ b/t/db_dependent/Items.t @@ -45,7 +45,7 @@ my $location = 'My Location'; subtest 'General Add, Get and Del tests' => sub { - plan tests => 16; + plan tests => 17; $schema->storage->txn_begin; @@ -80,8 +80,10 @@ subtest 'General Add, Get and Del tests' => sub { # Delete item. DelItem({ biblionumber => $bibnum, itemnumber => $itemnumber }); + my $deletedItem = Koha::Items->find({ itemnumber => $itemnumber }); + isnt($deletedItem->deleted_on, undef, "Item marked deleted as expected."); my $getdeleted = GetItem($itemnumber); - isnt($getdeleted->{'deleted_on'}, undef, "Item deleted as expected."); + is($getdeleted->{'itemnumber'}, undef, "Item not returned by GetItem as expected."); ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $library->{branchcode}, holdingbranch => $library->{branchcode}, location => $location, permanent_location => 'my permanent location', itype => $itemtype->{itemtype} } , $bibnum); $getitem = GetItem($itemnumber); -- 2.1.4