Lines 228-234
subtest 'lines() tests' => sub {
Link Here
|
228 |
|
228 |
|
229 |
subtest 'reconcile_balance' => sub { |
229 |
subtest 'reconcile_balance' => sub { |
230 |
|
230 |
|
231 |
plan tests => 3; |
231 |
plan tests => 4; |
232 |
|
232 |
|
233 |
subtest 'more credit than debit' => sub { |
233 |
subtest 'more credit than debit' => sub { |
234 |
|
234 |
|
Lines 345-348
subtest 'reconcile_balance' => sub {
Link Here
|
345 |
|
345 |
|
346 |
$schema->storage->txn_rollback; |
346 |
$schema->storage->txn_rollback; |
347 |
}; |
347 |
}; |
|
|
348 |
|
349 |
subtest 'credits are applied to older debits first' => sub { |
350 |
|
351 |
plan tests => 9; |
352 |
|
353 |
$schema->storage->txn_begin; |
354 |
|
355 |
my $patron = $builder->build_object({ class => 'Koha::Patrons' }); |
356 |
my $account = $patron->account; |
357 |
|
358 |
# Add Credits |
359 |
$account->add_credit({ amount => 1 }); |
360 |
$account->add_credit({ amount => 3 }); |
361 |
|
362 |
# Add Debits TODO: replace for calls to add_debit when time comes |
363 |
my $debit_1 = Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 1, amountoutstanding => 1 })->store; |
364 |
my $debit_2 = Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 2, amountoutstanding => 2 })->store; |
365 |
my $debit_3 = Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 3, amountoutstanding => 3 })->store; |
366 |
|
367 |
is( $account->balance(), 2, "Account balance is 2" ); |
368 |
is( $account->outstanding_debits->total_outstanding, 6, 'Outstanding debits sum 6' ); |
369 |
is( $account->outstanding_credits->total_outstanding, -4, 'Outstanding credits sum -4' ); |
370 |
|
371 |
$account->reconcile_balance(); |
372 |
|
373 |
is( $account->balance(), 2, "Account balance is 2" ); |
374 |
is( $account->outstanding_debits->total_outstanding, 2, 'Outstanding debits sum 2' ); |
375 |
is( $account->outstanding_credits->total_outstanding, 0, 'Outstanding credits sum 0' ); |
376 |
|
377 |
$debit_1->discard_changes; |
378 |
is( $debit_1->amountoutstanding + 0, 0, 'Old debit payed' ); |
379 |
$debit_2->discard_changes; |
380 |
is( $debit_2->amountoutstanding + 0, 0, 'Old debit payed' ); |
381 |
$debit_3->discard_changes; |
382 |
is( $debit_3->amountoutstanding + 0, 2, 'Newest debit only partially payed' ); |
383 |
|
384 |
$schema->storage->txn_rollback; |
385 |
}; |
348 |
}; |
386 |
}; |
349 |
- |
|
|