From f5d135b8a7ab7faf7141025631b184725dba2a6a Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Wed, 6 Oct 2021 14:02:35 -0300 Subject: [PATCH] Bug 29084: Remove article_requests_finished and article_requests_current This patch removes those methods that are not really needed. Templates are adjusted to use the expected combination of ->article_requests->filter_by_current. To test: 1. Apply this patch 2. Visit a biblio with article requests => SUCCESS: All works 3. Run: $ kshell k$ prove t/db_dependent/Koha/Biblio.t => SUCCESS: Tests pass, less tests. 4. Sign off :-D --- Koha/Biblio.pm | 28 ------ .../prog/en/modules/circ/request-article.tt | 6 +- t/db_dependent/Koha/Biblio.t | 88 +------------------ 3 files changed, 5 insertions(+), 117 deletions(-) diff --git a/Koha/Biblio.pm b/Koha/Biblio.pm index 97b6f49366..f53d372ee9 100644 --- a/Koha/Biblio.pm +++ b/Koha/Biblio.pm @@ -354,34 +354,6 @@ sub article_requests { return Koha::ArticleRequests->_new_from_dbic( scalar $self->_result->article_requests ); } -=head3 article_requests_current - - my $current_article_requests = $biblio->article_requests_current - -Returns the article requests associated with this biblio that are incomplete - -=cut - -sub article_requests_current { - my ( $self ) = @_; - - return $self->article_requests->filter_by_current; -} - -=head3 article_requests_finished - - my $finished_article_requests = $biblio->article_requests_finished - -Returns the article requests associated with this biblio that are completed - -=cut - -sub article_requests_finished { - my ( $self, $borrower ) = @_; - - return $self->article_requests->filter_by_finished; -} - =head3 items my $items = $biblio->items(); diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/request-article.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/request-article.tt index 7c2ea0fdb1..5ab9d5a079 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/request-article.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/request-article.tt @@ -1,5 +1,6 @@ [% USE raw %] [% USE Asset %] +[% USE Context %] [% USE KohaDates %] [% USE Branches %] [% USE ItemTypes %] @@ -284,7 +285,8 @@ [% END %] - [% IF biblio.article_requests_current && !patron %] + [% SET biblio_current_article_requests = Context.Scalar( Context.Scalar( biblio, 'article_requests' ), 'filter_by_current' ) %] + [% IF biblio_current_article_requests.count > 0 && !patron %]
Current article requests @@ -307,7 +309,7 @@   - [% FOREACH ar IN biblio.article_requests_current %] + [% FOREACH ar IN biblio_current_article_requests %] [% ar.created_on | $KohaDates %] [% ar.borrower.firstname | html %] [% ar.borrower.surname | html %] diff --git a/t/db_dependent/Koha/Biblio.t b/t/db_dependent/Koha/Biblio.t index ce16b9bd3a..893608d933 100755 --- a/t/db_dependent/Koha/Biblio.t +++ b/t/db_dependent/Koha/Biblio.t @@ -17,7 +17,7 @@ use Modern::Perl; -use Test::More tests => 18; +use Test::More tests => 16; use C4::Biblio qw( AddBiblio ModBiblio ); use Koha::Database; @@ -724,89 +724,3 @@ subtest 'article_requests() tests' => sub { $schema->storage->txn_rollback; }; - -subtest 'article_requests_current() tests' => sub { - - plan tests => 7; - - $schema->storage->txn_begin; - - my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); - my $item = $builder->build_sample_item; - my $biblio = $item->biblio; - - my $article_request = Koha::ArticleRequest->new( - { - borrowernumber => $patron->id, - biblionumber => $biblio->id, - itemnumber => $item->id, - title => $biblio->title, - } - )->request(); - - my $ar = $biblio->article_requests(); - is( ref($ar), 'Koha::ArticleRequests', - '$biblio->article_requests returns Koha::ArticleRequests object' ); - is( $ar->next->id, $article_request->id, - 'Returned article request matches' ); - - is( $biblio->article_requests_current()->count(), - 1, 'Open request returned for article_requests_current' ); - $article_request->set_pending(); - is( $biblio->article_requests_current()->count(), - 1, 'Pending request returned for article_requests_current' ); - $article_request->process(); - is( $biblio->article_requests_current()->count(), - 1, 'Processing request returned for article_requests_current' ); - $article_request->complete(); - is( $biblio->article_requests_current()->count(), - 0, 'Completed request not returned for article_requests_current' ); - $article_request->cancel(); - is( $biblio->article_requests_current()->count(), - 0, 'Canceled request not returned for article_requests_current' ); - - $schema->storage->txn_rollback; -}; - -subtest 'article_requests_finished() tests' => sub { - - plan tests => 7; - - $schema->storage->txn_begin; - - my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); - my $item = $builder->build_sample_item; - my $biblio = $item->biblio; - - my $article_request = Koha::ArticleRequest->new( - { - borrowernumber => $patron->id, - biblionumber => $biblio->id, - itemnumber => $item->id, - title => $biblio->title, - } - )->request(); - - my $ar = $biblio->article_requests(); - is( ref($ar), 'Koha::ArticleRequests', - '$biblio->article_requests returns Koha::ArticleRequests object' ); - is( $ar->next->id, $article_request->id, - 'Returned article request matches' ); - - is( $biblio->article_requests_finished->count, - 0, 'Open request returned for article_requests_finished' ); - $article_request->set_pending(); - is( $biblio->article_requests_finished->count, - 0, 'Pending request returned for article_requests_finished' ); - $article_request->process(); - is( $biblio->article_requests_finished->count, - 0, 'Processing request returned for article_requests_finished' ); - $article_request->complete(); - is( $biblio->article_requests_finished->count, - 1, 'Completed request returned for article_requests_finished' ); - $article_request->cancel(); - is( $biblio->article_requests_finished->count, - 1, 'Cancelled request not returned for article_requests_finished' ); - - $schema->storage->txn_rollback; -}; -- 2.32.0