From 07741c30b64e420343c44cfcb2c8824b01b53154 Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Wed, 19 Aug 2020 16:52:13 +0200 Subject: [PATCH] Bug 21260: Introduce local pref to affect status grouping Introducing a local preference Available_NFL to control which not for loan statuses are considered to be 'available for reference'. Standard value is '1|2' which comes down to the former >0 when using the initial Koha defaults. Test plan: [1] Pick a biblio with an available item A, an item B with notforloan 1, an item C with notforloan 2 and two damaged items. (Former patch.) Include it in a OPAC search. You should see: Available: A. Reference: B, C. Not-available: Damaged(2). [2] Add local pref Available_NFL with value '1'. Repeat the search. You should see now: Available: A. Reference: B. Not-available: S.C.(1), Damaged(2). [where S.C. stands for Staff Collection] [3] Run test t/db_dependent/XSLT.t Signed-off-by: Marcel de Rooy Signed-off-by: ava li Signed-off-by: Martin Renvoize Signed-off-by: Jonathan Druart --- C4/XSLT.pm | 11 ++++++++--- t/db_dependent/XSLT.t | 12 ++++++++++-- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/C4/XSLT.pm b/C4/XSLT.pm index 0484c2b733..cd183fbe51 100644 --- a/C4/XSLT.pm +++ b/C4/XSLT.pm @@ -316,6 +316,7 @@ sub buildKohaItemsNamespace { my $itemtypes = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search->unblessed } }; my $xml = ''; my %descs = map { $_->{authorised_value} => $_ } Koha::AuthorisedValues->get_descriptions_by_koha_field( { kohafield => 'items.notforloan' } ); + my $ref_status = C4::Context->preference('Available_NFL') || '1|2'; for my $item (@items) { my $status; @@ -343,13 +344,17 @@ sub buildKohaItemsNamespace { $status = "Checked out"; } elsif ( $item->notforloan ) { - $status = $item->notforloan < 0 ? "reallynotforloan" : "reference"; - $substatus = exists $descs{$item->notforloan} ? $descs{$item->notforloan}->{opac_description} : "Not for loan_".$item->notforloan; + $status = $item->notforloan =~ /^($ref_status)$/ + ? "reference" + : "reallynotforloan"; + $substatus = exists $descs{$item->notforloan} ? $descs{$item->notforloan}->{opac_description} : "Not for loan"; } elsif ( exists $itemtypes->{ $item->effective_itemtype } && $itemtypes->{ $item->effective_itemtype }->{notforloan} == 1 ) { - $status = "reference"; + $status = "1" =~ /^($ref_status)$/ + ? "reference" + : "reallynotforloan"; $substatus = "Not for loan"; } else { diff --git a/t/db_dependent/XSLT.t b/t/db_dependent/XSLT.t index befce88e5c..16487db5ec 100755 --- a/t/db_dependent/XSLT.t +++ b/t/db_dependent/XSLT.t @@ -34,7 +34,10 @@ my $builder = t::lib::TestBuilder->new; $schema->storage->txn_begin; subtest 'buildKohaItemsNamespace status tests' => sub { - plan tests => 13; + plan tests => 14; + + t::lib::Mocks::mock_preference('Available_NFL', '1|2'); + my $itype = $builder->build_object({ class => 'Koha::ItemTypes' }); my $itemtype = $builder->build_object({ class => 'Koha::ItemTypes' }); my $item = $builder->build_sample_item({ itype => $itype->itemtype }); @@ -45,7 +48,6 @@ subtest 'buildKohaItemsNamespace status tests' => sub { # notforloan { - t::lib::Mocks::mock_preference('item-level_itypes', 0); $item->notforloan(0)->store; Koha::ItemTypes->find($item->itype)->notforloan(0)->store; @@ -69,6 +71,12 @@ subtest 'buildKohaItemsNamespace status tests' => sub { $item->notforloan(1)->store; $xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]); like($xml,qr{reference},"reference if positive notforloan value"); + + # But now make status notforloan==1 count under Not available + t::lib::Mocks::mock_preference('Available_NFL', '2'); + $xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]); + like($xml,qr{reallynotforloan},"reallynotforloan when we change Avaiable_NFL"); + t::lib::Mocks::mock_preference('Available_NFL', '1|2'); } $item->onloan('2001-01-01')->store; -- 2.39.5