View | Details | Raw Unified | Return to bug 31895
Collapse All | Expand All

(-)a/Koha/Account.pm (+12 lines)
Lines 35-40 use Koha::Account::Offsets; Link Here
35
use Koha::Account::DebitTypes;
35
use Koha::Account::DebitTypes;
36
use Koha::Exceptions;
36
use Koha::Exceptions;
37
use Koha::Exceptions::Account;
37
use Koha::Exceptions::Account;
38
use Koha::Plugins;
38
39
39
=head1 NAME
40
=head1 NAME
40
41
Lines 255-260 sub add_credit { Link Here
255
                    }
256
                    }
256
                ) if grep { $credit_type eq $_ } ( 'PAYMENT', 'WRITEOFF' );
257
                ) if grep { $credit_type eq $_ } ( 'PAYMENT', 'WRITEOFF' );
257
258
259
                Koha::Plugins->call(
260
                    'after_account_action',
261
                    {
262
                        action  => "add_credit",
263
                        payload => {
264
                            type => lc($credit_type),
265
                            line => $line->get_from_storage 
266
                        }
267
                    }
268
                );
269
258
                if ( C4::Context->preference("FinesLog") ) {
270
                if ( C4::Context->preference("FinesLog") ) {
259
                    logaction(
271
                    logaction(
260
                        "FINES", 'CREATE',
272
                        "FINES", 'CREATE',
(-)a/t/db_dependent/Koha/Plugins/Account_hooks.t (+74 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it under the
6
# terms of the GNU General Public License as published by the Free Software
7
# Foundation; either version 3 of the License, or (at your option) any later
8
# version.
9
#
10
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License along
15
# with Koha; if not, see <http://www.gnu.org/licenses>.
16
17
use Modern::Perl;
18
19
use Test::More tests => 4;
20
use Test::MockModule;
21
use Test::Warn;
22
23
use File::Basename;
24
25
use Koha::Account qw( add_credit );
26
27
use t::lib::Mocks;
28
use t::lib::TestBuilder;
29
30
BEGIN {
31
    # Mock pluginsdir before loading Plugins module
32
    my $path = dirname(__FILE__) . '/../../../lib/plugins';
33
    t::lib::Mocks::mock_config( 'pluginsdir', $path );
34
35
    use_ok('Koha::Plugins');
36
    use_ok('Koha::Plugins::Handler');
37
    use_ok('Koha::Plugin::Test');
38
}
39
40
my $schema  = Koha::Database->new->schema;
41
my $builder = t::lib::TestBuilder->new;
42
43
t::lib::Mocks::mock_config( 'enable_plugins', 1 );
44
45
subtest 'Koha::Account tests' => sub {
46
47
    plan tests => 2;
48
49
    $schema->storage->txn_begin;
50
51
    my $plugins = Koha::Plugins->new;
52
    $plugins->InstallPlugins;
53
54
    my $plugin = Koha::Plugin::Test->new->enable;
55
56
    my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
57
58
    my $account = $patron->account;
59
    warning_like {
60
        $account->add_credit({ amount => 20, interface => 'commandline', type => 'WRITEOFF'});
61
    }
62
    qr/after_account_action called with action: add_credit, type: writeoff, ref: Koha::Account::Line/,
63
      '->add_credit calls the after_account_action hook with type writeoff';
64
65
66
    warning_like {
67
        $account->add_credit({ amount => 10, interface => 'commandline', type => 'PAYMENT'});
68
    }
69
    qr/after_account_action called with action: add_credit, type: payment, ref: Koha::Account::Line/,
70
      '->add_credit calls the after_account_action hook with type payment';
71
72
    $schema->storage->txn_rollback;
73
    Koha::Plugins::Methods->delete;
74
};
(-)a/t/lib/plugins/Koha/Plugin/Test.pm (-1 / +11 lines)
Lines 348-353 sub background_tasks { Link Here
348
    };
348
    };
349
}
349
}
350
350
351
sub after_account_action {
352
    my ( $self, $params ) = @_;
353
354
    my $action = $params->{action};
355
    my $line   = $params->{payload}->{line};
356
    my $type   = $params->{payload}->{type};
357
358
    Koha::Exception->throw(
359
        "after_account_action called with action: $action, type: $type, ref: " . ref($line) );
360
}
361
351
sub _private_sub {
362
sub _private_sub {
352
    return "";
363
    return "";
353
}
364
}
354
- 

Return to bug 31895