From 97ad392f59d3eca3f0fe70e3d7b0c759af642d36 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Fri, 22 Jun 2018 12:24:33 -0300 Subject: [PATCH] Bug 20980: (follow-up) Only use UpdateStats for 'payment' and 'writeoff' This patch makes Koha::Account::add_credit record statistics logs (through C4::Stats::UpdateStats) only for the 'payment' and 'writeoff' credit types. Both credit types are whitelisted in UpdateStats, so we keep the current behaviour. Another option would've been to add new account types to the white list, but with the account offsets it seems that using the statistics table for account changes won't be useful for too long, as offsets contain the same (and more) information. To test: - Apply the patch - Run: $ kshell k$ prove t/db_dependent/Koha/Account.t => SUCCESS: Tests pass! - Sign off :-D Signed-off-by: Josef Moravec Signed-off-by: Kyle M Hall --- Koha/Account.pm | 2 +- t/db_dependent/Koha/Account.t | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/Koha/Account.pm b/Koha/Account.pm index 04a8583524..e20fe140e0 100644 --- a/Koha/Account.pm +++ b/Koha/Account.pm @@ -347,7 +347,7 @@ sub add_credit { borrowernumber => $self->{patron_id}, accountno => $accountno, } - ); + ) if grep { $type eq $_ } ('payment', 'writeoff') ; if ( C4::Context->preference("FinesLog") ) { logaction( diff --git a/t/db_dependent/Koha/Account.t b/t/db_dependent/Koha/Account.t index 9684b65230..6f94833838 100755 --- a/t/db_dependent/Koha/Account.t +++ b/t/db_dependent/Koha/Account.t @@ -67,7 +67,7 @@ subtest 'outstanding_debits() tests' => sub { subtest 'add_credit() tests' => sub { - plan tests => 13; + plan tests => 15; $schema->storage->txn_begin; @@ -88,6 +88,7 @@ subtest 'add_credit() tests' => sub { description => 'Payment of 25', library_id => $patron->branchcode, note => 'not really important', + type => 'payment', user_id => $patron->id } ); @@ -125,5 +126,17 @@ subtest 'add_credit() tests' => sub { is( $offset_2->credit_id, $line_2->id, 'No debit_id is set for credits' ); is( $offset_2->debit_id, undef, 'No debit_id is set for credits' ); + my $line_3 = $account->add_credit( + { amount => 20, + description => 'Manual credit applied', + library_id => $patron->branchcode, + user_id => $patron->id, + type => 'forgiven' + } + ); + + is( $schema->resultset('ActionLog')->count(), 2, 'Log was added' ); + is( $schema->resultset('Statistic')->count(), 2, 'No action added to statistics, because of credit type' ); + $schema->storage->txn_rollback; }; -- 2.15.2 (Apple Git-101.1)