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

(-)a/Koha/Account.pm (-5 / +2 lines)
Lines 424-430 sub outstanding_debits { Link Here
424
424
425
=head3 outstanding_credits
425
=head3 outstanding_credits
426
426
427
my ( $total, $lines ) = Koha::Account->new({ patron_id => $patron_id })->outstanding_credits;
427
my $lines = Koha::Account->new({ patron_id => $patron_id })->outstanding_credits;
428
428
429
=cut
429
=cut
430
430
Lines 438-447 sub outstanding_credits { Link Here
438
        }
438
        }
439
    );
439
    );
440
440
441
    # sum returns undef if list is empty
441
    return $lines;
442
    my $total = sum0( $lines->get_column('amountoutstanding') );
443
444
    return ( $total, $lines );
445
}
442
}
446
443
447
=head3 non_issues_charges
444
=head3 non_issues_charges
(-)a/t/db_dependent/Koha/Account.t (-6 / +6 lines)
Lines 90-96 subtest 'outstanding_credits() tests' => sub { Link Here
90
    $schema->storage->txn_begin;
90
    $schema->storage->txn_begin;
91
91
92
    my $patron  = $builder->build_object({ class => 'Koha::Patrons' });
92
    my $patron  = $builder->build_object({ class => 'Koha::Patrons' });
93
    my $account = Koha::Account->new({ patron_id => $patron->id });
93
    my $account = $patron->account;
94
94
95
    my @generated_lines;
95
    my @generated_lines;
96
    push @generated_lines, $account->add_credit({ amount => 1 });
96
    push @generated_lines, $account->add_credit({ amount => 1 });
Lines 98-106 subtest 'outstanding_credits() tests' => sub { Link Here
98
    push @generated_lines, $account->add_credit({ amount => 3 });
98
    push @generated_lines, $account->add_credit({ amount => 3 });
99
    push @generated_lines, $account->add_credit({ amount => 4 });
99
    push @generated_lines, $account->add_credit({ amount => 4 });
100
100
101
    my ( $total, $lines ) = $account->outstanding_credits();
101
    my $lines = $account->outstanding_credits();
102
102
103
    is( $total, -10, 'Outstandig credits total is correctly calculated' );
103
    is( $lines->total_outstanding, -10, 'Outstandig credits total is correctly calculated' );
104
104
105
    my $i = 0;
105
    my $i = 0;
106
    foreach my $line ( @{ $lines->as_list } ) {
106
    foreach my $line ( @{ $lines->as_list } ) {
Lines 109-116 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();
112
    my $patron_2 = $builder->build_object({ class => 'Koha::Patrons' });
113
    is( $total, 0, "Total if no outstanding credits is 0" );
113
    $lines       = $patron_2->account->outstanding_credits();
114
    is( $lines->total_outstanding, 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
    is( $lines->count, 0, "With no outstanding credits, we get back a Lines object with 0 lines" );
115
116
116
    $schema->storage->txn_rollback;
117
    $schema->storage->txn_rollback;
117
- 

Return to bug 20990