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

(-)a/C4/Overdues.pm (+16 lines)
Lines 222-227 sub CalcFine { Link Here
222
    # Skip calculations if item is not overdue
222
    # Skip calculations if item is not overdue
223
    return ( 0, 0, 0 ) unless ( DateTime->compare( $due_dt, $end_date ) == -1 );
223
    return ( 0, 0, 0 ) unless ( DateTime->compare( $due_dt, $end_date ) == -1 );
224
224
225
    # Call the plugin hook overwrite_calc_fine of all plugins and return
226
    # the first defined fine.
227
    my @fines = Koha::Plugins->call(
228
        'overwrite_calc_fine',
229
        {
230
            item         => $item,
231
            categorycode => $bortype,
232
            branchcode   => $branchcode,
233
            due_date     => $due_dt,
234
            end_date     => $end_date,
235
        }
236
    );
237
    foreach my $fine (@fines) {
238
        return @$fine if ( defined $fine );
239
    }
240
225
    my $start_date = $due_dt->clone();
241
    my $start_date = $due_dt->clone();
226
242
227
    # get issuingrules (fines part will be used)
243
    # get issuingrules (fines part will be used)
(-)a/t/db_dependent/Koha/Plugins/Overdues.t (+111 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::NoWarnings;
20
use Test::More tests => 6;
21
22
use C4::Overdues qw(CalcFine);
23
24
use File::Basename;
25
26
use t::lib::Mocks;
27
use t::lib::TestBuilder;
28
29
BEGIN {
30
    # Mock pluginsdir before loading Plugins module
31
    my $path = dirname(__FILE__) . '/../../../lib/plugins';
32
    t::lib::Mocks::mock_config( 'pluginsdir', $path );
33
34
    use_ok('C4::Overdues');
35
    use_ok('Koha::Plugins');
36
    use_ok('Koha::Plugins::Handler');
37
    use_ok('Koha::Plugin::Test');
38
}
39
40
t::lib::Mocks::mock_config( 'enable_plugins', 1 );
41
42
my $builder = t::lib::TestBuilder->new;
43
44
my $branch = $builder->build(
45
    {
46
        source => 'Branch',
47
    }
48
);
49
50
my $category = $builder->build(
51
    {
52
        source => 'Category',
53
    }
54
);
55
56
my $item = $builder->build_sample_item;
57
58
subtest 'overwrite_calc_fine hook tests' => sub {
59
    plan tests => 6;
60
61
    my $schema = Koha::Database->new->schema;
62
    $schema->storage->txn_begin;
63
64
    my $plugins = Koha::Plugins->new;
65
    $plugins->InstallPlugins;
66
    Koha::Plugin::Test->new->enable;
67
68
    Koha::CirculationRules->set_rules(
69
        {
70
            branchcode   => undef,
71
            categorycode => undef,
72
            itemtype     => undef,
73
            rules        => {
74
                fine                          => '2.00',
75
                lengthunit                    => 'days',
76
                finedays                      => 0,
77
                firstremind                   => 0,
78
                chargeperiod                  => 1,
79
                overduefinescap               => '0',
80
                cap_fine_to_replacement_price => 0,
81
            }
82
        },
83
    );
84
85
    my $due_date = DateTime->new(
86
        year  => 2000,
87
        month => 1,
88
        day   => 1,
89
    );
90
    my $end_date = DateTime->new(
91
        year  => 2000,
92
        month => 1,
93
        day   => 30,
94
    );
95
96
    my ( $amount, $units, $chargable_units ) = CalcFine( $item->unblessed, undef, undef, $due_date, $end_date );
97
98
    is( $amount,          87, 'Amount is calculated correctly with custom function' );
99
    is( $units,           29, 'Units are calculated correctly with custom function' );
100
    is( $chargable_units, 27, 'Chargable units are calculated correctly with custom function' );
101
102
    ( $amount, $units, $chargable_units ) =
103
        CalcFine( $item->unblessed, $category->{categorycode}, $branch->{branchcode}, $due_date, $end_date );
104
105
    is( $amount,          58, 'Amount is calculated correctly with original function' );
106
    is( $units,           29, 'Units are calculated correctly with original function' );
107
    is( $chargable_units, 29, 'Chargable units are calculated correctly with original function' );
108
109
    Koha::Plugins->RemovePlugins;
110
    $schema->storage->txn_rollback;
111
};
(-)a/t/lib/plugins/Koha/Plugin/Test.pm (-1 / +10 lines)
Lines 448-453 sub auth_client_get_user { Link Here
448
    return;
448
    return;
449
}
449
}
450
450
451
sub overwrite_calc_fine {
452
    my ( $self, $params ) = @_;
453
454
    my $days = $params->{end_date}->delta_days( $params->{due_date} )->delta_days;
455
456
    return $params->{categorycode} && $params->{branchcode}
457
        ? undef
458
        : [ 3 * $days, $days, $days - 2 ];
459
}
460
451
sub _private_sub {
461
sub _private_sub {
452
    return "";
462
    return "";
453
}
463
}
454
- 

Return to bug 39405