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

(-)a/Koha/Account.pm (-13 / +3 lines)
Lines 431-449 my ( $total, $lines ) = Koha::Account->new({ patron_id => $patron_id })->outstan Link Here
431
sub outstanding_credits {
431
sub outstanding_credits {
432
    my ($self) = @_;
432
    my ($self) = @_;
433
433
434
    my $outstanding_credits = Koha::Account::Lines->search(
435
        {   borrowernumber    => $self->{patron_id},
436
            amountoutstanding => { '<' => 0 }
437
        },
438
        {   select => [ { sum => 'amountoutstanding' } ],
439
            as     => ['outstanding_credits_total'],
440
        }
441
    );
442
    my $total
443
        = ( $outstanding_credits->count )
444
        ? $outstanding_credits->next->get_column('outstanding_credits_total') + 0
445
        : 0;
446
447
    my $lines = Koha::Account::Lines->search(
434
    my $lines = Koha::Account::Lines->search(
448
        {
435
        {
449
            borrowernumber    => $self->{patron_id},
436
            borrowernumber    => $self->{patron_id},
Lines 451-456 sub outstanding_credits { Link Here
451
        }
438
        }
452
    );
439
    );
453
440
441
    # sum returns undef if list is empty
442
    my $total = sum0( $lines->get_column('amountoutstanding') );
443
454
    return ( $total, $lines );
444
    return ( $total, $lines );
455
}
445
}
456
446
(-)a/t/db_dependent/Koha/Account.t (-2 / +5 lines)
Lines 85-91 subtest 'outstanding_debits() tests' => sub { Link Here
85
85
86
subtest 'outstanding_credits() tests' => sub {
86
subtest 'outstanding_credits() tests' => sub {
87
87
88
    plan tests => 5;
88
    plan tests => 7;
89
89
90
    $schema->storage->txn_begin;
90
    $schema->storage->txn_begin;
91
91
Lines 109-114 subtest 'outstanding_credits() tests' => sub { Link Here
109
        $i++;
109
        $i++;
110
    }
110
    }
111
111
112
    ( $total, $lines ) =  Koha::Account->new({ patron_id => 'InvalidBorrowernumber' })->outstanding_credits();
113
    is( $total, 0, "Total if no outstanding credits is 0" );
114
    is( $lines->count, 0, "With no outstanding credits, we get back a Lines object with 0 lines" );
115
112
    $schema->storage->txn_rollback;
116
    $schema->storage->txn_rollback;
113
};
117
};
114
118
115
- 

Return to bug 20990