|
Lines 33-38
use t::lib::TestBuilder;
Link Here
|
| 33 |
|
33 |
|
| 34 |
my $schema = Koha::Database->new->schema; |
34 |
my $schema = Koha::Database->new->schema; |
| 35 |
my $builder = t::lib::TestBuilder->new; |
35 |
my $builder = t::lib::TestBuilder->new; |
|
|
36 |
C4::Context->interface('commandline'); |
| 36 |
|
37 |
|
| 37 |
subtest 'new' => sub { |
38 |
subtest 'new' => sub { |
| 38 |
|
39 |
|
|
Lines 59-68
subtest 'outstanding_debits() tests' => sub {
Link Here
|
| 59 |
my $account = $patron->account; |
60 |
my $account = $patron->account; |
| 60 |
|
61 |
|
| 61 |
my @generated_lines; |
62 |
my @generated_lines; |
| 62 |
push @generated_lines, Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 1, amountoutstanding => 1 })->store; |
63 |
push @generated_lines, Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 1, amountoutstanding => 1, interface => 'commandline' })->store; |
| 63 |
push @generated_lines, Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 2, amountoutstanding => 2 })->store; |
64 |
push @generated_lines, Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 2, amountoutstanding => 2, interface => 'commandline' })->store; |
| 64 |
push @generated_lines, Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 3, amountoutstanding => 3 })->store; |
65 |
push @generated_lines, Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 3, amountoutstanding => 3, interface => 'commandline' })->store; |
| 65 |
push @generated_lines, Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 4, amountoutstanding => 4 })->store; |
66 |
push @generated_lines, Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 4, amountoutstanding => 4, interface => 'commandline' })->store; |
| 66 |
|
67 |
|
| 67 |
my $lines = $account->outstanding_debits(); |
68 |
my $lines = $account->outstanding_debits(); |
| 68 |
my @lines_arr = $account->outstanding_debits(); |
69 |
my @lines_arr = $account->outstanding_debits(); |
|
Lines 79-87
subtest 'outstanding_debits() tests' => sub {
Link Here
|
| 79 |
$i++; |
80 |
$i++; |
| 80 |
} |
81 |
} |
| 81 |
my $patron_2 = $builder->build_object({ class => 'Koha::Patrons' }); |
82 |
my $patron_2 = $builder->build_object({ class => 'Koha::Patrons' }); |
| 82 |
Koha::Account::Line->new({ borrowernumber => $patron_2->id, amountoutstanding => -2 })->store; |
83 |
Koha::Account::Line->new({ borrowernumber => $patron_2->id, amountoutstanding => -2, interface => 'commandline' })->store; |
| 83 |
my $just_one = Koha::Account::Line->new({ borrowernumber => $patron_2->id, amount => 3, amountoutstanding => 3 })->store; |
84 |
my $just_one = Koha::Account::Line->new({ borrowernumber => $patron_2->id, amount => 3, amountoutstanding => 3, interface => 'commandline' })->store; |
| 84 |
Koha::Account::Line->new({ borrowernumber => $patron_2->id, amount => -6, amountoutstanding => -6 })->store; |
85 |
Koha::Account::Line->new({ borrowernumber => $patron_2->id, amount => -6, amountoutstanding => -6, interface => 'commandline' })->store; |
| 85 |
$lines = $patron_2->account->outstanding_debits(); |
86 |
$lines = $patron_2->account->outstanding_debits(); |
| 86 |
is( $lines->total_outstanding, 3, "Total if some outstanding debits and some credits is only debits" ); |
87 |
is( $lines->total_outstanding, 3, "Total if some outstanding debits and some credits is only debits" ); |
| 87 |
is( $lines->count, 1, "With 1 outstanding debits, we get back a Lines object with 1 lines" ); |
88 |
is( $lines->count, 1, "With 1 outstanding debits, we get back a Lines object with 1 lines" ); |
|
Lines 89-97
subtest 'outstanding_debits() tests' => sub {
Link Here
|
| 89 |
is_deeply( $the_line->unblessed, $lines->next->unblessed, "We get back the one correct line"); |
90 |
is_deeply( $the_line->unblessed, $lines->next->unblessed, "We get back the one correct line"); |
| 90 |
|
91 |
|
| 91 |
my $patron_3 = $builder->build_object({ class => 'Koha::Patrons' }); |
92 |
my $patron_3 = $builder->build_object({ class => 'Koha::Patrons' }); |
| 92 |
Koha::Account::Line->new({ borrowernumber => $patron_2->id, amount => -2, amountoutstanding => -2 })->store; |
93 |
Koha::Account::Line->new({ borrowernumber => $patron_2->id, amount => -2, amountoutstanding => -2, interface => 'commandline' })->store; |
| 93 |
Koha::Account::Line->new({ borrowernumber => $patron_2->id, amount => -20, amountoutstanding => -20 })->store; |
94 |
Koha::Account::Line->new({ borrowernumber => $patron_2->id, amount => -20, amountoutstanding => -20, interface => 'commandline' })->store; |
| 94 |
Koha::Account::Line->new({ borrowernumber => $patron_2->id, amount => -200, amountoutstanding => -200 })->store; |
95 |
Koha::Account::Line->new({ borrowernumber => $patron_2->id, amount => -200, amountoutstanding => -200, interface => 'commandline' })->store; |
| 95 |
$lines = $patron_3->account->outstanding_debits(); |
96 |
$lines = $patron_3->account->outstanding_debits(); |
| 96 |
is( $lines->total_outstanding, 0, "Total if no outstanding debits total is 0" ); |
97 |
is( $lines->total_outstanding, 0, "Total if no outstanding debits total is 0" ); |
| 97 |
is( $lines->count, 0, "With 0 outstanding debits, we get back a Lines object with 0 lines" ); |
98 |
is( $lines->count, 0, "With 0 outstanding debits, we get back a Lines object with 0 lines" ); |
|
Lines 103-109
subtest 'outstanding_debits() tests' => sub {
Link Here
|
| 103 |
is( $lines->count, 0, "With no outstanding debits, we get back a Lines object with 0 lines" ); |
104 |
is( $lines->count, 0, "With no outstanding debits, we get back a Lines object with 0 lines" ); |
| 104 |
|
105 |
|
| 105 |
# create a pathological credit with amountoutstanding > 0 (BZ 14591) |
106 |
# create a pathological credit with amountoutstanding > 0 (BZ 14591) |
| 106 |
Koha::Account::Line->new({ borrowernumber => $patron_4->id, amount => -3, amountoutstanding => 3 })->store(); |
107 |
Koha::Account::Line->new({ borrowernumber => $patron_4->id, amount => -3, amountoutstanding => 3, interface => 'commandline' })->store(); |
| 107 |
$lines = $account_4->outstanding_debits(); |
108 |
$lines = $account_4->outstanding_debits(); |
| 108 |
is( $lines->count, 0, 'No credits are confused with debits because of the amountoutstanding value' ); |
109 |
is( $lines->count, 0, 'No credits are confused with debits because of the amountoutstanding value' ); |
| 109 |
|
110 |
|
|
Lines 120-129
subtest 'outstanding_credits() tests' => sub {
Link Here
|
| 120 |
my $account = $patron->account; |
121 |
my $account = $patron->account; |
| 121 |
|
122 |
|
| 122 |
my @generated_lines; |
123 |
my @generated_lines; |
| 123 |
push @generated_lines, $account->add_credit({ amount => 1 }); |
124 |
push @generated_lines, $account->add_credit({ amount => 1, interface => 'commandline' }); |
| 124 |
push @generated_lines, $account->add_credit({ amount => 2 }); |
125 |
push @generated_lines, $account->add_credit({ amount => 2, interface => 'commandline' }); |
| 125 |
push @generated_lines, $account->add_credit({ amount => 3 }); |
126 |
push @generated_lines, $account->add_credit({ amount => 3, interface => 'commandline' }); |
| 126 |
push @generated_lines, $account->add_credit({ amount => 4 }); |
127 |
push @generated_lines, $account->add_credit({ amount => 4, interface => 'commandline' }); |
| 127 |
|
128 |
|
| 128 |
my $lines = $account->outstanding_credits(); |
129 |
my $lines = $account->outstanding_credits(); |
| 129 |
my @lines_arr = $account->outstanding_credits(); |
130 |
my @lines_arr = $account->outstanding_credits(); |
|
Lines 147-153
subtest 'outstanding_credits() tests' => sub {
Link Here
|
| 147 |
is( $lines->count, 0, "With no outstanding credits, we get back a Lines object with 0 lines" ); |
148 |
is( $lines->count, 0, "With no outstanding credits, we get back a Lines object with 0 lines" ); |
| 148 |
|
149 |
|
| 149 |
# create a pathological debit with amountoutstanding < 0 (BZ 14591) |
150 |
# create a pathological debit with amountoutstanding < 0 (BZ 14591) |
| 150 |
Koha::Account::Line->new({ borrowernumber => $patron_2->id, amount => 2, amountoutstanding => -3 })->store(); |
151 |
Koha::Account::Line->new({ borrowernumber => $patron_2->id, amount => 2, amountoutstanding => -3, interface => 'commandline' })->store(); |
| 151 |
$lines = $account->outstanding_credits(); |
152 |
$lines = $account->outstanding_credits(); |
| 152 |
is( $lines->count, 0, 'No debits are confused with credits because of the amountoutstanding value' ); |
153 |
is( $lines->count, 0, 'No debits are confused with credits because of the amountoutstanding value' ); |
| 153 |
|
154 |
|
|
Lines 178-184
subtest 'add_credit() tests' => sub {
Link Here
|
| 178 |
library_id => $patron->branchcode, |
179 |
library_id => $patron->branchcode, |
| 179 |
note => 'not really important', |
180 |
note => 'not really important', |
| 180 |
type => 'payment', |
181 |
type => 'payment', |
| 181 |
user_id => $patron->id |
182 |
user_id => $patron->id, |
|
|
183 |
interface => 'commandline' |
| 182 |
} |
184 |
} |
| 183 |
); |
185 |
); |
| 184 |
|
186 |
|
|
Lines 197-203
subtest 'add_credit() tests' => sub {
Link Here
|
| 197 |
library_id => $patron->branchcode, |
199 |
library_id => $patron->branchcode, |
| 198 |
note => 'not really important', |
200 |
note => 'not really important', |
| 199 |
user_id => $patron->id, |
201 |
user_id => $patron->id, |
| 200 |
sip => $sip_code |
202 |
sip => $sip_code, |
|
|
203 |
interface => 'commandline' |
| 201 |
} |
204 |
} |
| 202 |
); |
205 |
); |
| 203 |
|
206 |
|
|
Lines 220-226
subtest 'add_credit() tests' => sub {
Link Here
|
| 220 |
description => 'Manual credit applied', |
223 |
description => 'Manual credit applied', |
| 221 |
library_id => $patron->branchcode, |
224 |
library_id => $patron->branchcode, |
| 222 |
user_id => $patron->id, |
225 |
user_id => $patron->id, |
| 223 |
type => 'forgiven' |
226 |
type => 'forgiven', |
|
|
227 |
interface => 'commandline' |
| 224 |
} |
228 |
} |
| 225 |
); |
229 |
); |
| 226 |
|
230 |
|
|
Lines 254-260
subtest 'add_debit() tests' => sub {
Link Here
|
| 254 |
library_id => $patron->branchcode, |
258 |
library_id => $patron->branchcode, |
| 255 |
note => 'this should fail anyway', |
259 |
note => 'this should fail anyway', |
| 256 |
type => 'rent', |
260 |
type => 'rent', |
| 257 |
user_id => $patron->id |
261 |
user_id => $patron->id, |
|
|
262 |
interface => 'commandline' |
| 258 |
} |
263 |
} |
| 259 |
); } 'Koha::Exceptions::Account::AmountNotPositive', 'Expected validation exception thrown (amount)'; |
264 |
); } 'Koha::Exceptions::Account::AmountNotPositive', 'Expected validation exception thrown (amount)'; |
| 260 |
|
265 |
|
|
Lines 266-272
subtest 'add_debit() tests' => sub {
Link Here
|
| 266 |
library_id => $patron->branchcode, |
271 |
library_id => $patron->branchcode, |
| 267 |
note => 'this should fail anyway', |
272 |
note => 'this should fail anyway', |
| 268 |
type => 'failure', |
273 |
type => 'failure', |
| 269 |
user_id => $patron->id |
274 |
user_id => $patron->id, |
|
|
275 |
interface => 'commandline' |
| 270 |
} |
276 |
} |
| 271 |
); } 'Koha::Exceptions::Account::UnrecognisedType', 'Expected validation exception thrown (type)'; |
277 |
); } 'Koha::Exceptions::Account::UnrecognisedType', 'Expected validation exception thrown (type)'; |
| 272 |
|
278 |
|
|
Lines 280-286
subtest 'add_debit() tests' => sub {
Link Here
|
| 280 |
library_id => $patron->branchcode, |
286 |
library_id => $patron->branchcode, |
| 281 |
note => 'not really important', |
287 |
note => 'not really important', |
| 282 |
type => 'rent', |
288 |
type => 'rent', |
| 283 |
user_id => $patron->id |
289 |
user_id => $patron->id, |
|
|
290 |
interface => 'commandline' |
| 284 |
} |
291 |
} |
| 285 |
); |
292 |
); |
| 286 |
|
293 |
|
|
Lines 308-313
subtest 'add_debit() tests' => sub {
Link Here
|
| 308 |
note => 'not really important', |
315 |
note => 'not really important', |
| 309 |
type => 'rent', |
316 |
type => 'rent', |
| 310 |
user_id => $patron->id, |
317 |
user_id => $patron->id, |
|
|
318 |
interface => 'commandline' |
| 311 |
} |
319 |
} |
| 312 |
); |
320 |
); |
| 313 |
|
321 |
|
|
Lines 349-368
subtest 'lines() tests' => sub {
Link Here
|
| 349 |
my @generated_lines; |
357 |
my @generated_lines; |
| 350 |
|
358 |
|
| 351 |
# Add Credits |
359 |
# Add Credits |
| 352 |
push @generated_lines, $account->add_credit({ amount => 1 }); |
360 |
push @generated_lines, $account->add_credit({ amount => 1, interface => 'commandline' }); |
| 353 |
push @generated_lines, $account->add_credit({ amount => 2 }); |
361 |
push @generated_lines, $account->add_credit({ amount => 2, interface => 'commandline' }); |
| 354 |
push @generated_lines, $account->add_credit({ amount => 3 }); |
362 |
push @generated_lines, $account->add_credit({ amount => 3, interface => 'commandline' }); |
| 355 |
push @generated_lines, $account->add_credit({ amount => 4 }); |
363 |
push @generated_lines, $account->add_credit({ amount => 4, interface => 'commandline' }); |
| 356 |
|
364 |
|
| 357 |
# Add Debits |
365 |
# Add Debits |
| 358 |
push @generated_lines, Koha::Account::Line->new({ borrowernumber => $patron->id, amountoutstanding => 1 })->store; |
366 |
push @generated_lines, Koha::Account::Line->new({ borrowernumber => $patron->id, amountoutstanding => 1, interface => 'commandline' })->store; |
| 359 |
push @generated_lines, Koha::Account::Line->new({ borrowernumber => $patron->id, amountoutstanding => 2 })->store; |
367 |
push @generated_lines, Koha::Account::Line->new({ borrowernumber => $patron->id, amountoutstanding => 2, interface => 'commandline' })->store; |
| 360 |
push @generated_lines, Koha::Account::Line->new({ borrowernumber => $patron->id, amountoutstanding => 3 })->store; |
368 |
push @generated_lines, Koha::Account::Line->new({ borrowernumber => $patron->id, amountoutstanding => 3, interface => 'commandline' })->store; |
| 361 |
push @generated_lines, Koha::Account::Line->new({ borrowernumber => $patron->id, amountoutstanding => 4 })->store; |
369 |
push @generated_lines, Koha::Account::Line->new({ borrowernumber => $patron->id, amountoutstanding => 4, interface => 'commandline' })->store; |
| 362 |
|
370 |
|
| 363 |
# Paid Off |
371 |
# Paid Off |
| 364 |
push @generated_lines, Koha::Account::Line->new({ borrowernumber => $patron->id, amountoutstanding => 0 })->store; |
372 |
push @generated_lines, Koha::Account::Line->new({ borrowernumber => $patron->id, amountoutstanding => 0, interface => 'commandline' })->store; |
| 365 |
push @generated_lines, Koha::Account::Line->new({ borrowernumber => $patron->id, amountoutstanding => 0 })->store; |
373 |
push @generated_lines, Koha::Account::Line->new({ borrowernumber => $patron->id, amountoutstanding => 0, interface => 'commandline' })->store; |
| 366 |
|
374 |
|
| 367 |
my $lines = $account->lines; |
375 |
my $lines = $account->lines; |
| 368 |
is( $lines->_resultset->count, 10, "All accountlines (debits, credits and paid off) were fetched"); |
376 |
is( $lines->_resultset->count, 10, "All accountlines (debits, credits and paid off) were fetched"); |
|
Lines 384-404
subtest 'reconcile_balance' => sub {
Link Here
|
| 384 |
my $account = $patron->account; |
392 |
my $account = $patron->account; |
| 385 |
|
393 |
|
| 386 |
# Add Credits |
394 |
# Add Credits |
| 387 |
$account->add_credit({ amount => 1 }); |
395 |
$account->add_credit({ amount => 1, interface => 'commandline' }); |
| 388 |
$account->add_credit({ amount => 2 }); |
396 |
$account->add_credit({ amount => 2, interface => 'commandline' }); |
| 389 |
$account->add_credit({ amount => 3 }); |
397 |
$account->add_credit({ amount => 3, interface => 'commandline' }); |
| 390 |
$account->add_credit({ amount => 4 }); |
398 |
$account->add_credit({ amount => 4, interface => 'commandline' }); |
| 391 |
$account->add_credit({ amount => 5 }); |
399 |
$account->add_credit({ amount => 5, interface => 'commandline' }); |
| 392 |
|
400 |
|
| 393 |
# Add Debits TODO: replace for calls to add_debit when time comes |
401 |
# Add Debits TODO: replace for calls to add_debit when time comes |
| 394 |
Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 1, amountoutstanding => 1 })->store; |
402 |
Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 1, amountoutstanding => 1, interface => 'commandline' })->store; |
| 395 |
Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 2, amountoutstanding => 2 })->store; |
403 |
Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 2, amountoutstanding => 2, interface => 'commandline' })->store; |
| 396 |
Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 3, amountoutstanding => 3 })->store; |
404 |
Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 3, amountoutstanding => 3, interface => 'commandline' })->store; |
| 397 |
Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 4, amountoutstanding => 4 })->store; |
405 |
Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 4, amountoutstanding => 4, interface => 'commandline' })->store; |
| 398 |
|
406 |
|
| 399 |
# Paid Off |
407 |
# Paid Off |
| 400 |
Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 1, amountoutstanding => 0 })->store; |
408 |
Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 1, amountoutstanding => 0, interface => 'commandline' })->store; |
| 401 |
Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 1, amountoutstanding => 0 })->store; |
409 |
Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 1, amountoutstanding => 0, interface => 'commandline' })->store; |
| 402 |
|
410 |
|
| 403 |
is( $account->balance(), -5, "Account balance is -5" ); |
411 |
is( $account->balance(), -5, "Account balance is -5" ); |
| 404 |
is( $account->outstanding_debits->total_outstanding, 10, 'Outstanding debits sum 10' ); |
412 |
is( $account->outstanding_debits->total_outstanding, 10, 'Outstanding debits sum 10' ); |
|
Lines 423-442
subtest 'reconcile_balance' => sub {
Link Here
|
| 423 |
my $account = $patron->account; |
431 |
my $account = $patron->account; |
| 424 |
|
432 |
|
| 425 |
# Add Credits |
433 |
# Add Credits |
| 426 |
$account->add_credit({ amount => 1 }); |
434 |
$account->add_credit({ amount => 1, interface => 'commandline' }); |
| 427 |
$account->add_credit({ amount => 2 }); |
435 |
$account->add_credit({ amount => 2, interface => 'commandline' }); |
| 428 |
$account->add_credit({ amount => 3 }); |
436 |
$account->add_credit({ amount => 3, interface => 'commandline' }); |
| 429 |
$account->add_credit({ amount => 4 }); |
437 |
$account->add_credit({ amount => 4, interface => 'commandline' }); |
| 430 |
|
438 |
|
| 431 |
# Add Debits TODO: replace for calls to add_debit when time comes |
439 |
# Add Debits TODO: replace for calls to add_debit when time comes |
| 432 |
Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 1, amountoutstanding => 1 })->store; |
440 |
Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 1, amountoutstanding => 1, interface => 'commandline' })->store; |
| 433 |
Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 2, amountoutstanding => 2 })->store; |
441 |
Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 2, amountoutstanding => 2, interface => 'commandline' })->store; |
| 434 |
Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 3, amountoutstanding => 3 })->store; |
442 |
Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 3, amountoutstanding => 3, interface => 'commandline' })->store; |
| 435 |
Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 4, amountoutstanding => 4 })->store; |
443 |
Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 4, amountoutstanding => 4, interface => 'commandline' })->store; |
| 436 |
|
444 |
|
| 437 |
# Paid Off |
445 |
# Paid Off |
| 438 |
Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 1, amountoutstanding => 0 })->store; |
446 |
Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 1, amountoutstanding => 0, interface => 'commandline' })->store; |
| 439 |
Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 1, amountoutstanding => 0 })->store; |
447 |
Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 1, amountoutstanding => 0, interface => 'commandline' })->store; |
| 440 |
|
448 |
|
| 441 |
is( $account->balance(), 0, "Account balance is 0" ); |
449 |
is( $account->balance(), 0, "Account balance is 0" ); |
| 442 |
is( $account->outstanding_debits->total_outstanding, 10, 'Outstanding debits sum 10' ); |
450 |
is( $account->outstanding_debits->total_outstanding, 10, 'Outstanding debits sum 10' ); |
|
Lines 461-481
subtest 'reconcile_balance' => sub {
Link Here
|
| 461 |
my $account = $patron->account; |
469 |
my $account = $patron->account; |
| 462 |
|
470 |
|
| 463 |
# Add Credits |
471 |
# Add Credits |
| 464 |
$account->add_credit({ amount => 1 }); |
472 |
$account->add_credit({ amount => 1, interface => 'commandline' }); |
| 465 |
$account->add_credit({ amount => 2 }); |
473 |
$account->add_credit({ amount => 2, interface => 'commandline' }); |
| 466 |
$account->add_credit({ amount => 3 }); |
474 |
$account->add_credit({ amount => 3, interface => 'commandline' }); |
| 467 |
$account->add_credit({ amount => 4 }); |
475 |
$account->add_credit({ amount => 4, interface => 'commandline' }); |
| 468 |
|
476 |
|
| 469 |
# Add Debits TODO: replace for calls to add_debit when time comes |
477 |
# Add Debits TODO: replace for calls to add_debit when time comes |
| 470 |
Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 1, amountoutstanding => 1 })->store; |
478 |
Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 1, amountoutstanding => 1, interface => 'commandline' })->store; |
| 471 |
Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 2, amountoutstanding => 2 })->store; |
479 |
Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 2, amountoutstanding => 2, interface => 'commandline' })->store; |
| 472 |
Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 3, amountoutstanding => 3 })->store; |
480 |
Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 3, amountoutstanding => 3, interface => 'commandline' })->store; |
| 473 |
Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 4, amountoutstanding => 4 })->store; |
481 |
Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 4, amountoutstanding => 4, interface => 'commandline' })->store; |
| 474 |
Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 5, amountoutstanding => 5 })->store; |
482 |
Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 5, amountoutstanding => 5, interface => 'commandline' })->store; |
| 475 |
|
483 |
|
| 476 |
# Paid Off |
484 |
# Paid Off |
| 477 |
Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 1, amountoutstanding => 0 })->store; |
485 |
Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 1, amountoutstanding => 0, interface => 'commandline' })->store; |
| 478 |
Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 1, amountoutstanding => 0 })->store; |
486 |
Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 1, amountoutstanding => 0, interface => 'commandline' })->store; |
| 479 |
|
487 |
|
| 480 |
is( $account->balance(), 5, "Account balance is 5" ); |
488 |
is( $account->balance(), 5, "Account balance is 5" ); |
| 481 |
is( $account->outstanding_debits->total_outstanding, 15, 'Outstanding debits sum 15' ); |
489 |
is( $account->outstanding_debits->total_outstanding, 15, 'Outstanding debits sum 15' ); |
|
Lines 500-512
subtest 'reconcile_balance' => sub {
Link Here
|
| 500 |
my $account = $patron->account; |
508 |
my $account = $patron->account; |
| 501 |
|
509 |
|
| 502 |
# Add Credits |
510 |
# Add Credits |
| 503 |
$account->add_credit({ amount => 1 }); |
511 |
$account->add_credit({ amount => 1, interface => 'commandline' }); |
| 504 |
$account->add_credit({ amount => 3 }); |
512 |
$account->add_credit({ amount => 3, interface => 'commandline' }); |
| 505 |
|
513 |
|
| 506 |
# Add Debits TODO: replace for calls to add_debit when time comes |
514 |
# Add Debits TODO: replace for calls to add_debit when time comes |
| 507 |
my $debit_1 = Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 1, amountoutstanding => 1 })->store; |
515 |
my $debit_1 = Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 1, amountoutstanding => 1, interface => 'commandline' })->store; |
| 508 |
my $debit_2 = Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 2, amountoutstanding => 2 })->store; |
516 |
my $debit_2 = Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 2, amountoutstanding => 2, interface => 'commandline' })->store; |
| 509 |
my $debit_3 = Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 3, amountoutstanding => 3 })->store; |
517 |
my $debit_3 = Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 3, amountoutstanding => 3, interface => 'commandline' })->store; |
| 510 |
|
518 |
|
| 511 |
is( $account->balance(), 2, "Account balance is 2" ); |
519 |
is( $account->balance(), 2, "Account balance is 2" ); |
| 512 |
is( $account->outstanding_debits->total_outstanding, 6, 'Outstanding debits sum 6' ); |
520 |
is( $account->outstanding_debits->total_outstanding, 6, 'Outstanding debits sum 6' ); |