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; |