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