View | Details | Raw Unified | Return to bug 25683
Collapse All | Expand All

(-)a/Koha/Patrons.pm (-2 / +2 lines)
Lines 399-406 sub search_patrons_to_update_category { Link Here
399
        $query{join} = ["accountlines"];
399
        $query{join} = ["accountlines"];
400
        $query{select} = ["borrowernumber", "accountlines.amountoutstanding" ];
400
        $query{select} = ["borrowernumber", "accountlines.amountoutstanding" ];
401
        $query{group_by} = ["borrowernumber"];
401
        $query{group_by} = ["borrowernumber"];
402
        $query{having} = \['sum(accountlines.amountoutstanding) <= ?',$params->{fine_max}] if defined $params->{fine_max};
402
        $query{having} = \['IFNULL(sum(accountlines.amountoutstanding),0) <= ?',$params->{fine_max}] if defined $params->{fine_max};
403
        $query{having} = \['sum(accountlines.amountoutstanding) >= ?',$params->{fine_min}] if defined $params->{fine_min};
403
        $query{having} = \['IFNULL(sum(accountlines.amountoutstanding),0) >= ?',$params->{fine_min}] if defined $params->{fine_min};
404
    }
404
    }
405
    return $self->search($search_params,\%query);
405
    return $self->search($search_params,\%query);
406
}
406
}
(-)a/t/db_dependent/Patrons.t (-2 / +8 lines)
Lines 106-112 foreach my $b ( $patrons->as_list() ) { Link Here
106
}
106
}
107
107
108
subtest "Update patron categories" => sub {
108
subtest "Update patron categories" => sub {
109
    plan tests => 19;
109
    plan tests => 20;
110
    t::lib::Mocks::mock_preference( 'borrowerRelationship', 'test' );
110
    t::lib::Mocks::mock_preference( 'borrowerRelationship', 'test' );
111
    my $c_categorycode = $builder->build({ source => 'Category', value => {
111
    my $c_categorycode = $builder->build({ source => 'Category', value => {
112
            category_type=>'C',
112
            category_type=>'C',
Lines 183-188 subtest "Update patron categories" => sub { Link Here
183
    is( Koha::Patrons->search_patrons_to_update_category({from=>$a_categorycode,fine_max=>5})->count,1,'One patron with fines under $5');
183
    is( Koha::Patrons->search_patrons_to_update_category({from=>$a_categorycode,fine_max=>5})->count,1,'One patron with fines under $5');
184
    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');
184
    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');
185
185
186
    my $adult3 = $builder->build_object({class => 'Koha::Patrons', value => {
187
            categorycode=>$a_categorycode,
188
            branchcode=>$branchcode1,
189
        }
190
    });
191
    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');
192
186
    is( Koha::Patrons->find($adult1->borrowernumber)->guarantee_relationships->guarantees->count,3,'Guarantor has 3 guarantees');
193
    is( Koha::Patrons->find($adult1->borrowernumber)->guarantee_relationships->guarantees->count,3,'Guarantor has 3 guarantees');
187
    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');
194
    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');
188
    is( Koha::Patrons->find($adult1->borrowernumber)->guarantee_relationships->guarantees->count,3,'Guarantees not removed when made changing child categories');
195
    is( Koha::Patrons->find($adult1->borrowernumber)->guarantee_relationships->guarantees->count,3,'Guarantees not removed when made changing child categories');
189
- 

Return to bug 25683