Lines 371-377
subtest 'list_debits() test' => sub {
Link Here
|
371 |
|
371 |
|
372 |
subtest 'add_debit() tests' => sub { |
372 |
subtest 'add_debit() tests' => sub { |
373 |
|
373 |
|
374 |
plan tests => 13; |
374 |
plan tests => 18; |
375 |
|
375 |
|
376 |
$schema->storage->txn_begin; |
376 |
$schema->storage->txn_begin; |
377 |
|
377 |
|
Lines 397-403
subtest 'add_debit() tests' => sub {
Link Here
|
397 |
my $debit = { |
397 |
my $debit = { |
398 |
amount => 100, |
398 |
amount => 100, |
399 |
description => "A description", |
399 |
description => "A description", |
400 |
debit_type => "NEW_CARD", |
400 |
type => "NEW_CARD", |
401 |
user_id => $patron->borrowernumber, |
401 |
user_id => $patron->borrowernumber, |
402 |
interface => 'test', |
402 |
interface => 'test', |
403 |
library_id => $library->id, |
403 |
library_id => $library->id, |
Lines 406-421
subtest 'add_debit() tests' => sub {
Link Here
|
406 |
my $ret = $t->post_ok( |
406 |
my $ret = $t->post_ok( |
407 |
"//$userid:$password@/api/v1/patrons/$patron_id/account/debits" => |
407 |
"//$userid:$password@/api/v1/patrons/$patron_id/account/debits" => |
408 |
json => $debit )->status_is(201)->tx->res->json; |
408 |
json => $debit )->status_is(201)->tx->res->json; |
409 |
my $account_line = Koha::Account::Lines->find( $ret->{account_line_id} ); |
409 |
my $account_line = Koha::Account::Debits->find( $ret->{account_line_id} ); |
410 |
|
410 |
|
411 |
is_deeply( $ret, $account_line->to_api, 'Line returned correctly' ); |
411 |
is_deeply( $ret, $account_line->to_api, 'Line returned correctly' ); |
412 |
|
412 |
|
413 |
is( $account_line->branchcode, |
413 |
is( $account_line->branchcode, |
414 |
$library->id, 'Library id is sored correctly' ); |
414 |
$library->id, 'Library id is stored correctly' ); |
415 |
|
415 |
|
416 |
my $outstanding_debits = $account->outstanding_debits; |
416 |
my $outstanding_debits = $account->outstanding_debits; |
417 |
is( $outstanding_debits->count, 1 ); |
417 |
is( $outstanding_debits->count, 1, "One outstanding debit added" ); |
418 |
is( $outstanding_debits->total_outstanding, 100 ); |
418 |
is( $outstanding_debits->total_outstanding, 100, "Outstanding debit is 100" ); |
419 |
|
419 |
|
420 |
my $credit_1 = $account->add_credit( |
420 |
my $credit_1 = $account->add_credit( |
421 |
{ |
421 |
{ |
Lines 430-436
subtest 'add_debit() tests' => sub {
Link Here
|
430 |
} |
430 |
} |
431 |
)->store()->apply( { debits => [$account_line] } ); |
431 |
)->store()->apply( { debits => [$account_line] } ); |
432 |
|
432 |
|
433 |
is( $account->outstanding_credits->total_outstanding, 0 ); |
433 |
is( $account->outstanding_credits->total_outstanding, 0, "Credits all applied" ); |
434 |
is( $account->outstanding_debits->total_outstanding, |
434 |
is( $account->outstanding_debits->total_outstanding, |
435 |
75, "Credits partially cancelled debit" ); |
435 |
75, "Credits partially cancelled debit" ); |
436 |
|
436 |
|
Lines 443-447
subtest 'add_debit() tests' => sub {
Link Here
|
443 |
is( $account->outstanding_debits->total_outstanding, |
443 |
is( $account->outstanding_debits->total_outstanding, |
444 |
175, "Debit added to total outstanding debits" ); |
444 |
175, "Debit added to total outstanding debits" ); |
445 |
|
445 |
|
|
|
446 |
# Cash register handling and PAYOUTs |
447 |
t::lib::Mocks::mock_preference( 'UseCashRegisters', 1 ); |
448 |
my $payout = { |
449 |
amount => 10, |
450 |
description => "A description", |
451 |
type => "PAYOUT", |
452 |
payout_type => "CASH", |
453 |
user_id => $patron->borrowernumber, |
454 |
interface => 'test', |
455 |
library_id => $library->id, |
456 |
}; |
457 |
|
458 |
$t->post_ok( |
459 |
"//$userid:$password@/api/v1/patrons/$patron_id/account/debits" => |
460 |
json => $payout )->status_is(400) |
461 |
->json_is( '/error' => 'Account transaction requires a cash register' ); |
462 |
|
463 |
my $register = $builder->build_object( |
464 |
{ |
465 |
class => 'Koha::Cash::Registers', |
466 |
} |
467 |
); |
468 |
$payout->{cash_register_id} = $register->id; |
469 |
my $res = $t->post_ok( |
470 |
"//$userid:$password@/api/v1/patrons/$patron_id/account/debits" => |
471 |
json => $payout )->status_is(201)->tx->res->json; |
472 |
|
446 |
$schema->storage->txn_rollback; |
473 |
$schema->storage->txn_rollback; |
447 |
}; |
474 |
}; |
448 |
- |
|
|