From c423fe12d3e040b49753019e20228f7060daebea Mon Sep 17 00:00:00 2001 From: Maryse Simard Date: Wed, 13 Nov 2019 16:06:58 -0500 Subject: [PATCH] Bug 12446: (follow-up) Update for Bug 17168 --- Koha/Patron.pm | 3 +-- t/db_dependent/Patrons.t | 9 +++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Koha/Patron.pm b/Koha/Patron.pm index 5436ccc448..b218bf0680 100644 --- a/Koha/Patron.pm +++ b/Koha/Patron.pm @@ -290,8 +290,7 @@ sub store { # Clean up guarantors on category change if required $self->guarantor_relationships->delete - if ( $self->category->category_type ne 'C' - && $self->category->category_type ne 'P' ); + unless ( $self->category->canbeguarantee ); } diff --git a/t/db_dependent/Patrons.t b/t/db_dependent/Patrons.t index b11a9d34f5..aeb7c74fb9 100755 --- a/t/db_dependent/Patrons.t +++ b/t/db_dependent/Patrons.t @@ -106,19 +106,22 @@ foreach my $b ( $patrons->as_list() ) { } subtest "Update patron categories" => sub { - plan tests => 19; + plan tests => 21; t::lib::Mocks::mock_preference( 'borrowerRelationship', 'test' ); my $c_categorycode = $builder->build({ source => 'Category', value => { category_type=>'C', upperagelimit=>17, dateofbirthrequired=>5, + canbeguarantee=>1, } })->{categorycode}; my $c_categorycode_2 = $builder->build({ source => 'Category', value => { category_type=>'C', upperagelimit=>17, dateofbirthrequired=>5, + canbeguarantee=>1, } })->{categorycode}; - my $a_categorycode = $builder->build({ source => 'Category', value => {category_type=>'A'} })->{categorycode}; + my $a_categorycode = $builder->build({ source => 'Category', value => {category_type=>'A', canbeguarantee=>0} })->{categorycode}; + my $a_categorycode_2 = $builder->build({ source => 'Category', value => {category_type=>'A', canbeguarantee=>1} })->{categorycode}; my $p_categorycode = $builder->build({ source => 'Category', value => {category_type=>'P'} })->{categorycode}; my $i_categorycode = $builder->build({ source => 'Category', value => {category_type=>'I'} })->{categorycode}; my $branchcode1 = $builder->build({ source => 'Branch' })->{branchcode}; @@ -188,6 +191,8 @@ subtest "Update patron categories" => sub { is( Koha::Patrons->find($adult1->borrowernumber)->guarantee_relationships->guarantees->count,3,'Guarantees not removed when made changing child categories'); is( Koha::Patrons->search_patrons_to_update_category({from=>$c_categorycode_2,too_young=>1})->update_category_to({category=>$a_categorycode}),1,'One child patron updated to adult category'); is( Koha::Patrons->find($adult1->borrowernumber)->guarantee_relationships->guarantees->count,2,'Guarantee was removed when made adult'); + is( Koha::Patrons->search_patrons_to_update_category({from=>$c_categorycode_2})->update_category_to({category=>$a_categorycode_2}),2,'Two child patrons updated to adult category'); + is( Koha::Patrons->find($adult1->borrowernumber)->guarantee_relationships->guarantees->count,2,'Guarantees were not removed when made adult which can be guarantee'); is( Koha::Patrons->find($inst->borrowernumber)->guarantee_relationships->guarantees->count,1,'Guarantor has 1 guarantees'); is( Koha::Patrons->search_patrons_to_update_category({from=>$p_categorycode})->update_category_to({category=>$a_categorycode}),1,'One professional patron updated to adult category'); -- 2.17.1