From 944c5f7b3ccddfbe1e47729faeb32559fef2ae27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Radek=20=C5=A0iman?= Date: Mon, 24 Oct 2016 03:41:02 +0200 Subject: [PATCH] Bug 17492: Add a warning about age being of-limits and a button to update it MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Signed-off-by: Jonathan Druart Signed-off-by: Katrin Fischer --- Koha/Patron.pm | 18 +++++++ circ/circulation.pl | 7 +++ .../prog/en/includes/category-out-of-age-limit.inc | 4 ++ .../prog/en/modules/circ/circulation.tt | 4 ++ .../prog/en/modules/members/moremember.tt | 9 +++- members/moremember.pl | 8 +++ t/db_dependent/Koha/Patrons.t | 60 +++++++++++++++++++++- 7 files changed, 107 insertions(+), 3 deletions(-) create mode 100644 koha-tmpl/intranet-tmpl/prog/en/includes/category-out-of-age-limit.inc diff --git a/Koha/Patron.pm b/Koha/Patron.pm index 04b54a3ed6..06124a8ccf 100644 --- a/Koha/Patron.pm +++ b/Koha/Patron.pm @@ -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 diff --git a/circ/circulation.pl b/circ/circulation.pl index 43ce1aa41b..7191654e70 100755 --- a/circ/circulation.pl +++ b/circ/circulation.pl @@ -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 ); + } + } # diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/category-out-of-age-limit.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/category-out-of-age-limit.inc new file mode 100644 index 0000000000..2f09139dbf --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/category-out-of-age-limit.inc @@ -0,0 +1,4 @@ +
  • + Patron's age is incorrect for their category. + Ages allowed are [% age_low %]-[% age_high %]. + Change category
  • diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt index 41dec3b814..a502470d5f 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt @@ -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 ) %]
  • Fees & Charges: Patron's guarantees collectively owe [% chargesamount_guarantees | $Price %]. 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 e967d56f68..05cb6c9478 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt @@ -71,10 +71,15 @@ [% END %] - [% IF fines %] + [% IF fines || age_limitations %]
      - [% INCLUDE 'blocked-fines.inc' %] + [% IF fines %] + [% INCLUDE 'blocked-fines.inc' %] + [% END %] + [% IF age_limitations %] + [% INCLUDE 'category-out-of-age-limit.inc' %] + [% END %]
    [% END %] diff --git a/members/moremember.pl b/members/moremember.pl index 1f63180e58..defd5d466f 100755 --- a/members/moremember.pl +++ b/members/moremember.pl @@ -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'),}), diff --git a/t/db_dependent/Koha/Patrons.t b/t/db_dependent/Koha/Patrons.t index a73b8e819d..75b91cc4c7 100644 --- a/t/db_dependent/Koha/Patrons.t +++ b/t/db_dependent/Koha/Patrons.t @@ -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; -- 2.11.0