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 479-482 subtest 'checkout() tests' => sub { Link Here
479
    $schema->storage->txn_rollback;
479
    $schema->storage->txn_rollback;
480
};
480
};
481
481
482
subtest "void() tests" => sub {
483
484
    plan tests => 15;
485
486
    # Create a borrower
487
    my $categorycode = $builder->build({ source => 'Category' })->{ categorycode };
488
    my $branchcode   = $builder->build({ source => 'Branch' })->{ branchcode };
489
490
    my $borrower = Koha::Patron->new( {
491
        cardnumber => 'dariahall',
492
        surname => 'Hall',
493
        firstname => 'Daria',
494
    } );
495
    $borrower->categorycode( $categorycode );
496
    $borrower->branchcode( $branchcode );
497
    $borrower->store;
498
499
    my $account = Koha::Account->new({ patron_id => $borrower->id });
500
501
    my $line1 = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amount => 10, amountoutstanding => 10 })->store();
502
    my $line2 = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amount => 20, amountoutstanding => 20 })->store();
503
504
    is( $account->balance(), 30, "Account balance is 30" );
505
    is( $line1->amountoutstanding, 10, 'First fee has amount outstanding of 10' );
506
    is( $line2->amountoutstanding, 20, 'Second fee has amount outstanding of 20' );
507
508
    my $id = $account->pay(
509
        {
510
            lines  => [$line1, $line2],
511
            amount => 30,
512
        }
513
    );
514
515
    my $account_payment = Koha::Account::Lines->find( $id );
516
517
    is( $account->balance(), 0, "Account balance is 0" );
518
519
    $line1->_result->discard_changes();
520
    $line2->_result->discard_changes();
521
    is( $line1->amountoutstanding+0, 0, 'First fee has amount outstanding of 0' );
522
    is( $line2->amountoutstanding+0, 0, 'Second fee has amount outstanding of 0' );
523
524
    my $ret = $account_payment->void();
525
526
    is( ref($ret), 'Koha::Account::Line', 'Void returns the account line' );
527
    is( $account->balance(), 30, "Account balance is again 30" );
528
529
    $account_payment->_result->discard_changes();
530
    $line1->_result->discard_changes();
531
    $line2->_result->discard_changes();
532
533
    is( $account_payment->accounttype, 'Pay', 'Voided payment accounttype is still Pay' );
534
    is( $account_payment->status, 'VOID', 'Voided payment status is VOID' );
535
    is( $account_payment->amount+0, 0, 'Voided payment amount is 0' );
536
    is( $account_payment->amountoutstanding+0, 0, 'Voided payment amount outstanding is 0' );
537
538
    is( $line1->amountoutstanding+0, 10, 'First fee again has amount outstanding of 10' );
539
    is( $line2->amountoutstanding+0, 20, 'Second fee again has amount outstanding of 20' );
540
541
    # Accountlines that are not credits should be un-voidable
542
    my $line1_pre = $line1->unblessed();
543
    $ret = $line1->void();
544
    $line1->_result->discard_changes();
545
    my $line1_post = $line1->unblessed();
546
    is( $ret, undef, 'Attempted void on non-credit returns undef' );
547
    is_deeply( $line1_pre, $line1_post, 'Non-credit account line cannot be voided' )
548
};
549
482
1;
550
1;
483
- 

Return to bug 22511