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

(-)a/t/db_dependent/Circulation/_CalculateAndUpdateFine.t (-1 / +137 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
# Copyright University of Helsinki 2020
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
use Modern::Perl;
21
22
use Test::More tests => 1;
23
24
use Koha::Database;
25
use Koha::DateUtils qw( dt_from_string );
26
use Koha::CirculationRules;
27
28
use C4::Circulation;
29
30
use t::lib::TestBuilder;
31
use t::lib::Mocks;
32
33
34
my $schema = Koha::Database->schema;
35
$schema->storage->txn_begin;
36
37
my $builder = t::lib::TestBuilder->new();
38
39
my $branch = $builder->build({
40
    source => 'Branch',
41
});
42
43
my $branch2 = $builder->build({
44
     source => 'Branch',
45
});
46
47
my $category = $builder->build({
48
    source => 'Category',
49
});
50
51
my $patron = $builder->build({
52
    source => 'Borrower',
53
    value => {
54
        categorycode => $category->{categorycode},
55
        branchcode => $branch->{branchcode},
56
    },
57
});
58
59
my $biblio = $builder->build_sample_biblio({ branchcode => $branch->{branchcode} });
60
61
my $item = $builder->build_sample_item({
62
    biblionumber => $biblio->biblionumber,
63
    homebranch => $branch->{branchcode},
64
    holdingbranch => $branch2->{branchcode},
65
});
66
67
Koha::CirculationRules->search()->delete();
68
69
subtest 'HomeOrHoldingBranch is used' => sub {
70
    plan tests => 2;
71
72
    # Homebranch rule with fine
73
    Koha::CirculationRules->set_rules(
74
        {
75
            itemtype     => undef,
76
            categorycode => undef,
77
            branchcode   => $branch->{branchcode},
78
            rules        => {
79
                fine                          => '1.00',
80
                lengthunit                    => 'days',
81
                finedays                      => 0,
82
                chargeperiod                  => 1,
83
            }
84
        }
85
    );
86
87
    # Holdingbranch rule without fine
88
    Koha::CirculationRules->set_rules(
89
        {
90
            itemtype     => undef,
91
            categorycode => undef,
92
            branchcode   => $branch2->{branchcode},
93
            rules        => {
94
                fine                          => '0.00',
95
                lengthunit                    => 'days',
96
                finedays                      => 0,
97
                chargeperiod                  => 1,
98
            }
99
        }
100
    );
101
102
    t::lib::Mocks::mock_preference('finesMode', 'production');
103
    t::lib::Mocks::mock_preference('CircControl', 'ItemHomeLibrary');
104
    t::lib::Mocks::mock_preference('HomeOrHoldingBranch', 'holdingbranch');
105
    t::lib::Mocks::mock_userenv({ branchcode => $branch->{branchcode} });
106
107
    my $issue = C4::Circulation::AddIssue( $patron, $item->barcode, dt_from_string() );
108
109
    # Returning loan 1 day after due date
110
    my $return_date = dt_from_string()->add( days => 1 )->set( hour => 23, minute => 59, second => 0 );
111
    C4::Circulation::_CalculateAndUpdateFine(
112
       {
113
            borrower => $patron,
114
            issue => $issue,
115
            item => $item->unblessed,
116
            return_date => $return_date,
117
        }
118
    );
119
120
    my $fines = Koha::Account::Lines->search({ borrowernumber => $patron->{borrowernumber} });
121
    is($fines->total_outstanding, 0, "Fine is not accrued for holdingbranch");
122
123
    t::lib::Mocks::mock_preference('HomeOrHoldingBranch', 'homebranch');
124
    C4::Circulation::_CalculateAndUpdateFine(
125
        {
126
            borrower => $patron,
127
            issue => $issue,
128
            item => $item->unblessed,
129
            return_date => $return_date,
130
        }
131
    );
132
    $fines = Koha::Account::Lines->search({ borrowernumber => $patron->{borrowernumber} });
133
    is($fines->total_outstanding, 1, "Fine is accrued for homebranch");
134
135
};
136
137
$schema->storage->txn_rollback;

Return to bug 27259