diff --git a/t/db_dependent/Accounts.t b/t/db_dependent/Accounts.t index 791af7875b..e1ba90d124 100644 --- a/t/db_dependent/Accounts.t +++ b/t/db_dependent/Accounts.t @@ -958,72 +958,6 @@ subtest "Koha::Account::non_issues_charges tests" => sub { is( Koha::Account::Lines->count({ borrowernumber => $patron->id }), 2 + 2, "The 2 + 2 account lines still exists, the last 2 have been deleted ok" ); }; -subtest "Koha::Account::Line::void tests" => sub { - - plan tests => 15; - - # Create a borrower - my $categorycode = $builder->build({ source => 'Category' })->{ categorycode }; - my $branchcode = $builder->build({ source => 'Branch' })->{ branchcode }; - - my $borrower = Koha::Patron->new( { - cardnumber => 'dariahall', - surname => 'Hall', - firstname => 'Daria', - } ); - $borrower->categorycode( $categorycode ); - $borrower->branchcode( $branchcode ); - $borrower->store; - - my $account = Koha::Account->new({ patron_id => $borrower->id }); - - my $line1 = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amount => 10, amountoutstanding => 10, interface => 'commandline' })->store(); - my $line2 = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amount => 20, amountoutstanding => 20, interface => 'commandline' })->store(); - - is( $account->balance(), 30, "Account balance is 30" ); - is( $line1->amountoutstanding, 10, 'First fee has amount outstanding of 10' ); - is( $line2->amountoutstanding, 20, 'Second fee has amount outstanding of 20' ); - - my $id = $account->pay( - { - lines => [$line1, $line2], - amount => 30, - } - ); - - my $account_payment = Koha::Account::Lines->find( $id ); - - is( $account->balance(), 0, "Account balance is 0" ); - - $line1->_result->discard_changes(); - $line2->_result->discard_changes(); - is( $line1->amountoutstanding+0, 0, 'First fee has amount outstanding of 0' ); - is( $line2->amountoutstanding+0, 0, 'Second fee has amount outstanding of 0' ); - - my $ret = $account_payment->void(); - - is( ref($ret), 'Koha::Account::Line', 'Void returns the account line' ); - is( $account->balance(), 30, "Account balance is again 30" ); - - $account_payment->_result->discard_changes(); - $line1->_result->discard_changes(); - $line2->_result->discard_changes(); - - is( $account_payment->accounttype, 'VOID', 'Voided payment accounttype is VOID' ); - is( $account_payment->amount+0, 0, 'Voided payment amount is 0' ); - is( $account_payment->amountoutstanding+0, 0, 'Voided payment amount outstanding is 0' ); - - is( $line1->amountoutstanding+0, 10, 'First fee again has amount outstanding of 10' ); - is( $line2->amountoutstanding+0, 20, 'Second fee again has amount outstanding of 20' ); - - # Accountlines that are not credits should be un-voidable - my $line1_pre = $line1->unblessed(); - $ret = $line1->void(); - $line1->_result->discard_changes(); - my $line1_post = $line1->unblessed(); - is( $ret, undef, 'Attempted void on non-credit returns undef' ); - is_deeply( $line1_pre, $line1_post, 'Non-credit account line cannot be voided' ) -}; subtest "Koha::Account::Offset credit & debit tests" => sub { diff --git a/t/db_dependent/Koha/Account/Lines.t b/t/db_dependent/Koha/Account/Lines.t index 610a342b3a..f0087a9935 100755 --- a/t/db_dependent/Koha/Account/Lines.t +++ b/t/db_dependent/Koha/Account/Lines.t @@ -489,4 +489,72 @@ subtest 'checkout() tests' => sub { $schema->storage->txn_rollback; }; +subtest "void() tests" => sub { + + plan tests => 15; + + # Create a borrower + my $categorycode = $builder->build({ source => 'Category' })->{ categorycode }; + my $branchcode = $builder->build({ source => 'Branch' })->{ branchcode }; + + my $borrower = Koha::Patron->new( { + cardnumber => 'dariahall', + surname => 'Hall', + firstname => 'Daria', + } ); + $borrower->categorycode( $categorycode ); + $borrower->branchcode( $branchcode ); + $borrower->store; + + my $account = Koha::Account->new({ patron_id => $borrower->id }); + + my $line1 = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amount => 10, amountoutstanding => 10, interface => 'commandline' })->store(); + my $line2 = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amount => 20, amountoutstanding => 20, interface => 'commandline' })->store(); + + is( $account->balance(), 30, "Account balance is 30" ); + is( $line1->amountoutstanding, 10, 'First fee has amount outstanding of 10' ); + is( $line2->amountoutstanding, 20, 'Second fee has amount outstanding of 20' ); + + my $id = $account->pay( + { + lines => [$line1, $line2], + amount => 30, + } + ); + + my $account_payment = Koha::Account::Lines->find( $id ); + + is( $account->balance(), 0, "Account balance is 0" ); + + $line1->_result->discard_changes(); + $line2->_result->discard_changes(); + is( $line1->amountoutstanding+0, 0, 'First fee has amount outstanding of 0' ); + is( $line2->amountoutstanding+0, 0, 'Second fee has amount outstanding of 0' ); + + my $ret = $account_payment->void(); + + is( ref($ret), 'Koha::Account::Line', 'Void returns the account line' ); + is( $account->balance(), 30, "Account balance is again 30" ); + + $account_payment->_result->discard_changes(); + $line1->_result->discard_changes(); + $line2->_result->discard_changes(); + + is( $account_payment->accounttype, 'Pay', 'Voided payment accounttype is still Pay' ); + is( $account_payment->status, 'VOID', 'Voided payment status is VOID' ); + is( $account_payment->amount+0, 0, 'Voided payment amount is 0' ); + is( $account_payment->amountoutstanding+0, 0, 'Voided payment amount outstanding is 0' ); + + is( $line1->amountoutstanding+0, 10, 'First fee again has amount outstanding of 10' ); + is( $line2->amountoutstanding+0, 20, 'Second fee again has amount outstanding of 20' ); + + # Accountlines that are not credits should be un-voidable + my $line1_pre = $line1->unblessed(); + $ret = $line1->void(); + $line1->_result->discard_changes(); + my $line1_post = $line1->unblessed(); + is( $ret, undef, 'Attempted void on non-credit returns undef' ); + is_deeply( $line1_pre, $line1_post, 'Non-credit account line cannot be voided' ) +}; + 1;