From 9f15737f4d923b1edfaf84d556d2b8027dbb4af4 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Fri, 28 May 2021 12:02:09 +0000 Subject: [PATCH] Bug 28482: [19.11.x] Unit test Signed-off-by: Martin Renvoize Signed-off-by: Katrin Fischer Fix test rebase --- t/db_dependent/Koha/Account/Lines.t | 59 ++++++++++++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Koha/Account/Lines.t b/t/db_dependent/Koha/Account/Lines.t index d63de70938..78526109d9 100755 --- a/t/db_dependent/Koha/Account/Lines.t +++ b/t/db_dependent/Koha/Account/Lines.t @@ -26,6 +26,7 @@ use C4::Circulation qw/AddIssue AddReturn/; use Koha::Account; use Koha::Account::Lines; use Koha::Account::Offsets; +use Koha::DateUtils; use Koha::Items; use t::lib::Mocks; @@ -209,7 +210,7 @@ subtest 'is_credit() and is_debit() tests' => sub { subtest 'apply() tests' => sub { - plan tests => 24; + plan tests => 25; $schema->storage->txn_begin; @@ -319,6 +320,62 @@ subtest 'apply() tests' => sub { is( $debit_2->discard_changes->amountoutstanding * 1, 0, 'Debit cancelled' ); is( $debit_3->discard_changes->amountoutstanding * 1, 90, 'Outstanding amount correctly calculated' ); is( $credit_2->discard_changes->amountoutstanding * 1, 0, 'No remaining credit' ); + + my $loser = $builder->build_object( { class => 'Koha::Patrons' } ); + my $loser_account = $loser->account; + + + my $now = dt_from_string(); + my $seven_weeks = DateTime::Duration->new(weeks => 7); + my $five_weeks = DateTime::Duration->new(weeks => 5); + my $seven_weeks_ago = $now - $seven_weeks; + my $five_weeks_ago = $now - $five_weeks; + + my $lost_item = $builder->build_sample_item(); + my $lost_checkout = Koha::Checkout->new( + { + borrowernumber => $loser->id, + itemnumber => $lost_item->id, + date_due => $five_weeks_ago, + branchcode => $loser->branchcode, + issuedate => $seven_weeks_ago + } + )->store(); + + $lost_item->itemlost(1)->store; + my $processing_fee = Koha::Account::Line->new( + { + issue_id => $lost_checkout->id, + borrowernumber => $loser->id, + itemnumber => $lost_item->id, + branchcode => $loser->branchcode, + date => \'NOW()', + debit_type_code => 'PROCESSING', + status => undef, + interface => 'intranet', + amount => '15', + amountoutstanding => '15', + } + )->store(); + my $lost_fee = Koha::Account::Line->new( + { + issue_id => $lost_checkout->id, + borrowernumber => $loser->id, + itemnumber => $lost_item->id, + branchcode => $loser->branchcode, + date => \'NOW()', + debit_type_code => 'LOST', + status => undef, + interface => 'intranet', + amount => '12.63', + amountoutstanding => '12.63', + } + )->store(); + my $pay_lost = $loser_account->add_credit({ amount => 27.630000, user_id => $loser->id, interface => 'intranet' }); + my $pay_lines = [ $processing_fee, $lost_fee ]; + $pay_lost->apply( { debits => $pay_lines, offset_type => 'Credit applied' } ); + + is( $loser->checkouts->next, undef, "Item has been returned"); $schema->storage->txn_rollback; }; -- 2.20.1