Lines 194-200
subtest 'add_credit() tests' => sub {
Link Here
|
194 |
|
194 |
|
195 |
subtest 'reconcile_balance' => sub { |
195 |
subtest 'reconcile_balance' => sub { |
196 |
|
196 |
|
197 |
plan tests => 3; |
197 |
plan tests => 4; |
198 |
|
198 |
|
199 |
subtest 'more credit than debit' => sub { |
199 |
subtest 'more credit than debit' => sub { |
200 |
|
200 |
|
Lines 311-314
subtest 'reconcile_balance' => sub {
Link Here
|
311 |
|
311 |
|
312 |
$schema->storage->txn_rollback; |
312 |
$schema->storage->txn_rollback; |
313 |
}; |
313 |
}; |
|
|
314 |
|
315 |
subtest 'credits are applied to older debits first' => sub { |
316 |
|
317 |
plan tests => 9; |
318 |
|
319 |
$schema->storage->txn_begin; |
320 |
|
321 |
my $patron = $builder->build_object({ class => 'Koha::Patrons' }); |
322 |
my $account = $patron->account; |
323 |
|
324 |
# Add Credits |
325 |
$account->add_credit({ amount => 1 }); |
326 |
$account->add_credit({ amount => 3 }); |
327 |
|
328 |
# Add Debits TODO: replace for calls to add_debit when time comes |
329 |
my $debit_1 = Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 1, amountoutstanding => 1 })->store; |
330 |
my $debit_2 = Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 2, amountoutstanding => 2 })->store; |
331 |
my $debit_3 = Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 3, amountoutstanding => 3 })->store; |
332 |
|
333 |
is( $account->balance(), 2, "Account balance is 2" ); |
334 |
is( $account->outstanding_debits->total_outstanding, 6, 'Outstanding debits sum 6' ); |
335 |
is( $account->outstanding_credits->total_outstanding, -4, 'Outstanding credits sum -4' ); |
336 |
|
337 |
$account->reconcile_balance(); |
338 |
|
339 |
is( $account->balance(), 2, "Account balance is 2" ); |
340 |
is( $account->outstanding_debits->total_outstanding, 2, 'Outstanding debits sum 2' ); |
341 |
is( $account->outstanding_credits->total_outstanding, 0, 'Outstanding credits sum 0' ); |
342 |
|
343 |
$debit_1->discard_changes; |
344 |
is( $debit_1->amountoutstanding + 0, 0, 'Old debit payed' ); |
345 |
$debit_2->discard_changes; |
346 |
is( $debit_2->amountoutstanding + 0, 0, 'Old debit payed' ); |
347 |
$debit_3->discard_changes; |
348 |
is( $debit_3->amountoutstanding + 0, 2, 'Newest debit only partially payed' ); |
349 |
|
350 |
$schema->storage->txn_rollback; |
351 |
}; |
314 |
}; |
352 |
}; |
315 |
- |
|
|