From ff40178c7654d208b6ab9a39d4ca8c6b36475b87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Radek=20=C5=A0iman?= Date: Mon, 2 Oct 2017 17:08:45 +0200 Subject: [PATCH] Bug 17492: (followup) Logic moved to Koha namespace 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 --- Koha/Patron.pm | 18 ++++++++++++++++++ circ/circulation.pl | 10 +++------- members/moremember.pl | 16 ++++------------ 3 files changed, 25 insertions(+), 19 deletions(-) diff --git a/Koha/Patron.pm b/Koha/Patron.pm index daa972c..d444111 100644 --- a/Koha/Patron.pm +++ b/Koha/Patron.pm @@ -568,6 +568,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 (($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 1f22bed..c002412 100755 --- a/circ/circulation.pl +++ b/circ/circulation.pl @@ -304,14 +304,10 @@ if ($patron) { } # Calculate and display patron's age - my $age = $patron->get_age; - - my $patroncategory = $patron->category; - my ($low,$high) = ($patroncategory->dateofbirthrequired, $patroncategory->upperagelimit); - if (($high && ($age > $high)) or ($age < $low)) { + if ( !$patron->is_category_valid ) { $template->param( age_limitations => 1 ); - $template->param( age_low => $low ); - $template->param( age_high => $high ); + $template->param( age_low => $patron->category->dateofbirthrequired ); + $template->param( age_high => $patron->category->upperagelimit ); } } diff --git a/members/moremember.pl b/members/moremember.pl index fcf51f7..8d9815a 100755 --- a/members/moremember.pl +++ b/members/moremember.pl @@ -246,20 +246,12 @@ my $overdues_exist = 0; my $totalprice = 0; # Calculate and display patron's age -my $age; -if ( $data->{dateofbirth} ) { - $age = Koha::Patron->new({ dateofbirth => $data->{dateofbirth} })->get_age; - $template->param( age => $age ); -} - -# Check patron's category against age -my $patroncategory = Koha::Patron::Categories->find($data->{ 'categorycode' }); -my ($low,$high) = ($patroncategory->dateofbirthrequired, $patroncategory->upperagelimit); -if (($high && ($age > $high)) or ($age < $low)) { +if ( !$patron->is_category_valid ) { $template->param( age_limitations => 1 ); - $template->param( age_low => $low ); - $template->param( age_high => $high ); + $template->param( age_low => $patron->category->dateofbirthrequired ); + $template->param( age_high => $patron->category->upperagelimit ); } +$template->param( age => $patron->get_age ); ### ############################################################################### -- 2.1.4