Bugzilla – Attachment 125704 Details for
Bug 27945
Limit the number of active article requests per patron category
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 27945: Clarify 'same day' behavior
Bug-27945-Clarify-same-day-behavior.patch (text/plain), 4.59 KB, created by
Tomás Cohen Arazi (tcohen)
on 2021-10-04 15:15:37 UTC
(
hide
)
Description:
Bug 27945: Clarify 'same day' behavior
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2021-10-04 15:15:37 UTC
Size:
4.59 KB
patch
obsolete
>From ce6f3050b0fd3b480f7020ef31f7d1a6aea1693d Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Thu, 30 Sep 2021 15:57:00 -0300 >Subject: [PATCH] Bug 27945: Clarify 'same day' behavior > >This patch introduces tests for the 'same day' check of the ability to >place article requests for a patron. > >The limit goes against current requests, and those that have been >completed on the same day. The tests cover this specific situation. > >The current behavior is that it takes into account a 24 hr timespan, but >consensus on the QA step was that we should do it as 'same day' and use >a separate feature request to change this, if required. > >To test: >1. Apply this patch >2. Run: > $ kshell > k$ prove t/db_dependent/Koha/Patron.t >=> SUCCESS: Tests pass! >3. Sign off :-D > >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> >--- > Koha/Patron.pm | 16 +++++------ > t/db_dependent/Koha/Patron.t | 54 +++++++++++++++++++++++++++++++++++- > 2 files changed, 61 insertions(+), 9 deletions(-) > >diff --git a/Koha/Patron.pm b/Koha/Patron.pm >index 967ae9a33b..7ffb11cbeb 100644 >--- a/Koha/Patron.pm >+++ b/Koha/Patron.pm >@@ -960,9 +960,10 @@ sub move_to_deleted { > > =head3 can_request_article > >-my $can_request = $borrower->can_request_article >+ if ( $patron->can_request_article ) { ... } > >-Returns true if patron can request articles >+Returns true if the patron can request articles. As limits apply for the patron >+on on the same day, those completed the same day are considered as current. > > =cut > >@@ -972,12 +973,11 @@ sub can_request_article { > > return 1 unless defined $limit; > >- my $dtf = Koha::Database->new->schema->storage->datetime_parser; >- my $compdate = dt_from_string->add( days => -1 ); >- my $count = Koha::ArticleRequests->search([ >- { borrowernumber => $self->borrowernumber, status => ['REQUESTED','PENDING','PROCESSING'] }, >- { borrowernumber => $self->borrowernumber, status => 'COMPLETED', updated_on => { '>', $dtf->format_date($compdate) }}, >- ])->count; >+ my $count = Koha::ArticleRequests->search( >+ [ { borrowernumber => $self->borrowernumber, status => [ 'REQUESTED', 'PENDING', 'PROCESSING' ] }, >+ { borrowernumber => $self->borrowernumber, status => 'COMPLETED', updated_on => { '>=' => \'CAST(NOW() AS DATE)' } }, >+ ] >+ )->count; > return $count < $limit ? 1 : 0; > } > >diff --git a/t/db_dependent/Koha/Patron.t b/t/db_dependent/Koha/Patron.t >index b088d2a5b2..0d62df241c 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 => 9; >+use Test::More tests => 10; > use Test::Exception; > use Test::Warn; > >@@ -831,3 +831,55 @@ subtest 'can_request_article() tests' => sub { > > $schema->storage->txn_rollback; > }; >+ >+subtest 'can_request_article() tests' => sub { >+ >+ plan tests => 3; >+ >+ $schema->storage->txn_begin; >+ >+ my $category = $builder->build_object( >+ { >+ class => 'Koha::Patron::Categories', >+ value => { article_request_limit => 4 } >+ } >+ ); >+ my $patron = $builder->build_object( >+ { >+ class => 'Koha::Patrons', >+ value => { categorycode => $category->id } >+ } >+ ); >+ >+ $builder->build_object( { class => 'Koha::ArticleRequests', value => { status => 'REQUESTED', borrowernumber => $patron->id } } ); >+ $builder->build_object( { class => 'Koha::ArticleRequests', value => { status => 'PENDING', borrowernumber => $patron->id } } ); >+ $builder->build_object( { class => 'Koha::ArticleRequests', value => { status => 'PROCESSING', borrowernumber => $patron->id } } ); >+ $builder->build_object( { class => 'Koha::ArticleRequests', value => { status => 'CANCELED', borrowernumber => $patron->id } } ); >+ >+ ok( $patron->can_request_article, 'Patron has 3 current requests, 4 is the limit: allowed' ); >+ >+ # Completed request, same day >+ my $completed = $builder->build_object( >+ { >+ class => 'Koha::ArticleRequests', >+ value => { >+ status => 'COMPLETED', >+ borrowernumber => $patron->id >+ } >+ } >+ ); >+ >+ ok( !$patron->can_request_article, 'Patron has 3 current requests and a completed one the same day: denied' ); >+ >+ $completed->updated_on( >+ dt_from_string->add( days => -1 )->set( >+ hour => 23, >+ minute => 59, >+ second => 59, >+ ) >+ )->store; >+ >+ ok( $patron->can_request_article, 'Patron has 3 current requests and a completed one the day before: allowed' ); >+ >+ $schema->storage->txn_rollback; >+}; >-- >2.32.0
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 27945
:
123217
|
123218
|
123219
|
123220
|
123714
|
123715
|
123774
|
123775
|
123776
|
123777
|
123778
|
123820
|
124066
|
124067
|
124068
|
124069
|
124070
|
124071
|
124072
|
124073
|
124074
|
124075
|
124076
|
124077
|
124078
|
124079
|
124284
|
124285
|
124633
|
124673
|
124674
|
124675
|
124676
|
124677
|
124678
|
124679
|
124680
|
124681
|
124682
|
125140
|
125142
|
125143
|
125144
|
125145
|
125146
|
125147
|
125148
|
125149
|
125150
|
125151
|
125152
|
125178
|
125179
|
125569
|
125571
|
125638
|
125690
|
125702
|
125703
| 125704 |
125705
|
125706
|
125707
|
125726
|
125741
|
125761