From 1dae07e8c55de438dc66ae502b9d5e9768d8a837 Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Mon, 26 Mar 2018 13:20:53 +0200 Subject: [PATCH] Bug 20469: Add item status to staff article request form A method Koha::Item->is_waiting_or_transit is added (with tests). The template checks if an item is checked out, on hold (waiting or transit), or is available. (Note: This can be extended in the future in a general include as we have at opac side.) Test plan: [1] Run t/db_dependent/Koha/Items.t [2] Place an article request on an item on loan. Verify status on form. [3] Place an article request on a waiting item. Check status again. Signed-off-by: Marcel de Rooy Signed-off-by: Owen Leonard --- Koha/Item.pm | 12 ++++++++++++ .../prog/en/modules/circ/article-requests.tt | 8 ++++++++ t/db_dependent/Koha/Items.t | 18 ++++++++++++++++-- 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/Koha/Item.pm b/Koha/Item.pm index 964359ecf8..45f8995016 100644 --- a/Koha/Item.pm +++ b/Koha/Item.pm @@ -282,6 +282,18 @@ sub current_holds { return Koha::Holds->_new_from_dbic($hold_rs); } +=head3 is_waiting_or_transit + + Returns true if an item has a waiting or transit hold + +=cut + +sub is_waiting_or_transit { + my ( $self ) = @_; + return 1 if Koha::Holds->search({ itemnumber => $self->itemnumber, found => ['W', 'T'] })->count > 0; + return q{}; +} + =head3 type =cut diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/article-requests.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/article-requests.tt index 8a2a0731c3..db0f2068cb 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/article-requests.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/article-requests.tt @@ -42,6 +42,12 @@ [% END %] +[% BLOCK item_status %][%# pass Koha::Item into myitem %] + [% IF myitem.onloan %]Checked out + [% ELSIF myitem.is_waiting_or_transit %]On hold + [% ELSE %]Available + [% END %] +[% END %] [% INCLUDE 'header.inc' %] @@ -176,6 +182,7 @@ [% END %] [% ar.item.itemcallnumber %] +

[% PROCESS 'item_status' myitem = ar.item %]

[% ar.item.copynumber %] [% ar.item.enumchron %] @@ -284,6 +291,7 @@ [% END %] [% ar.item.itemcallnumber %] +

[% PROCESS 'item_status' myitem = ar.item %]

[% ar.item.copynumber %] [% ar.item.enumchron %] diff --git a/t/db_dependent/Koha/Items.t b/t/db_dependent/Koha/Items.t index 87ebfb3718..51f1213654 100644 --- a/t/db_dependent/Koha/Items.t +++ b/t/db_dependent/Koha/Items.t @@ -19,7 +19,7 @@ use Modern::Perl; -use Test::More tests => 9; +use Test::More tests => 10; use Test::Exception; use C4::Circulation; @@ -34,7 +34,7 @@ use t::lib::Mocks; my $schema = Koha::Database->new->schema; $schema->storage->txn_begin; -my $builder = t::lib::TestBuilder->new; +our $builder = t::lib::TestBuilder->new; my $biblioitem = $builder->build( { source => 'Biblioitem' } ); my $library = $builder->build( { source => 'Branch' } ); my $nb_of_items = Koha::Items->search->count; @@ -164,5 +164,19 @@ subtest 'can_be_transferred' => sub { $retrieved_item_1->delete; is( Koha::Items->search->count, $nb_of_items + 1, 'Delete should have deleted the item' ); +subtest 'is_waiting_or_transit' => sub { + plan tests => 3; + + my $hold = $builder->build_object({ class => 'Koha::Holds', value => { found => 'W' } }); + is( Koha::Items->find($hold->itemnumber)->is_waiting_or_transit, 1, + 'Item is waiting' ); + $hold->found('T')->store; + is( Koha::Items->find($hold->itemnumber)->is_waiting_or_transit, 1, + 'Item has transit hold' ); + $hold->found(undef)->store; + is( Koha::Items->find($hold->itemnumber)->is_waiting_or_transit, q{}, + 'Item should be available' ); +}; + $schema->storage->txn_rollback; -- 2.11.0