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

(-)a/Koha/Account.pm (-1 / +1 lines)
Lines 306-312 sub outstanding_debits { Link Here
306
    );
306
    );
307
307
308
    # sum returns undef it list is empty
308
    # sum returns undef it list is empty
309
    my $total = sum( $lines->get_column('amountoutstanding') ) + 0;
309
    my $total = sum( $lines->get_column('amountoutstanding') ) ? sum( $lines->get_column('amountoutstanding') ) + 0 : 0;
310
310
311
    return ( $total, $lines );
311
    return ( $total, $lines );
312
}
312
}
(-)a/t/db_dependent/Koha/Account.t (-2 / +18 lines)
Lines 31-37 my $builder = t::lib::TestBuilder->new; Link Here
31
31
32
subtest 'outstanding_debits() tests' => sub {
32
subtest 'outstanding_debits() tests' => sub {
33
33
34
    plan tests => 7;
34
    plan tests => 12;
35
35
36
    $schema->storage->txn_begin;
36
    $schema->storage->txn_begin;
37
37
Lines 59-64 subtest 'outstanding_debits() tests' => sub { Link Here
59
    is( $total, 0, "Total if no outstanding debits is 0" );
59
    is( $total, 0, "Total if no outstanding debits is 0" );
60
    is( $lines->count, 0, "With no outstanding debits, we get back a Lines object with 0 lines" );
60
    is( $lines->count, 0, "With no outstanding debits, we get back a Lines object with 0 lines" );
61
61
62
    my $patron_2 = $builder->build_object({ class => 'Koha::Patrons' });
63
    Koha::Account::Line->new({ borrowernumber => $patron_2->id, amountoutstanding => -2 })->store;
64
    my $just_one = Koha::Account::Line->new({ borrowernumber => $patron_2->id, amountoutstanding =>  3 })->store;
65
    Koha::Account::Line->new({ borrowernumber => $patron_2->id, amountoutstanding => -6 })->store;
66
    ( $total, $lines ) =  Koha::Account->new({ patron_id => $patron_2->id })->outstanding_debits();
67
    is( $total, 3, "Total if some outstanding debits and some credits is only debits" );
68
    is( $lines->count, 1, "With 1 outstanding debits, we get back a Lines object with 1 lines" );
69
    my $the_line = Koha::Account::Lines->find( $just_one->id );
70
    is_deeply( $the_line->unblessed, $lines->next->unblessed, "We get back the one correct line");
71
72
    my $patron_3 = $builder->build_object({ class => 'Koha::Patrons' });
73
    Koha::Account::Line->new({ borrowernumber => $patron_2->id, amountoutstanding => -2 })->store;
74
    Koha::Account::Line->new({ borrowernumber => $patron_2->id, amountoutstanding => -20 })->store;
75
    Koha::Account::Line->new({ borrowernumber => $patron_2->id, amountoutstanding => -200 })->store;
76
    ( $total, $lines ) =  Koha::Account->new({ patron_id => $patron_3->id })->outstanding_debits();
77
    is( $total, 0, "Total if no outstanding debits total is 0" );
78
    is( $lines->count, 0, "With 0 outstanding debits, we get back a Lines object with 0 lines" );
62
79
63
    $schema->storage->txn_rollback;
80
    $schema->storage->txn_rollback;
64
};
81
};
65
- 

Return to bug 20946