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

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

Return to bug 20990