Lines 296-302
subtest 'add_credit() tests' => sub {
Link Here
|
296 |
|
296 |
|
297 |
subtest 'add_debit() tests' => sub { |
297 |
subtest 'add_debit() tests' => sub { |
298 |
|
298 |
|
299 |
plan tests => 13; |
299 |
plan tests => 18; |
300 |
|
300 |
|
301 |
$schema->storage->txn_begin; |
301 |
$schema->storage->txn_begin; |
302 |
|
302 |
|
Lines 322-328
subtest 'add_debit() tests' => sub {
Link Here
|
322 |
my $debit = { |
322 |
my $debit = { |
323 |
amount => 100, |
323 |
amount => 100, |
324 |
description => "A description", |
324 |
description => "A description", |
325 |
debit_type => "NEW_CARD", |
325 |
type => "NEW_CARD", |
326 |
user_id => $patron->borrowernumber, |
326 |
user_id => $patron->borrowernumber, |
327 |
interface => 'test', |
327 |
interface => 'test', |
328 |
library_id => $library->id, |
328 |
library_id => $library->id, |
Lines 331-346
subtest 'add_debit() tests' => sub {
Link Here
|
331 |
my $ret = $t->post_ok( |
331 |
my $ret = $t->post_ok( |
332 |
"//$userid:$password@/api/v1/patrons/$patron_id/account/debits" => |
332 |
"//$userid:$password@/api/v1/patrons/$patron_id/account/debits" => |
333 |
json => $debit )->status_is(201)->tx->res->json; |
333 |
json => $debit )->status_is(201)->tx->res->json; |
334 |
my $account_line = Koha::Account::Lines->find( $ret->{account_line_id} ); |
334 |
my $account_line = Koha::Account::Debits->find( $ret->{account_line_id} ); |
335 |
|
335 |
|
336 |
is_deeply( $ret, $account_line->to_api, 'Line returned correctly' ); |
336 |
is_deeply( $ret, $account_line->to_api, 'Line returned correctly' ); |
337 |
|
337 |
|
338 |
is( $account_line->branchcode, |
338 |
is( $account_line->branchcode, |
339 |
$library->id, 'Library id is sored correctly' ); |
339 |
$library->id, 'Library id is stored correctly' ); |
340 |
|
340 |
|
341 |
my $outstanding_debits = $account->outstanding_debits; |
341 |
my $outstanding_debits = $account->outstanding_debits; |
342 |
is( $outstanding_debits->count, 1 ); |
342 |
is( $outstanding_debits->count, 1, "One outstanding debit added" ); |
343 |
is( $outstanding_debits->total_outstanding, 100 ); |
343 |
is( $outstanding_debits->total_outstanding, 100, "Outstanding debit is 100" ); |
344 |
|
344 |
|
345 |
my $credit_1 = $account->add_credit( |
345 |
my $credit_1 = $account->add_credit( |
346 |
{ |
346 |
{ |
Lines 355-361
subtest 'add_debit() tests' => sub {
Link Here
|
355 |
} |
355 |
} |
356 |
)->store()->apply( { debits => [$account_line] } ); |
356 |
)->store()->apply( { debits => [$account_line] } ); |
357 |
|
357 |
|
358 |
is( $account->outstanding_credits->total_outstanding, 0 ); |
358 |
is( $account->outstanding_credits->total_outstanding, 0, "Credits all applied" ); |
359 |
is( $account->outstanding_debits->total_outstanding, |
359 |
is( $account->outstanding_debits->total_outstanding, |
360 |
75, "Credits partially cancelled debit" ); |
360 |
75, "Credits partially cancelled debit" ); |
361 |
|
361 |
|
Lines 368-372
subtest 'add_debit() tests' => sub {
Link Here
|
368 |
is( $account->outstanding_debits->total_outstanding, |
368 |
is( $account->outstanding_debits->total_outstanding, |
369 |
175, "Debit added to total outstanding debits" ); |
369 |
175, "Debit added to total outstanding debits" ); |
370 |
|
370 |
|
|
|
371 |
# Cash register handling and PAYOUTs |
372 |
t::lib::Mocks::mock_preference( 'UseCashRegisters', 1 ); |
373 |
my $payout = { |
374 |
amount => 10, |
375 |
description => "A description", |
376 |
type => "PAYOUT", |
377 |
payout_type => "CASH", |
378 |
user_id => $patron->borrowernumber, |
379 |
interface => 'test', |
380 |
library_id => $library->id, |
381 |
}; |
382 |
|
383 |
$t->post_ok( |
384 |
"//$userid:$password@/api/v1/patrons/$patron_id/account/debits" => |
385 |
json => $payout )->status_is(400) |
386 |
->json_is( '/error' => 'Account transaction requires a cash register' ); |
387 |
|
388 |
my $register = $builder->build_object( |
389 |
{ |
390 |
class => 'Koha::Cash::Registers', |
391 |
} |
392 |
); |
393 |
$payout->{cash_register_id} = $register->id; |
394 |
my $res = $t->post_ok( |
395 |
"//$userid:$password@/api/v1/patrons/$patron_id/account/debits" => |
396 |
json => $payout )->status_is(201)->tx->res->json; |
397 |
|
371 |
$schema->storage->txn_rollback; |
398 |
$schema->storage->txn_rollback; |
372 |
}; |
399 |
}; |
373 |
- |
|
|