Bug 19921: Fix update child when only one adult patron category exist
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Fri, 5 Jan 2018 19:36:31 +0000 (16:36 -0300)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Mon, 15 Jan 2018 15:13:59 +0000 (12:13 -0300)
We are passing the Koha::Patron::Category object to the template instead
of the categorycode.

To reproduce this bug you must test in a system which has only one
patron category of the "adult" type. View the details of a patron with a
child-type patron category and choose More -> Update child to adult
patron.

This results in an error:

Can't call method "category_type" on an undefined value at
/home/vagrant/kohaclone/members/update-child.pl line 84.

The URL of the error page shows a problem with the parameters being
passed:

members/update-child.pl?op=update&borrowernumber=12345&catcode=Koha::Patron::Category=HASH(0xa168a18)&catcode_multi=

Test plan:
Make sure you have only 1 adult patron category
Update a child to adult
=> With this patch applied the error is gone and the patron has been
correctly updated

Signed-off-by: Owen Leonard <oleonard@myacpl.org>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

13 files changed:
circ/circulation.pl
members/boraccount.pl
members/holdshistory.pl
members/mancredit.pl
members/maninvoice.pl
members/member-flags.pl
members/member-password.pl
members/moremember.pl
members/pay.pl
members/paycollect.pl
members/printfeercpt.pl
members/printinvoice.pl
members/readingrec.pl

index 98f4a78..5dc5d89 100755 (executable)
@@ -548,7 +548,7 @@ my ( $total, $accts, $numaccts) = GetMemberAccountRecords( $borrowernumber );
 if ( $patron && $patron->category->category_type eq 'C') {
     my $patron_categories = Koha::Patron::Categories->search_limited({ category_type => 'A' }, {order_by => ['categorycode']});
     $template->param( 'CATCODE_MULTI' => 1) if $patron_categories->count > 1;
-    $template->param( 'catcode' => $patron_categories->next )  if $patron_categories->count == 1;
+    $template->param( 'catcode' => $patron_categories->next->categorycode )  if $patron_categories->count == 1;
 }
 
 my $messages = Koha::Patron::Messages->search(
index ac7cee2..9988494 100755 (executable)
@@ -66,7 +66,7 @@ if ( $action eq 'reverse' ) {
 if ( $patron->category->category_type eq 'C') {
     my $patron_categories = Koha::Patron::Categories->search_limited({ category_type => 'A' }, {order_by => ['categorycode']});
     $template->param( 'CATCODE_MULTI' => 1) if $patron_categories->count > 1;
-    $template->param( 'catcode' => $patron_categories->next )  if $patron_categories->count == 1;
+    $template->param( 'catcode' => $patron_categories->next->categorycode )  if $patron_categories->count == 1;
 }
 
 #get account details
index 9d6f7a4..06d0d1e 100755 (executable)
@@ -77,7 +77,7 @@ if ( $borrowernumber eq C4::Context->preference('AnonymousPatron') ){
 if ( $patron->category->category_type eq 'C') {
     my $patron_categories = Koha::Patron::Categories->search_limited({ category_type => 'A' }, {order_by => ['categorycode']});
     $template->param( 'CATCODE_MULTI' => 1) if $patron_categories->count > 1;
-    $template->param( 'catcode' => $patron_categories->next )  if $patron_categories->count == 1;
+    $template->param( 'catcode' => $patron_categories->next->categorycode )  if $patron_categories->count == 1;
 }
 
 $template->param( adultborrower => 1 ) if ( $patron->category->category_type eq 'A' || $patron->category->category_type eq 'I' );
index 7534b83..fcfa1bf 100755 (executable)
@@ -80,7 +80,7 @@ if ($add){
     if ( $patron->category->category_type eq 'C') {
         my $patron_categories = Koha::Patron::Categories->search_limited({ category_type => 'A' }, {order_by => ['categorycode']});
         $template->param( 'CATCODE_MULTI' => 1) if $patron_categories->count > 1;
-        $template->param( 'catcode' => $patron_categories->next )  if $patron_categories->count == 1;
+        $template->param( 'catcode' => $patron_categories->next->categorycode )  if $patron_categories->count == 1;
     }
 
     $template->param( adultborrower => 1 ) if ( $patron->category->category_type =~ /^(A|I)$/ );
index 44d2b18..6c646c1 100755 (executable)
@@ -107,7 +107,7 @@ if ($add){
     if ( $patron->category->category_type eq 'C') {
         my $patron_categories = Koha::Patron::Categories->search_limited({ category_type => 'A' }, {order_by => ['categorycode']});
         $template->param( 'CATCODE_MULTI' => 1) if $patron_categories->count > 1;
-        $template->param( 'catcode' => $patron_categories->next )  if $patron_categories->count == 1;
+        $template->param( 'catcode' => $patron_categories->next->categorycode )  if $patron_categories->count == 1;
     }
 
     $template->param( adultborrower => 1 ) if ( $patron->category->category_type =~ /^(A|I)$/ );
index 27e020c..ba01d3b 100755 (executable)
@@ -181,7 +181,7 @@ if ($input->param('newflags')) {
     if ( $category_type eq 'C') {
         my $patron_categories = Koha::Patron::Categories->search_limited({ category_type => 'A' }, {order_by => ['categorycode']});
         $template->param( 'CATCODE_MULTI' => 1) if $patron_categories->count > 1;
-        $template->param( 'catcode' => $patron_categories->next )  if $patron_categories->count == 1;
+        $template->param( 'catcode' => $patron_categories->next->categorycode )  if $patron_categories->count == 1;
     }
 
 $template->param( adultborrower => 1 ) if ( $category_type =~ /^(A|I)$/ );
index db51b17..efeadd7 100755 (executable)
@@ -104,7 +104,7 @@ if ( $newpassword and not @errors) {
 if ( $category_type eq 'C') {
     my $patron_categories = Koha::Patron::Categories->search_limited({ category_type => 'A' }, {order_by => ['categorycode']});
     $template->param( 'CATCODE_MULTI' => 1) if $patron_categories->count > 1;
-    $template->param( 'catcode' => $patron_categories->next )  if $patron_categories->count == 1;
+    $template->param( 'catcode' => $patron_categories->next->categorycode )  if $patron_categories->count == 1;
 }
 
 $template->param( adultborrower => 1 ) if ( $category_type =~ /^(A|I)$/ );
index 27185ef..f79f2f8 100755 (executable)
@@ -172,7 +172,7 @@ $data->{ "sex_".$data->{'sex'}."_p" } = 1 if defined $data->{sex};
 if ( $category_type eq 'C') {
     my $patron_categories = Koha::Patron::Categories->search_limited({ category_type => 'A' }, {order_by => ['categorycode']});
     $template->param( 'CATCODE_MULTI' => 1) if $patron_categories->count > 1;
-    $template->param( 'catcode' => $patron_categories->next )  if $patron_categories->count == 1;
+    $template->param( 'catcode' => $patron_categories->next->categorycode )  if $patron_categories->count == 1;
 }
 
 my @relatives;
index b1add01..a248db0 100755 (executable)
@@ -235,7 +235,7 @@ sub borrower_add_additional_fields {
     if ( $b_ref->{category_type} eq 'C' ) {
         my $patron_categories = Koha::Patron::Categories->search_limited({ category_type => 'A' }, {order_by => ['categorycode']});
         $template->param( 'CATCODE_MULTI' => 1) if $patron_categories->count > 1;
-        $template->param( 'catcode' => $patron_categories->next )  if $patron_categories->count == 1;
+        $template->param( 'catcode' => $patron_categories->next->categorycode )  if $patron_categories->count == 1;
     } elsif ( $b_ref->{category_type} eq 'A' || $b_ref->{category_type} eq 'I' ) {
         $b_ref->{adultborrower} = 1;
     }
index 6bf0fee..6e2fe67 100755 (executable)
@@ -200,7 +200,7 @@ sub borrower_add_additional_fields {
     if ( $b_ref->{category_type} eq 'C' ) {
         my $patron_categories = Koha::Patron::Categories->search_limited({ category_type => 'A' }, {order_by => ['categorycode']});
         $template->param( 'CATCODE_MULTI' => 1) if $patron_categories->count > 1;
-        $template->param( 'catcode' => $patron_categories->next )  if $patron_categories->count == 1;
+        $template->param( 'catcode' => $patron_categories->next->categorycode )  if $patron_categories->count == 1;
     } elsif ( $b_ref->{category_type} eq 'A' || $b_ref->{category_type} eq 'I' ) {
         $b_ref->{adultborrower} = 1;
     }
index f5933f1..8bce7a8 100755 (executable)
@@ -67,7 +67,7 @@ if ( $action eq 'print' ) {
 if ( $data->{'category_type'} eq 'C') {
     my $patron_categories = Koha::Patron::Categories->search_limited({ category_type => 'A' }, {order_by => ['categorycode']});
     $template->param( 'CATCODE_MULTI' => 1) if $patron_categories->count > 1;
-    $template->param( 'catcode' => $patron_categories->next )  if $patron_categories->count == 1;
+    $template->param( 'catcode' => $patron_categories->next->categorycde )  if $patron_categories->count == 1;
 }
 
 #get account details
index ff2c0d1..53c9438 100755 (executable)
@@ -62,7 +62,7 @@ $data->{category_type} = $category->category_type;
 if ( $data->{'category_type'} eq 'C' ) {
     my $patron_categories = Koha::Patron::Categories->search_limited({ category_type => 'A' }, {order_by => ['categorycode']});
     $template->param( 'CATCODE_MULTI' => 1) if $patron_categories->count > 1;
-    $template->param( 'catcode' => $patron_categories->next )  if $patron_categories->count == 1;
+    $template->param( 'catcode' => $patron_categories->next->categorycode )  if $patron_categories->count == 1;
 }
 
 #get account details
index 7fe990d..d94ff96 100755 (executable)
@@ -104,7 +104,7 @@ if ( $op eq 'export_barcodes' ) {
 if ( $data->{'category_type'} eq 'C') {
     my $patron_categories = Koha::Patron::Categories->search_limited({ category_type => 'A' }, {order_by => ['categorycode']});
     $template->param( 'CATCODE_MULTI' => 1) if $patron_categories->count > 1;
-    $template->param( 'catcode' => $patron_categories->next )  if $patron_categories->count == 1;
+    $template->param( 'catcode' => $patron_categories->next->categorycode )  if $patron_categories->count == 1;
 }
 
 $template->param( adultborrower => 1 ) if ( $data->{'category_type'} eq 'A' || $data->{'category_type'} eq 'I' );