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

(-)a/Koha/Patrons.pm (-2 / +4 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} =
403
        $query{having} = \['sum(accountlines.amountoutstanding) >= ?',$params->{fine_min}] if defined $params->{fine_min};
403
          defined $params->{fine_max}
404
          ? \['sum(accountlines.amountoutstanding) BETWEEN ? AND ?', $params->{fine_min} || 0.01, $params->{fine_max}]
405
          : \['sum(accountlines.amountoutstanding) >= ?', $params->{fine_min}];
404
    }
406
    }
405
    return $self->search($search_params,\%query);
407
    return $self->search($search_params,\%query);
406
}
408
}
(-)a/t/db_dependent/Patrons.t (-2 / +3 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 182-187 subtest "Update patron categories" => sub { Link Here
182
    is( Koha::Patrons->search_patrons_to_update_category({from=>$a_categorycode,fine_min=>5})->next->borrowernumber,$adult2->borrowernumber,'One patron with fines over $5 is expected one');
182
    is( Koha::Patrons->search_patrons_to_update_category({from=>$a_categorycode,fine_min=>5})->next->borrowernumber,$adult2->borrowernumber,'One patron with fines over $5 is expected one');
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
    $adult1->account->add_credit({ amount => 4.99, interface => 'test' });
186
    is( Koha::Patrons->search_patrons_to_update_category({from=>$a_categorycode,fine_max=>5})->count,0,'No patron with fines under $5');
185
187
186
    is( Koha::Patrons->find($adult1->borrowernumber)->guarantee_relationships->guarantees->count,3,'Guarantor has 3 guarantees');
188
    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');
189
    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
- 

Return to bug 25683