From 09146f4a995d50206c7f1c2d80e797b3cb1175c5 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Tue, 9 Jun 2020 10:52:26 +0000 Subject: [PATCH] Bug 25683: Patron with no accountlines should have 0 outstanding (not NULL) Test plan: - Have a patron with nothing in accountlines - run update_patron_categories to find patrons with fines under $5 (-fu=5) - Your patron is not found - Give your patron a manual charge of $1 - rerun the cron, your patron is found - pay off your patron's fine, putting their balance at $0 - rerun the cron, your patron is found Signed-off-by: David Nind Signed-off-by: Martin Renvoize Signed-off-by: Jonathan Druart --- Koha/Patrons.pm | 4 ++-- t/db_dependent/Patrons.t | 9 ++++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/Koha/Patrons.pm b/Koha/Patrons.pm index 6943018e88..6d45751a41 100644 --- a/Koha/Patrons.pm +++ b/Koha/Patrons.pm @@ -399,8 +399,8 @@ sub search_patrons_to_update_category { $query{join} = ["accountlines"]; $query{select} = ["borrowernumber", "accountlines.amountoutstanding" ]; $query{group_by} = ["borrowernumber"]; - $query{having} = \['sum(accountlines.amountoutstanding) <= ?',$params->{fine_max}] if defined $params->{fine_max}; - $query{having} = \['sum(accountlines.amountoutstanding) >= ?',$params->{fine_min}] if defined $params->{fine_min}; + $query{having} = \['IFNULL(sum(accountlines.amountoutstanding),0) <= ?',$params->{fine_max}] if defined $params->{fine_max}; + $query{having} = \['IFNULL(sum(accountlines.amountoutstanding),0) >= ?',$params->{fine_min}] if defined $params->{fine_min}; } return $self->search($search_params,\%query); } diff --git a/t/db_dependent/Patrons.t b/t/db_dependent/Patrons.t index b11a9d34f5..2aa964a28b 100755 --- a/t/db_dependent/Patrons.t +++ b/t/db_dependent/Patrons.t @@ -106,7 +106,7 @@ foreach my $b ( $patrons->as_list() ) { } subtest "Update patron categories" => sub { - plan tests => 19; + plan tests => 20; t::lib::Mocks::mock_preference( 'borrowerRelationship', 'test' ); my $c_categorycode = $builder->build({ source => 'Category', value => { category_type=>'C', @@ -183,6 +183,13 @@ subtest "Update patron categories" => sub { is( Koha::Patrons->search_patrons_to_update_category({from=>$a_categorycode,fine_max=>5})->count,1,'One patron with fines under $5'); is( Koha::Patrons->search_patrons_to_update_category({from=>$a_categorycode,fine_max=>5})->next->borrowernumber,$adult1->borrowernumber,'One patron with fines under $5 is expected one'); + my $adult3 = $builder->build_object({class => 'Koha::Patrons', value => { + categorycode=>$a_categorycode, + branchcode=>$branchcode1, + } + }); + is( Koha::Patrons->search_patrons_to_update_category({from=>$a_categorycode,fine_max=>5})->count,2,'Two patrons with fines under $5, patron with no fine history is found'); + is( Koha::Patrons->find($adult1->borrowernumber)->guarantee_relationships->guarantees->count,3,'Guarantor has 3 guarantees'); is( Koha::Patrons->search_patrons_to_update_category({from=>$c_categorycode})->update_category_to({category=>$c_categorycode_2}),3,'Three child patrons updated to another child category with no params passed'); is( Koha::Patrons->find($adult1->borrowernumber)->guarantee_relationships->guarantees->count,3,'Guarantees not removed when made changing child categories'); -- 2.39.5