From b642297148a7fa22616c293e200092d754475e76 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Wed, 6 Oct 2021 13:05:07 -0300 Subject: [PATCH] Bug 29083: 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 patron with article requests => SUCCESS: All works 3. Run: $ kshell k$ prove t/db_dependent/Koha/Patron.t => SUCCESS: Tests pass, less tests. 4. Sign off :-D Signed-off-by: Tomas Cohen Arazi --- Koha/Patron.pm | 28 ------ .../en/includes/patron-article-requests.inc | 6 +- .../prog/en/modules/members/moremember.tt | 4 +- .../bootstrap/en/modules/opac-user.tt | 2 +- opac/opac-user.pl | 2 +- t/db_dependent/Koha/Patron.t | 86 +------------------ 6 files changed, 10 insertions(+), 118 deletions(-) diff --git a/Koha/Patron.pm b/Koha/Patron.pm index ec64d00370..9fd93e8c44 100644 --- a/Koha/Patron.pm +++ b/Koha/Patron.pm @@ -1015,34 +1015,6 @@ sub article_requests { return Koha::ArticleRequests->_new_from_dbic( scalar $self->_result->article_requests ); } -=head3 article_requests_current - - my $current_article_requests = $patron->article_requests_current - -Returns the article requests associated with this patron 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 patron that are completed - -=cut - -sub article_requests_finished { - my ( $self ) = @_; - - return $self->article_requests->filter_by_finished; -} - =head3 add_enrolment_fee_if_needed my $enrolment_fee = $patron->add_enrolment_fee_if_needed($renewal); diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/patron-article-requests.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/patron-article-requests.inc index b2a25a0580..a22325e785 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/patron-article-requests.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/patron-article-requests.inc @@ -1,5 +1,7 @@ +[% USE Context %] +[% SET current_article_requests = Context.Scalar( Context.Scalar( patron, 'article_requests' ), 'filter_by_current' ) %]
-[% IF patron.article_requests_current.count %] +[% IF current_article_requests.count > 0 %] @@ -20,7 +22,7 @@ - [% FOREACH ar IN patron.article_requests_current %] + [% FOREACH ar IN current_article_requests %]
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt index 300d642bea..55c4d8e740 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt @@ -1,5 +1,6 @@ [% USE raw %] [% USE Asset %] +[% USE Context %] [% USE Koha %] [% USE Branches %] [% USE ItemTypes %] @@ -695,8 +696,9 @@ [% END %] [% IF Koha.Preference('ArticleRequests') %] + [% SET article_requests = Context.Scalar( Context.Scalar( patron, 'article_requests' ), 'filter_by_current') %]
  • - [% patron.article_requests_current.count | html %] Article requests + [% article_requests.count | html %] Article requests
  • [% END %] diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-user.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-user.tt index ece7aee244..dac477d909 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-user.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-user.tt @@ -866,7 +866,7 @@
    Article requests
    You have no article requests currently.
    - [% END # IF article_requests_current.count %] + [% END # IF current_article_requests_count %]
    [% END %] diff --git a/opac/opac-user.pl b/opac/opac-user.pl index 1cd97b628e..0515b162a3 100755 --- a/opac/opac-user.pl +++ b/opac/opac-user.pl @@ -387,7 +387,7 @@ if ( C4::Context->preference('AllowPatronToSetFinesVisibilityForGuarantor') } if ( C4::Context->preference("ArticleRequests") ) { - my @current_article_requests = $patron->article_requests_current->as_list; + my @current_article_requests = $patron->article_requests->filter_by_current->as_list; $template->param( current_article_requests => \@current_article_requests, current_article_requests_count => scalar @current_article_requests, diff --git a/t/db_dependent/Koha/Patron.t b/t/db_dependent/Koha/Patron.t index 8142e0c848..2929349661 100755 --- a/t/db_dependent/Koha/Patron.t +++ b/t/db_dependent/Koha/Patron.t @@ -19,7 +19,7 @@ use Modern::Perl; -use Test::More tests => 12; +use Test::More tests => 10; use Test::Exception; use Test::Warn; @@ -846,87 +846,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 $article_request = Koha::ArticleRequest->new( - { - borrowernumber => $patron->id, - biblionumber => $item->biblionumber, - itemnumber => $item->itemnumber, - title => "Boo", - } - )->request(); - - my $ar = $patron->article_requests(); - is( ref($ar), 'Koha::ArticleRequests', - '$patron->article_requests returns Koha::ArticleRequests object' ); - is( $ar->next->id, $article_request->id, - 'Returned article request matches' ); - - is( $patron->article_requests_current()->count(), - 1, 'Open request returned for article_requests_current' ); - $article_request->set_pending(); - is( $patron->article_requests_current()->count(), - 1, 'Pending request returned for article_requests_current' ); - $article_request->process(); - is( $patron->article_requests_current()->count(), - 1, 'Processing request returned for article_requests_current' ); - $article_request->complete(); - is( $patron->article_requests_current()->count(), - 0, 'Completed request not returned for article_requests_current' ); - $article_request->cancel(); - is( $patron->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 $article_request = Koha::ArticleRequest->new( - { - borrowernumber => $patron->id, - biblionumber => $item->biblionumber, - itemnumber => $item->itemnumber, - title => "Boo", - } - )->request(); - - my $ar = $patron->article_requests(); - is( ref($ar), 'Koha::ArticleRequests', - '$patron->article_requests returns Koha::ArticleRequests object' ); - is( $ar->next->id, $article_request->id, - 'Returned article request matches' ); - - is( $patron->article_requests_finished->count, - 0, 'Open request returned for article_requests_finished' ); - $article_request->set_pending(); - is( $patron->article_requests_finished->count, - 0, 'Pending request returned for article_requests_finished' ); - $article_request->process(); - is( $patron->article_requests_finished->count, - 0, 'Processing request returned for article_requests_finished' ); - $article_request->complete(); - is( $patron->article_requests_finished->count, - 1, 'Completed request returned for article_requests_finished' ); - $article_request->cancel(); - is( $patron->article_requests_finished->count, - 1, 'Cancelled request not returned for article_requests_finished' ); - - $schema->storage->txn_rollback; -}; -- 2.32.0