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

(-)a/t/db_dependent/Accounts.t (-66 lines)
Lines 958-1029 subtest "Koha::Account::non_issues_charges tests" => sub { Link Here
958
    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
    is( Koha::Account::Lines->count({ borrowernumber => $patron->id }), 2 + 2, "The 2 + 2 account lines still exists, the last 2 have been deleted ok" );
959
};
959
};
960
960
961
subtest "Koha::Account::Line::void tests" => sub {
962
963
    plan tests => 15;
964
965
    # Create a borrower
966
    my $categorycode = $builder->build({ source => 'Category' })->{ categorycode };
967
    my $branchcode   = $builder->build({ source => 'Branch' })->{ branchcode };
968
969
    my $borrower = Koha::Patron->new( {
970
        cardnumber => 'dariahall',
971
        surname => 'Hall',
972
        firstname => 'Daria',
973
    } );
974
    $borrower->categorycode( $categorycode );
975
    $borrower->branchcode( $branchcode );
976
    $borrower->store;
977
978
    my $account = Koha::Account->new({ patron_id => $borrower->id });
979
980
    my $line1 = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amount => 10, amountoutstanding => 10, interface => 'commandline'  })->store();
981
    my $line2 = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amount => 20, amountoutstanding => 20, interface => 'commandline'  })->store();
982
983
    is( $account->balance(), 30, "Account balance is 30" );
984
    is( $line1->amountoutstanding, 10, 'First fee has amount outstanding of 10' );
985
    is( $line2->amountoutstanding, 20, 'Second fee has amount outstanding of 20' );
986
987
    my $id = $account->pay(
988
        {
989
            lines  => [$line1, $line2],
990
            amount => 30,
991
        }
992
    );
993
994
    my $account_payment = Koha::Account::Lines->find( $id );
995
996
    is( $account->balance(), 0, "Account balance is 0" );
997
998
    $line1->_result->discard_changes();
999
    $line2->_result->discard_changes();
1000
    is( $line1->amountoutstanding+0, 0, 'First fee has amount outstanding of 0' );
1001
    is( $line2->amountoutstanding+0, 0, 'Second fee has amount outstanding of 0' );
1002
1003
    my $ret = $account_payment->void();
1004
1005
    is( ref($ret), 'Koha::Account::Line', 'Void returns the account line' );
1006
    is( $account->balance(), 30, "Account balance is again 30" );
1007
1008
    $account_payment->_result->discard_changes();
1009
    $line1->_result->discard_changes();
1010
    $line2->_result->discard_changes();
1011
1012
    is( $account_payment->accounttype, 'VOID', 'Voided payment accounttype is VOID' );
1013
    is( $account_payment->amount+0, 0, 'Voided payment amount is 0' );
1014
    is( $account_payment->amountoutstanding+0, 0, 'Voided payment amount outstanding is 0' );
1015
1016
    is( $line1->amountoutstanding+0, 10, 'First fee again has amount outstanding of 10' );
1017
    is( $line2->amountoutstanding+0, 20, 'Second fee again has amount outstanding of 20' );
1018
1019
    # Accountlines that are not credits should be un-voidable
1020
    my $line1_pre = $line1->unblessed();
1021
    $ret = $line1->void();
1022
    $line1->_result->discard_changes();
1023
    my $line1_post = $line1->unblessed();
1024
    is( $ret, undef, 'Attempted void on non-credit returns undef' );
1025
    is_deeply( $line1_pre, $line1_post, 'Non-credit account line cannot be voided' )
1026
};
1027
961
1028
subtest "Koha::Account::Offset credit & debit tests" => sub {
962
subtest "Koha::Account::Offset credit & debit tests" => sub {
1029
963
(-)a/t/db_dependent/Koha/Account/Lines.t (-1 / +68 lines)
Lines 489-492 subtest 'checkout() tests' => sub { Link Here
489
    $schema->storage->txn_rollback;
489
    $schema->storage->txn_rollback;
490
};
490
};
491
491
492
subtest "void() tests" => sub {
493
494
    plan tests => 15;
495
496
    # Create a borrower
497
    my $categorycode = $builder->build({ source => 'Category' })->{ categorycode };
498
    my $branchcode   = $builder->build({ source => 'Branch' })->{ branchcode };
499
500
    my $borrower = Koha::Patron->new( {
501
        cardnumber => 'dariahall',
502
        surname => 'Hall',
503
        firstname => 'Daria',
504
    } );
505
    $borrower->categorycode( $categorycode );
506
    $borrower->branchcode( $branchcode );
507
    $borrower->store;
508
509
    my $account = Koha::Account->new({ patron_id => $borrower->id });
510
511
    my $line1 = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amount => 10, amountoutstanding => 10, interface => 'commandline' })->store();
512
    my $line2 = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amount => 20, amountoutstanding => 20, interface => 'commandline' })->store();
513
514
    is( $account->balance(), 30, "Account balance is 30" );
515
    is( $line1->amountoutstanding, 10, 'First fee has amount outstanding of 10' );
516
    is( $line2->amountoutstanding, 20, 'Second fee has amount outstanding of 20' );
517
518
    my $id = $account->pay(
519
        {
520
            lines  => [$line1, $line2],
521
            amount => 30,
522
        }
523
    );
524
525
    my $account_payment = Koha::Account::Lines->find( $id );
526
527
    is( $account->balance(), 0, "Account balance is 0" );
528
529
    $line1->_result->discard_changes();
530
    $line2->_result->discard_changes();
531
    is( $line1->amountoutstanding+0, 0, 'First fee has amount outstanding of 0' );
532
    is( $line2->amountoutstanding+0, 0, 'Second fee has amount outstanding of 0' );
533
534
    my $ret = $account_payment->void();
535
536
    is( ref($ret), 'Koha::Account::Line', 'Void returns the account line' );
537
    is( $account->balance(), 30, "Account balance is again 30" );
538
539
    $account_payment->_result->discard_changes();
540
    $line1->_result->discard_changes();
541
    $line2->_result->discard_changes();
542
543
    is( $account_payment->accounttype, 'Pay', 'Voided payment accounttype is still Pay' );
544
    is( $account_payment->status, 'VOID', 'Voided payment status is VOID' );
545
    is( $account_payment->amount+0, 0, 'Voided payment amount is 0' );
546
    is( $account_payment->amountoutstanding+0, 0, 'Voided payment amount outstanding is 0' );
547
548
    is( $line1->amountoutstanding+0, 10, 'First fee again has amount outstanding of 10' );
549
    is( $line2->amountoutstanding+0, 20, 'Second fee again has amount outstanding of 20' );
550
551
    # Accountlines that are not credits should be un-voidable
552
    my $line1_pre = $line1->unblessed();
553
    $ret = $line1->void();
554
    $line1->_result->discard_changes();
555
    my $line1_post = $line1->unblessed();
556
    is( $ret, undef, 'Attempted void on non-credit returns undef' );
557
    is_deeply( $line1_pre, $line1_post, 'Non-credit account line cannot be voided' )
558
};
559
492
1;
560
1;
493
- 

Return to bug 22511