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

(-)a/t/db_dependent/Koha/Account.t (-15 / +26 lines)
Lines 33-49 my $builder = t::lib::TestBuilder->new; Link Here
33
33
34
subtest 'outstanding_debits() tests' => sub {
34
subtest 'outstanding_debits() tests' => sub {
35
35
36
    plan tests => 12;
36
    plan tests => 13;
37
37
38
    $schema->storage->txn_begin;
38
    $schema->storage->txn_begin;
39
39
40
    my $patron = $builder->build_object({ class => 'Koha::Patrons' });
40
    my $patron = $builder->build_object({ class => 'Koha::Patrons' });
41
41
42
    my @generated_lines;
42
    my @generated_lines;
43
    push @generated_lines, Koha::Account::Line->new({ borrowernumber => $patron->id, amountoutstanding => 1 })->store;
43
    push @generated_lines, Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 1, amountoutstanding => 1 })->store;
44
    push @generated_lines, Koha::Account::Line->new({ borrowernumber => $patron->id, amountoutstanding => 2 })->store;
44
    push @generated_lines, Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 2, amountoutstanding => 2 })->store;
45
    push @generated_lines, Koha::Account::Line->new({ borrowernumber => $patron->id, amountoutstanding => 3 })->store;
45
    push @generated_lines, Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 3, amountoutstanding => 3 })->store;
46
    push @generated_lines, Koha::Account::Line->new({ borrowernumber => $patron->id, amountoutstanding => 4 })->store;
46
    push @generated_lines, Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 4, amountoutstanding => 4 })->store;
47
47
48
    my $account = $patron->account;
48
    my $account = $patron->account;
49
    my $lines   = $account->outstanding_debits();
49
    my $lines   = $account->outstanding_debits();
Lines 59-66 subtest 'outstanding_debits() tests' => sub { Link Here
59
59
60
    my $patron_2 = $builder->build_object({ class => 'Koha::Patrons' });
60
    my $patron_2 = $builder->build_object({ class => 'Koha::Patrons' });
61
    Koha::Account::Line->new({ borrowernumber => $patron_2->id, amountoutstanding => -2 })->store;
61
    Koha::Account::Line->new({ borrowernumber => $patron_2->id, amountoutstanding => -2 })->store;
62
    my $just_one = Koha::Account::Line->new({ borrowernumber => $patron_2->id, amountoutstanding =>  3 })->store;
62
    my $just_one = Koha::Account::Line->new({ borrowernumber => $patron_2->id, amount => 3, amountoutstanding =>  3 })->store;
63
    Koha::Account::Line->new({ borrowernumber => $patron_2->id, amountoutstanding => -6 })->store;
63
    Koha::Account::Line->new({ borrowernumber => $patron_2->id, amount => -6, amountoutstanding => -6 })->store;
64
    $lines = $patron_2->account->outstanding_debits();
64
    $lines = $patron_2->account->outstanding_debits();
65
    is( $lines->total_outstanding, 3, "Total if some outstanding debits and some credits is only debits" );
65
    is( $lines->total_outstanding, 3, "Total if some outstanding debits and some credits is only debits" );
66
    is( $lines->count, 1, "With 1 outstanding debits, we get back a Lines object with 1 lines" );
66
    is( $lines->count, 1, "With 1 outstanding debits, we get back a Lines object with 1 lines" );
Lines 68-91 subtest 'outstanding_debits() tests' => sub { Link Here
68
    is_deeply( $the_line->unblessed, $lines->next->unblessed, "We get back the one correct line");
68
    is_deeply( $the_line->unblessed, $lines->next->unblessed, "We get back the one correct line");
69
69
70
    my $patron_3 = $builder->build_object({ class => 'Koha::Patrons' });
70
    my $patron_3 = $builder->build_object({ class => 'Koha::Patrons' });
71
    Koha::Account::Line->new({ borrowernumber => $patron_2->id, amountoutstanding => -2 })->store;
71
    Koha::Account::Line->new({ borrowernumber => $patron_2->id, amount => -2,   amountoutstanding => -2 })->store;
72
    Koha::Account::Line->new({ borrowernumber => $patron_2->id, amountoutstanding => -20 })->store;
72
    Koha::Account::Line->new({ borrowernumber => $patron_2->id, amount => -20,  amountoutstanding => -20 })->store;
73
    Koha::Account::Line->new({ borrowernumber => $patron_2->id, amountoutstanding => -200 })->store;
73
    Koha::Account::Line->new({ borrowernumber => $patron_2->id, amount => -200, amountoutstanding => -200 })->store;
74
    $lines = $patron_3->account->outstanding_debits();
74
    $lines = $patron_3->account->outstanding_debits();
75
    is( $lines->total_outstanding, 0, "Total if no outstanding debits total is 0" );
75
    is( $lines->total_outstanding, 0, "Total if no outstanding debits total is 0" );
76
    is( $lines->count, 0, "With 0 outstanding debits, we get back a Lines object with 0 lines" );
76
    is( $lines->count, 0, "With 0 outstanding debits, we get back a Lines object with 0 lines" );
77
77
78
    my $patron_4 = $builder->build_object({ class => 'Koha::Patrons' });
78
    my $patron_4  = $builder->build_object({ class => 'Koha::Patrons' });
79
    $lines = $patron_4->account->outstanding_debits();
79
    my $account_4 = $patron_4->account;
80
    $lines = $account_4->outstanding_debits();
80
    is( $lines->total_outstanding, 0, "Total if no outstanding debits is 0" );
81
    is( $lines->total_outstanding, 0, "Total if no outstanding debits is 0" );
81
    is( $lines->count, 0, "With no outstanding debits, we get back a Lines object with 0 lines" );
82
    is( $lines->count, 0, "With no outstanding debits, we get back a Lines object with 0 lines" );
82
83
84
    # create a pathological credit with amountoutstanding > 0 (BZ 14591)
85
    Koha::Account::Line->new({ borrowernumber => $patron_4->id, amount => -3, amountoutstanding => 3 })->store();
86
    $lines = $account_4->outstanding_debits();
87
    is( $lines->count, 0, 'No credits are confused with debits because of the amountoutstanding value' );
88
83
    $schema->storage->txn_rollback;
89
    $schema->storage->txn_rollback;
84
};
90
};
85
91
86
subtest 'outstanding_credits() tests' => sub {
92
subtest 'outstanding_credits() tests' => sub {
87
93
88
    plan tests => 7;
94
    plan tests => 8;
89
95
90
    $schema->storage->txn_begin;
96
    $schema->storage->txn_begin;
91
97
Lines 110-119 subtest 'outstanding_credits() tests' => sub { Link Here
110
    }
116
    }
111
117
112
    my $patron_2 = $builder->build_object({ class => 'Koha::Patrons' });
118
    my $patron_2 = $builder->build_object({ class => 'Koha::Patrons' });
113
    $lines       = $patron_2->account->outstanding_credits();
119
    $account  = $patron_2->account;
120
    $lines       = $account->outstanding_credits();
114
    is( $lines->total_outstanding, 0, "Total if no outstanding credits is 0" );
121
    is( $lines->total_outstanding, 0, "Total if no outstanding credits is 0" );
115
    is( $lines->count, 0, "With no outstanding credits, we get back a Lines object with 0 lines" );
122
    is( $lines->count, 0, "With no outstanding credits, we get back a Lines object with 0 lines" );
116
123
124
    # create a pathological debit with amountoutstanding < 0 (BZ 14591)
125
    Koha::Account::Line->new({ borrowernumber => $patron_2->id, amount => 2, amountoutstanding => -3 })->store();
126
    $lines = $account->outstanding_credits();
127
    is( $lines->count, 0, 'No debits are confused with credits because of the amountoutstanding value' );
128
117
    $schema->storage->txn_rollback;
129
    $schema->storage->txn_rollback;
118
};
130
};
119
131
120
- 

Return to bug 21969