Bug 17492: Add a warning about age being of-limits and a button to update it

This patch adds a warning if a patron's age is out of limits if an assigned category.
It also adds a button allowing to change the category.

Test plan:
1) Apply patch
2) Create a patron and assign him a category having age limits set
3) Change patron's age to be older/younger than category's limits
4) At "Check out" and "Details" tabs you should see a warning with a
button allowing to change the category, eg.:
 - http://prntscr.com/cz7ch3
 - http://prntscr.com/cz7em4
 - http://prntscr.com/cz7dj1
5) Set a valid category according to patron's age
6) Warning should disappear
7) Perform similar test again, but instead of changing the age change
the limits of a category
8) During tests verify "Change category" button everytime opens "Modify
patron" page:
  http://prntscr.com/cz7g5q
9) Ensure that left-side panel is always on its expected place
10) Remove patron's date of birth and test that all categories are
allowed now
11) Run automated tests: prove t/db_dependent/Koha/Patron.t

Signed-off-by: Marc Véron <veron@veron.ch>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Michal Denar <black23@gmail.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
This commit is contained in:
Radek Šiman 2016-10-24 03:41:02 +02:00 committed by Martin Renvoize
parent 98914ed6bb
commit e30f09af91
No known key found for this signature in database
GPG Key ID: 422B469130441A0F
7 changed files with 107 additions and 3 deletions

View File

@ -977,6 +977,24 @@ sub get_age {
return $age;
}
=head3 is_category_valid
my $is_valid = $patron->is_category_valid
Return 1 if patron's age is between allowed limits, returns 0 if it's not.
=cut
sub is_category_valid {
my ($self) = @_;
my $age = $self->get_age;
my $patroncategory = $self->category;
my ($low,$high) = ($patroncategory->dateofbirthrequired, $patroncategory->upperagelimit);
return (defined($age) && (($high && ($age > $high)) or ($age < $low))) ? 0 : 1;
}
=head3 account
my $account = $patron->account

View File

@ -320,6 +320,13 @@ if ($patron) {
}
}
# Calculate and display patron's age
if ( !$patron->is_category_valid ) {
$template->param( age_limitations => 1 );
$template->param( age_low => $patron->category->dateofbirthrequired );
$template->param( age_high => $patron->category->upperagelimit );
}
}
#

View File

@ -0,0 +1,4 @@
<li>
<span class="circ-hlt">Patron's age is incorrect for their category.</span>
Ages allowed are [% age_low %]-[% age_high %].
<a href="/cgi-bin/koha/members/memberentry.pl?op=modify&amp;borrowernumber=[% borrowernumber %]&amp;step=3" class="btn btn-default btn-xs">Change category</a></li>

View File

@ -743,6 +743,10 @@
[% INCLUDE 'blocked-fines.inc' fines = chargesamount %]
[% END %]
[% IF age_limitations %]
[% INCLUDE 'category-out-of-age-limit.inc' %]
[% END %]
[% IF ( charges_guarantees ) %]
<li>
<span class="circ-hlt">Fees &amp; Charges:</span> Patron's guarantees collectively owe [% chargesamount_guarantees | $Price %].

View File

@ -71,10 +71,15 @@
</div>
[% END %]
[% IF fines %]
[% IF fines || age_limitations %]
<div id="circmessages" class="circmessage attention">
<ul>
[% INCLUDE 'blocked-fines.inc' %]
[% IF fines %]
[% INCLUDE 'blocked-fines.inc' %]
[% END %]
[% IF age_limitations %]
[% INCLUDE 'category-out-of-age-limit.inc' %]
[% END %]
</ul>
</div>
[% END %]

View File

@ -119,6 +119,14 @@ if ( my $guarantor = $patron->guarantor ) {
my $relatives_issues_count =
Koha::Checkouts->count({ borrowernumber => \@relatives });
# Calculate and display patron's age
if ( !$patron->is_category_valid ) {
$template->param( age_limitations => 1 );
$template->param( age_low => $patron->category->dateofbirthrequired );
$template->param( age_high => $patron->category->upperagelimit );
}
$template->param( age => $patron->get_age );
# Generate CSRF token for upload and delete image buttons
$template->param(
csrf_token => Koha::Token->new->generate_csrf({ session_id => $input->cookie('CGISESSID'),}),

View File

@ -19,7 +19,7 @@
use Modern::Perl;
use Test::More tests => 39;
use Test::More tests => 40;
use Test::Warn;
use Test::Exception;
use Test::MockModule;
@ -639,6 +639,64 @@ subtest 'get_age' => sub {
$patron->delete;
};
subtest 'is_category_valid' => sub {
plan tests => 10;
my $today = dt_from_string;
my $category = $builder->build({
source => 'Category',
value => {
categorycode => 'AGE_5_10',
dateofbirthrequired => 5,
upperagelimit => 10
}
});
$category = Koha::Patron::Categories->find( $category->{categorycode} );
my $patron = $builder->build({
source => 'Borrower',
value => {
categorycode => 'AGE_5_10'
}
});
$patron = Koha::Patrons->find( $patron->{borrowernumber} );
$patron->dateofbirth( undef );
is( $patron->is_category_valid, 1, 'Patron with no dateofbirth is always valid for any category');
$patron->dateofbirth( $today->clone->add( years => -12, months => -6, days => -1 ) );
is( $patron->is_category_valid, 0, 'Patron is 12, so the age is above allowed range 5-10 years');
$patron->dateofbirth( $today->clone->add( years => -3, months => -6, days => -1 ) );
is( $patron->is_category_valid, 0, 'Patron is 3, so the age is below allowed range 5-10 years');
$patron->dateofbirth( $today->clone->add( years => -7, months => -6, days => -1 ) );
is( $patron->is_category_valid, 1, 'Patron is 7, so the age perfectly suits allowed range 5-10 years');
$patron->dateofbirth( $today->clone->add( years => -5, months => 0, days => 0 ) );
is( $patron->is_category_valid, 1, 'Patron celebrates the 5th birthday today, so the age is allowed for this category');
$patron->dateofbirth( $today->clone->add( years => -5, months => 0, days => 1 ) );
is( $patron->is_category_valid, 0, 'Patron will celebrate the 5th birthday tomorrow, so the age is NOT allowed for this category');
$patron->dateofbirth( $today->clone->add( years => -5, months => 0, days => -1 ) );
is( $patron->is_category_valid, 1, 'Patron celebrated the 5th birthday yesterday, so the age is allowed for this category');
$patron->dateofbirth( $today->clone->add( years => -11, months => 0, days => 0 ) );
is( $patron->is_category_valid, 0, 'Patron celebrate the 11th birthday today, so the age is NOT allowed for this category');
$patron->dateofbirth( $today->clone->add( years => -11, months => 0, days => 1 ) );
is( $patron->is_category_valid, 1, 'Patron will celebrate the 11th birthday tomorrow, so the age is allowed for this category');
$patron->dateofbirth( $today->clone->add( years => -11, months => 0, days => -1 ) );
is( $patron->is_category_valid, 0, 'Patron celebrated the 11th birthday yesterday, so the age is NOT allowed for this category');
$patron->delete;
$category->delete;
};
subtest 'account' => sub {
plan tests => 1;