Lines 43-52
subtest 'outstanding_debits() tests' => sub {
Link Here
|
43 |
push @generated_lines, Koha::Account::Line->new({ borrowernumber => $patron->id, amountoutstanding => 3 })->store; |
43 |
push @generated_lines, Koha::Account::Line->new({ borrowernumber => $patron->id, amountoutstanding => 3 })->store; |
44 |
push @generated_lines, Koha::Account::Line->new({ borrowernumber => $patron->id, amountoutstanding => 4 })->store; |
44 |
push @generated_lines, Koha::Account::Line->new({ borrowernumber => $patron->id, amountoutstanding => 4 })->store; |
45 |
|
45 |
|
46 |
my $account = Koha::Account->new({ patron_id => $patron->id }); |
46 |
my $account = $patron->account; |
47 |
my ( $total, $lines ) = $account->outstanding_debits(); |
47 |
my $lines = $account->outstanding_debits(); |
48 |
|
48 |
|
49 |
is( $total, 10, 'Outstandig debits total is correctly calculated' ); |
49 |
is( $lines->total_outstanding, 10, 'Outstandig debits total is correctly calculated' ); |
50 |
|
50 |
|
51 |
my $i = 0; |
51 |
my $i = 0; |
52 |
foreach my $line ( @{ $lines->as_list } ) { |
52 |
foreach my $line ( @{ $lines->as_list } ) { |
Lines 55-70
subtest 'outstanding_debits() tests' => sub {
Link Here
|
55 |
$i++; |
55 |
$i++; |
56 |
} |
56 |
} |
57 |
|
57 |
|
58 |
( $total, $lines ) = Koha::Account->new({ patron_id => 'InvalidBorrowernumber' })->outstanding_debits(); |
|
|
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" ); |
61 |
|
62 |
my $patron_2 = $builder->build_object({ class => 'Koha::Patrons' }); |
58 |
my $patron_2 = $builder->build_object({ class => 'Koha::Patrons' }); |
63 |
Koha::Account::Line->new({ borrowernumber => $patron_2->id, amountoutstanding => -2 })->store; |
59 |
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; |
60 |
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; |
61 |
Koha::Account::Line->new({ borrowernumber => $patron_2->id, amountoutstanding => -6 })->store; |
66 |
( $total, $lines ) = Koha::Account->new({ patron_id => $patron_2->id })->outstanding_debits(); |
62 |
$lines = $patron_2->account->outstanding_debits(); |
67 |
is( $total, 3, "Total if some outstanding debits and some credits is only debits" ); |
63 |
is( $lines->total_outstanding, 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" ); |
64 |
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 ); |
65 |
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"); |
66 |
is_deeply( $the_line->unblessed, $lines->next->unblessed, "We get back the one correct line"); |
Lines 73-81
subtest 'outstanding_debits() tests' => sub {
Link Here
|
73 |
Koha::Account::Line->new({ borrowernumber => $patron_2->id, amountoutstanding => -2 })->store; |
69 |
Koha::Account::Line->new({ borrowernumber => $patron_2->id, amountoutstanding => -2 })->store; |
74 |
Koha::Account::Line->new({ borrowernumber => $patron_2->id, amountoutstanding => -20 })->store; |
70 |
Koha::Account::Line->new({ borrowernumber => $patron_2->id, amountoutstanding => -20 })->store; |
75 |
Koha::Account::Line->new({ borrowernumber => $patron_2->id, amountoutstanding => -200 })->store; |
71 |
Koha::Account::Line->new({ borrowernumber => $patron_2->id, amountoutstanding => -200 })->store; |
76 |
( $total, $lines ) = Koha::Account->new({ patron_id => $patron_3->id })->outstanding_debits(); |
72 |
$lines = $patron_3->account->outstanding_debits(); |
77 |
is( $total, 0, "Total if no outstanding debits total is 0" ); |
73 |
is( $lines->total_outstanding, 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" ); |
74 |
is( $lines->count, 0, "With 0 outstanding debits, we get back a Lines object with 0 lines" ); |
79 |
|
75 |
|
|
|
76 |
my $patron_4 = $builder->build_object({ class => 'Koha::Patrons' }); |
77 |
$lines = $patron_4->account->outstanding_debits(); |
78 |
is( $lines->total_outstanding, 0, "Total if no outstanding debits is 0" ); |
79 |
is( $lines->count, 0, "With no outstanding debits, we get back a Lines object with 0 lines" ); |
80 |
|
80 |
$schema->storage->txn_rollback; |
81 |
$schema->storage->txn_rollback; |
81 |
}; |
82 |
}; |