View | Details | Raw Unified | Return to bug 22511
Collapse All | Expand All

(-)a/t/db_dependent/Accounts.t (-67 lines)
Lines 957-1029 subtest "Koha::Account::non_issues_charges tests" => sub { Link Here
957
    is( Koha::Account::Lines->count({ borrowernumber => $patron->id }), 2 + 2, "The 2 + 2 account lines still exists, the last 2 have been deleted ok" );
957
    is( Koha::Account::Lines->count({ borrowernumber => $patron->id }), 2 + 2, "The 2 + 2 account lines still exists, the last 2 have been deleted ok" );
958
};
958
};
959
959
960
subtest "Koha::Account::Line::void tests" => sub {
961
962
    plan tests => 15;
963
964
    # Create a borrower
965
    my $categorycode = $builder->build({ source => 'Category' })->{ categorycode };
966
    my $branchcode   = $builder->build({ source => 'Branch' })->{ branchcode };
967
968
    my $borrower = Koha::Patron->new( {
969
        cardnumber => 'dariahall',
970
        surname => 'Hall',
971
        firstname => 'Daria',
972
    } );
973
    $borrower->categorycode( $categorycode );
974
    $borrower->branchcode( $branchcode );
975
    $borrower->store;
976
977
    my $account = Koha::Account->new({ patron_id => $borrower->id });
978
979
    my $line1 = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amount => 10, amountoutstanding => 10 })->store();
980
    my $line2 = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amount => 20, amountoutstanding => 20 })->store();
981
982
    is( $account->balance(), 30, "Account balance is 30" );
983
    is( $line1->amountoutstanding, 10, 'First fee has amount outstanding of 10' );
984
    is( $line2->amountoutstanding, 20, 'Second fee has amount outstanding of 20' );
985
986
    my $id = $account->pay(
987
        {
988
            lines  => [$line1, $line2],
989
            amount => 30,
990
        }
991
    );
992
993
    my $account_payment = Koha::Account::Lines->find( $id );
994
995
    is( $account->balance(), 0, "Account balance is 0" );
996
997
    $line1->_result->discard_changes();
998
    $line2->_result->discard_changes();
999
    is( $line1->amountoutstanding+0, 0, 'First fee has amount outstanding of 0' );
1000
    is( $line2->amountoutstanding+0, 0, 'Second fee has amount outstanding of 0' );
1001
1002
    my $ret = $account_payment->void();
1003
1004
    is( ref($ret), 'Koha::Account::Line', 'Void returns the account line' );
1005
    is( $account->balance(), 30, "Account balance is again 30" );
1006
1007
    $account_payment->_result->discard_changes();
1008
    $line1->_result->discard_changes();
1009
    $line2->_result->discard_changes();
1010
1011
    is( $account_payment->accounttype, 'VOID', 'Voided payment accounttype is VOID' );
1012
    is( $account_payment->amount+0, 0, 'Voided payment amount is 0' );
1013
    is( $account_payment->amountoutstanding+0, 0, 'Voided payment amount outstanding is 0' );
1014
1015
    is( $line1->amountoutstanding+0, 10, 'First fee again has amount outstanding of 10' );
1016
    is( $line2->amountoutstanding+0, 20, 'Second fee again has amount outstanding of 20' );
1017
1018
    # Accountlines that are not credits should be un-voidable
1019
    my $line1_pre = $line1->unblessed();
1020
    $ret = $line1->void();
1021
    $line1->_result->discard_changes();
1022
    my $line1_post = $line1->unblessed();
1023
    is( $ret, undef, 'Attempted void on non-credit returns undef' );
1024
    is_deeply( $line1_pre, $line1_post, 'Non-credit account line cannot be voided' )
1025
};
1026
1027
subtest "Koha::Account::Offset credit & debit tests" => sub {
960
subtest "Koha::Account::Offset credit & debit tests" => sub {
1028
961
1029
    plan tests => 4;
962
    plan tests => 4;
(-)a/t/db_dependent/Koha/Account/Lines.t (-1 / +68 lines)
Lines 453-456 subtest 'checkout() tests' => sub { Link Here
453
    $schema->storage->txn_rollback;
453
    $schema->storage->txn_rollback;
454
};
454
};
455
455
456
subtest "void() tests" => sub {
457
458
    plan tests => 15;
459
460
    # Create a borrower
461
    my $categorycode = $builder->build({ source => 'Category' })->{ categorycode };
462
    my $branchcode   = $builder->build({ source => 'Branch' })->{ branchcode };
463
464
    my $borrower = Koha::Patron->new( {
465
        cardnumber => 'dariahall',
466
        surname => 'Hall',
467
        firstname => 'Daria',
468
    } );
469
    $borrower->categorycode( $categorycode );
470
    $borrower->branchcode( $branchcode );
471
    $borrower->store;
472
473
    my $account = Koha::Account->new({ patron_id => $borrower->id });
474
475
    my $line1 = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amount => 10, amountoutstanding => 10 })->store();
476
    my $line2 = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amount => 20, amountoutstanding => 20 })->store();
477
478
    is( $account->balance(), 30, "Account balance is 30" );
479
    is( $line1->amountoutstanding, 10, 'First fee has amount outstanding of 10' );
480
    is( $line2->amountoutstanding, 20, 'Second fee has amount outstanding of 20' );
481
482
    my $id = $account->pay(
483
        {
484
            lines  => [$line1, $line2],
485
            amount => 30,
486
        }
487
    );
488
489
    my $account_payment = Koha::Account::Lines->find( $id );
490
491
    is( $account->balance(), 0, "Account balance is 0" );
492
493
    $line1->_result->discard_changes();
494
    $line2->_result->discard_changes();
495
    is( $line1->amountoutstanding+0, 0, 'First fee has amount outstanding of 0' );
496
    is( $line2->amountoutstanding+0, 0, 'Second fee has amount outstanding of 0' );
497
498
    my $ret = $account_payment->void();
499
500
    is( ref($ret), 'Koha::Account::Line', 'Void returns the account line' );
501
    is( $account->balance(), 30, "Account balance is again 30" );
502
503
    $account_payment->_result->discard_changes();
504
    $line1->_result->discard_changes();
505
    $line2->_result->discard_changes();
506
507
    is( $account_payment->accounttype, 'Pay', 'Voided payment accounttype is still Pay' );
508
    is( $account_payment->status, 'VOID', 'Voided payment status is VOID' );
509
    is( $account_payment->amount+0, 0, 'Voided payment amount is 0' );
510
    is( $account_payment->amountoutstanding+0, 0, 'Voided payment amount outstanding is 0' );
511
512
    is( $line1->amountoutstanding+0, 10, 'First fee again has amount outstanding of 10' );
513
    is( $line2->amountoutstanding+0, 20, 'Second fee again has amount outstanding of 20' );
514
515
    # Accountlines that are not credits should be un-voidable
516
    my $line1_pre = $line1->unblessed();
517
    $ret = $line1->void();
518
    $line1->_result->discard_changes();
519
    my $line1_post = $line1->unblessed();
520
    is( $ret, undef, 'Attempted void on non-credit returns undef' );
521
    is_deeply( $line1_pre, $line1_post, 'Non-credit account line cannot be voided' )
522
};
523
456
1;
524
1;
457
- 

Return to bug 22511