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

(-)a/C4/Circulation.pm (-14 / +14 lines)
Lines 426-432 sub TooMany { Link Here
426
                                    SELECT itemtype FROM circulation_rules
426
                                    SELECT itemtype FROM circulation_rules
427
                                    WHERE branchcode = ?
427
                                    WHERE branchcode = ?
428
                                    AND   (categorycode = ? OR categorycode = ?)
428
                                    AND   (categorycode = ? OR categorycode = ?)
429
                                    AND   itemtype <> '*'
429
                                    AND   itemtype IS NOT NULL
430
                                    AND   rule_name = 'maxissueqty'
430
                                    AND   rule_name = 'maxissueqty'
431
                                  ) ";
431
                                  ) ";
432
            } else {
432
            } else {
Lines 435-441 sub TooMany { Link Here
435
                                    SELECT itemtype FROM circulation_rules
435
                                    SELECT itemtype FROM circulation_rules
436
                                    WHERE branchcode = ?
436
                                    WHERE branchcode = ?
437
                                    AND   (categorycode = ? OR categorycode = ?)
437
                                    AND   (categorycode = ? OR categorycode = ?)
438
                                    AND   itemtype <> '*'
438
                                    AND   itemtype IS NOT NULL
439
                                    AND   rule_name = 'maxissueqty'
439
                                    AND   rule_name = 'maxissueqty'
440
                                  ) ";
440
                                  ) ";
441
            }
441
            }
Lines 1547-1584 sub GetLoanLength { Link Here
1547
        },
1547
        },
1548
        {
1548
        {
1549
            categorycode => $categorycode,
1549
            categorycode => $categorycode,
1550
            itemtype     => '*',
1550
            itemtype     => undef,
1551
            branchcode   => $branchcode,
1551
            branchcode   => $branchcode,
1552
        },
1552
        },
1553
        {
1553
        {
1554
            categorycode => '*',
1554
            categorycode => undef,
1555
            itemtype     => $itemtype,
1555
            itemtype     => $itemtype,
1556
            branchcode   => $branchcode,
1556
            branchcode   => $branchcode,
1557
        },
1557
        },
1558
        {
1558
        {
1559
            categorycode => '*',
1559
            categorycode => undef,
1560
            itemtype     => '*',
1560
            itemtype     => undef,
1561
            branchcode   => $branchcode,
1561
            branchcode   => $branchcode,
1562
        },
1562
        },
1563
        {
1563
        {
1564
            categorycode => $categorycode,
1564
            categorycode => $categorycode,
1565
            itemtype     => $itemtype,
1565
            itemtype     => $itemtype,
1566
            branchcode   => '*',
1566
            branchcode   => undef,
1567
        },
1567
        },
1568
        {
1568
        {
1569
            categorycode => $categorycode,
1569
            categorycode => $categorycode,
1570
            itemtype     => '*',
1570
            itemtype     => undef,
1571
            branchcode   => '*',
1571
            branchcode   => undef,
1572
        },
1572
        },
1573
        {
1573
        {
1574
            categorycode => '*',
1574
            categorycode => undef,
1575
            itemtype     => $itemtype,
1575
            itemtype     => $itemtype,
1576
            branchcode   => '*',
1576
            branchcode   => undef,
1577
        },
1577
        },
1578
        {
1578
        {
1579
            categorycode => '*',
1579
            categorycode => undef,
1580
            itemtype     => '*',
1580
            itemtype     => undef,
1581
            branchcode   => '*',
1581
            branchcode   => undef,
1582
        },
1582
        },
1583
    );
1583
    );
1584
1584
(-)a/C4/Reserves.pm (-5 / +5 lines)
Lines 367-373 sub CanItemBeReserved { Link Here
367
        $holds_per_day    = $rights->{holds_per_day};
367
        $holds_per_day    = $rights->{holds_per_day};
368
    }
368
    }
369
    else {
369
    else {
370
        $ruleitemtype = '*';
370
        $ruleitemtype = undef;
371
    }
371
    }
372
372
373
    my $holds = Koha::Holds->search(
373
    my $holds = Koha::Holds->search(
Lines 403-417 sub CanItemBeReserved { Link Here
403
      C4::Context->preference('item-level_itypes')
403
      C4::Context->preference('item-level_itypes')
404
      ? " AND COALESCE( items.itype, biblioitems.itemtype ) = ?"
404
      ? " AND COALESCE( items.itype, biblioitems.itemtype ) = ?"
405
      : " AND biblioitems.itemtype = ?"
405
      : " AND biblioitems.itemtype = ?"
406
      if ( $ruleitemtype ne "*" );
406
      if defined $ruleitemtype;
407
407
408
    my $sthcount = $dbh->prepare($querycount);
408
    my $sthcount = $dbh->prepare($querycount);
409
409
410
    if ( $ruleitemtype eq "*" ) {
410
    if ( defined $ruleitemtype ) {
411
        $sthcount->execute( $borrowernumber, $branchcode );
411
        $sthcount->execute( $borrowernumber, $branchcode, $ruleitemtype );
412
    }
412
    }
413
    else {
413
    else {
414
        $sthcount->execute( $borrowernumber, $branchcode, $ruleitemtype );
414
        $sthcount->execute( $borrowernumber, $branchcode );
415
    }
415
    }
416
416
417
    my $reservecount = "0";
417
    my $reservecount = "0";
(-)a/Koha/CirculationRules.pm (-9 / +144 lines)
Lines 34-39 Koha::CirculationRules - Koha CirculationRule Object set class Link Here
34
34
35
=cut
35
=cut
36
36
37
=head3 rule_kinds
38
39
This structure describes the possible rules that may be set, and what scopes they can be set at.
40
41
Any attempt to set a rule with a nonsensical scope (for instance, setting the C<patron_maxissueqty> for a branchcode and itemtype), is an error.
42
43
=cut
44
45
our $RULE_KINDS = {
46
    refund => {
47
        scope => [ 'branchcode' ],
48
    },
49
50
    patron_maxissueqty => {
51
        scope => [ 'branchcode', 'categorycode' ],
52
    },
53
    patron_maxonsiteissueqty => {
54
        scope => [ 'branchcode', 'categorycode' ],
55
    },
56
    max_holds => {
57
        scope => [ 'branchcode', 'categorycode' ],
58
    },
59
60
    holdallowed => {
61
        scope => [ 'branchcode', 'itemtype' ],
62
    },
63
    hold_fulfillment_policy => {
64
        scope => [ 'branchcode', 'itemtype' ],
65
    },
66
    returnbranch => {
67
        scope => [ 'branchcode', 'itemtype' ],
68
    },
69
70
    article_requests => {
71
        scope => [ 'branchcode', 'categorycode', 'itemtype' ],
72
    },
73
    auto_renew => {
74
        scope => [ 'branchcode', 'categorycode', 'itemtype' ],
75
    },
76
    cap_fine_to_replacement_price => {
77
        scope => [ 'branchcode', 'categorycode', 'itemtype' ],
78
    },
79
    chargeperiod => {
80
        scope => [ 'branchcode', 'categorycode', 'itemtype' ],
81
    },
82
    chargeperiod_charge_at => {
83
        scope => [ 'branchcode', 'categorycode', 'itemtype' ],
84
    },
85
    fine => {
86
        scope => [ 'branchcode', 'categorycode', 'itemtype' ],
87
    },
88
    finedays => {
89
        scope => [ 'branchcode', 'categorycode', 'itemtype' ],
90
    },
91
    firstremind => {
92
        scope => [ 'branchcode', 'categorycode', 'itemtype' ],
93
    },
94
    hardduedate => {
95
        scope => [ 'branchcode', 'categorycode', 'itemtype' ],
96
    },
97
    hardduedatecompare => {
98
        scope => [ 'branchcode', 'categorycode', 'itemtype' ],
99
    },
100
    holds_per_record => {
101
        scope => [ 'branchcode', 'categorycode', 'itemtype' ],
102
    },
103
    issuelength => {
104
        scope => [ 'branchcode', 'categorycode', 'itemtype' ],
105
    },
106
    lengthunit => {
107
        scope => [ 'branchcode', 'categorycode', 'itemtype' ],
108
    },
109
    maxissueqty => {
110
        scope => [ 'branchcode', 'categorycode', 'itemtype' ],
111
    },
112
    maxonsiteissueqty => {
113
        scope => [ 'branchcode', 'categorycode', 'itemtype' ],
114
    },
115
    maxsuspensiondays => {
116
        scope => [ 'branchcode', 'categorycode', 'itemtype' ],
117
    },
118
    no_auto_renewal_after => {
119
        scope => [ 'branchcode', 'categorycode', 'itemtype' ],
120
    },
121
    no_auto_renewal_after_hard_limit => {
122
        scope => [ 'branchcode', 'categorycode', 'itemtype' ],
123
    },
124
    norenewalbefore => {
125
        scope => [ 'branchcode', 'categorycode', 'itemtype' ],
126
    },
127
    onshelfholds => {
128
        scope => [ 'branchcode', 'categorycode', 'itemtype' ],
129
    },
130
    opacitemholds => {
131
        scope => [ 'branchcode', 'categorycode', 'itemtype' ],
132
    },
133
    overduefinescap => {
134
        scope => [ 'branchcode', 'categorycode', 'itemtype' ],
135
    },
136
    renewalperiod => {
137
        scope => [ 'branchcode', 'categorycode', 'itemtype' ],
138
    },
139
    renewalsallowed => {
140
        scope => [ 'branchcode', 'categorycode', 'itemtype' ],
141
    },
142
    rentaldiscount => {
143
        scope => [ 'branchcode', 'categorycode', 'itemtype' ],
144
    },
145
    reservesallowed => {
146
        scope => [ 'branchcode', 'categorycode', 'itemtype' ],
147
    },
148
    # Not included (deprecated?):
149
    #   * accountsent
150
    #   * chargename
151
    #   * reservecharge
152
    #   * restrictedtype
153
};
154
155
sub rule_kinds {
156
    return $RULE_KINDS;
157
}
158
37
=head3 get_effective_rule
159
=head3 get_effective_rule
38
160
39
=cut
161
=cut
Lines 41-49 Koha::CirculationRules - Koha CirculationRule Object set class Link Here
41
sub get_effective_rule {
163
sub get_effective_rule {
42
    my ( $self, $params ) = @_;
164
    my ( $self, $params ) = @_;
43
165
44
    $params->{categorycode} = '*' if exists($params->{categorycode}) && !defined($params->{categorycode});
166
    $params->{categorycode} //= undef;
45
    $params->{branchcode}   = '*' if exists($params->{branchcode})   && !defined($params->{branchcode});
167
    $params->{branchcode}   //= undef;
46
    $params->{itemtype}     = '*' if exists($params->{itemtype})     && !defined($params->{itemtype});
168
    $params->{itemtype}     //= undef;
47
169
48
    my $rule_name    = $params->{rule_name};
170
    my $rule_name    = $params->{rule_name};
49
    my $categorycode = $params->{categorycode};
171
    my $categorycode = $params->{categorycode};
Lines 119-124 sub set_rule { Link Here
119
        Koha::Exceptions::MissingParameter->throw(
241
        Koha::Exceptions::MissingParameter->throw(
120
            "Required parameter 'branchcode' missing")
242
            "Required parameter 'branchcode' missing")
121
          unless exists $params->{$mandatory_parameter};
243
          unless exists $params->{$mandatory_parameter};
244
245
    my $kind_info = $RULE_KINDS->{ $params->{rule_name} };
246
    croak "set_rule given unknown rule '$params->{rule_name}'!"
247
        unless defined $kind_info;
248
249
    # Enforce scope; a rule should be set for its defined scope, no more, no less.
250
    foreach my $scope_level ( qw( branchcode categorycode itemtype ) ) {
251
        if ( grep /$scope_level/, @{ $kind_info->{scope} } ) {
252
            croak "set_rule needs '$scope_level' to set '$params->{rule_name}'!"
253
                unless exists $params->{$scope_level};
254
        } else {
255
            croak "set_rule cannot set '$params->{rule_name}' for a '$scope_level'!"
256
                if exists $params->{$scope_level};
257
        }
122
    }
258
    }
123
259
124
    my $branchcode   = $params->{branchcode};
260
    my $branchcode   = $params->{branchcode};
Lines 173-190 sub set_rule { Link Here
173
sub set_rules {
309
sub set_rules {
174
    my ( $self, $params ) = @_;
310
    my ( $self, $params ) = @_;
175
311
176
    my $branchcode   = $params->{branchcode};
312
    my %set_params;
177
    my $categorycode = $params->{categorycode};
313
    $set_params{branchcode} = $params->{branchcode} if exists $params->{branchcode};
178
    my $itemtype     = $params->{itemtype};
314
    $set_params{categorycode} = $params->{categorycode} if exists $params->{categorycode};
315
    $set_params{itemtype} = $params->{itemtype} if exists $params->{itemtype};
179
    my $rules        = $params->{rules};
316
    my $rules        = $params->{rules};
180
317
181
    my $rule_objects = [];
318
    my $rule_objects = [];
182
    while ( my ( $rule_name, $rule_value ) = each %$rules ) {
319
    while ( my ( $rule_name, $rule_value ) = each %$rules ) {
183
        my $rule_object = Koha::CirculationRules->set_rule(
320
        my $rule_object = Koha::CirculationRules->set_rule(
184
            {
321
            {
185
                branchcode   => $branchcode,
322
                %set_params,
186
                categorycode => $categorycode,
187
                itemtype     => $itemtype,
188
                rule_name    => $rule_name,
323
                rule_name    => $rule_name,
189
                rule_value   => $rule_value,
324
                rule_value   => $rule_value,
190
            }
325
            }
(-)a/Koha/REST/V1/CirculationRules.pm (+32 lines)
Line 0 Link Here
1
package Koha::REST::V1::CirculationRules;
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, write to the Free Software Foundation, Inc.,
16
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
18
use Modern::Perl;
19
20
use Mojo::Base 'Mojolicious::Controller';
21
22
use Koha::CirculationRules;
23
24
use Try::Tiny;
25
26
sub get_kinds {
27
    my ( $c, $args, $cb ) = @_;
28
29
    return $c->$cb( Koha::CirculationRules->rule_kinds, 200 );
30
}
31
32
1;
(-)a/admin/smart-rules.pl (-75 / +79 lines)
Lines 81-89 if ($op eq 'delete') { Link Here
81
81
82
    Koha::CirculationRules->set_rules(
82
    Koha::CirculationRules->set_rules(
83
        {
83
        {
84
            categorycode => $categorycode,
84
            categorycode => $categorycode eq '*' ? undef : $categorycode,
85
            branchcode   => $branch,
85
            branchcode   => $branch eq '*' ? undef : $branch,
86
            itemtype     => $itemtype,
86
            itemtype     => $itemtype eq '*' ? undef : $itemtype,
87
            rules        => {
87
            rules        => {
88
                restrictedtype                   => undef,
88
                restrictedtype                   => undef,
89
                rentaldiscount                   => undef,
89
                rentaldiscount                   => undef,
Lines 119-162 elsif ($op eq 'delete-branch-cat') { Link Here
119
    my $categorycode  = $input->param('categorycode');
119
    my $categorycode  = $input->param('categorycode');
120
    if ($branch eq "*") {
120
    if ($branch eq "*") {
121
        if ($categorycode eq "*") {
121
        if ($categorycode eq "*") {
122
             Koha::CirculationRules->set_rules(
122
            Koha::CirculationRules->set_rules(
123
                 {
123
                {
124
                     categorycode => undef,
124
                    branchcode   => undef,
125
                     branchcode   => undef,
125
                    categorycode => undef,
126
                     itemtype     => undef,
126
                    rules        => {
127
                     rules        => {
127
                        max_holds                      => undef,
128
                         patron_maxissueqty             => undef,
128
                        patron_maxissueqty             => undef,
129
                         patron_maxonsiteissueqty       => undef,
129
                        patron_maxonsiteissueqty       => undef,
130
                         holdallowed             => undef,
130
                    }
131
                         hold_fulfillment_policy => undef,
131
                }
132
                         returnbranch            => undef,
132
            );
133
                         max_holds               => undef,
133
            Koha::CirculationRules->set_rules(
134
                     }
134
                {
135
                 }
135
                    branchcode   => undef,
136
             );
136
                    itemtype     => undef,
137
         } else {
137
                    rules        => {
138
             Koha::CirculationRules->set_rules(
138
                        holdallowed             => undef,
139
                 {
139
                        hold_fulfillment_policy => undef,
140
                     categorycode => $categorycode,
140
                        returnbranch            => undef,
141
                     branchcode   => undef,
141
                    }
142
                     itemtype     => undef,
142
                }
143
                     rules        => {
143
            );
144
                         max_holds         => undef,
144
        } else {
145
                         patron_maxissueqty       => undef,
145
            Koha::CirculationRules->set_rules(
146
                         patron_maxonsiteissueqty => undef,
146
                {
147
                     }
147
                    categorycode => $categorycode,
148
                 }
148
                    branchcode   => undef,
149
             );
149
                    rules        => {
150
                        max_holds                => undef,
151
                        patron_maxissueqty       => undef,
152
                        patron_maxonsiteissueqty => undef,
153
                    }
154
                }
155
            );
150
        }
156
        }
151
    } elsif ($categorycode eq "*") {
157
    } elsif ($categorycode eq "*") {
152
        Koha::CirculationRules->set_rules(
158
        Koha::CirculationRules->set_rules(
153
            {
159
            {
160
                branchcode   => $branch,
154
                categorycode => undef,
161
                categorycode => undef,
162
                rules        => {
163
                    patron_maxissueqty       => undef,
164
                    patron_maxonsiteissueqty => undef,
165
                }
166
            }
167
        );
168
        Koha::CirculationRules->set_rules(
169
            {
155
                branchcode   => $branch,
170
                branchcode   => $branch,
156
                itemtype     => undef,
157
                rules        => {
171
                rules        => {
158
                    patron_maxissueqty             => undef,
159
                    patron_maxonsiteissueqty       => undef,
160
                    holdallowed             => undef,
172
                    holdallowed             => undef,
161
                    hold_fulfillment_policy => undef,
173
                    hold_fulfillment_policy => undef,
162
                    returnbranch            => undef,
174
                    returnbranch            => undef,
Lines 169-175 elsif ($op eq 'delete-branch-cat') { Link Here
169
            {
181
            {
170
                categorycode => $categorycode,
182
                categorycode => $categorycode,
171
                branchcode   => $branch,
183
                branchcode   => $branch,
172
                itemtype     => undef,
173
                rules        => {
184
                rules        => {
174
                    max_holds         => undef,
185
                    max_holds         => undef,
175
                    patron_maxissueqty       => undef,
186
                    patron_maxissueqty       => undef,
Lines 185-196 elsif ($op eq 'delete-branch-item') { Link Here
185
        if ($itemtype eq "*") {
196
        if ($itemtype eq "*") {
186
            Koha::CirculationRules->set_rules(
197
            Koha::CirculationRules->set_rules(
187
                {
198
                {
188
                    categorycode => undef,
189
                    branchcode   => undef,
199
                    branchcode   => undef,
190
                    itemtype     => undef,
200
                    itemtype     => undef,
191
                    rules        => {
201
                    rules        => {
192
                        patron_maxissueqty             => undef,
193
                        patron_maxonsiteissueqty       => undef,
194
                        holdallowed             => undef,
202
                        holdallowed             => undef,
195
                        hold_fulfillment_policy => undef,
203
                        hold_fulfillment_policy => undef,
196
                        returnbranch            => undef,
204
                        returnbranch            => undef,
Lines 200-206 elsif ($op eq 'delete-branch-item') { Link Here
200
        } else {
208
        } else {
201
            Koha::CirculationRules->set_rules(
209
            Koha::CirculationRules->set_rules(
202
                {
210
                {
203
                    categorycode => undef,
204
                    branchcode   => undef,
211
                    branchcode   => undef,
205
                    itemtype     => $itemtype,
212
                    itemtype     => $itemtype,
206
                    rules        => {
213
                    rules        => {
Lines 214-225 elsif ($op eq 'delete-branch-item') { Link Here
214
    } elsif ($itemtype eq "*") {
221
    } elsif ($itemtype eq "*") {
215
        Koha::CirculationRules->set_rules(
222
        Koha::CirculationRules->set_rules(
216
            {
223
            {
217
                categorycode => undef,
218
                branchcode   => $branch,
224
                branchcode   => $branch,
219
                itemtype     => undef,
225
                itemtype     => undef,
220
                rules        => {
226
                rules        => {
221
                    maxissueqty             => undef,
222
                    maxonsiteissueqty       => undef,
223
                    holdallowed             => undef,
227
                    holdallowed             => undef,
224
                    hold_fulfillment_policy => undef,
228
                    hold_fulfillment_policy => undef,
225
                    returnbranch            => undef,
229
                    returnbranch            => undef,
Lines 229-235 elsif ($op eq 'delete-branch-item') { Link Here
229
    } else {
233
    } else {
230
        Koha::CirculationRules->set_rules(
234
        Koha::CirculationRules->set_rules(
231
            {
235
            {
232
                categorycode => undef,
233
                branchcode   => $branch,
236
                branchcode   => $branch,
234
                itemtype     => $itemtype,
237
                itemtype     => $itemtype,
235
                rules        => {
238
                rules        => {
Lines 325-333 elsif ($op eq 'add') { Link Here
325
328
326
    Koha::CirculationRules->set_rules(
329
    Koha::CirculationRules->set_rules(
327
        {
330
        {
328
            categorycode => $bor,
331
            categorycode => $bor eq '*' ? undef : $bor,
329
            itemtype     => $itemtype,
332
            itemtype     => $itemtype eq '*' ? undef : $itemtype,
330
            branchcode   => $br,
333
            branchcode   => $br eq '*' ? undef : $br,
331
            rules        => $rules,
334
            rules        => $rules,
332
        }
335
        }
333
    );
336
    );
Lines 353-382 elsif ($op eq "set-branch-defaults") { Link Here
353
    if ($branch eq "*") {
356
    if ($branch eq "*") {
354
        Koha::CirculationRules->set_rules(
357
        Koha::CirculationRules->set_rules(
355
            {
358
            {
356
                categorycode => undef,
357
                itemtype     => undef,
359
                itemtype     => undef,
358
                branchcode   => undef,
360
                branchcode   => undef,
359
                rules        => {
361
                rules        => {
360
                    patron_maxissueqty       => $patron_maxissueqty,
362
                    holdallowed             => $holdallowed,
361
                    patron_maxonsiteissueqty => $patron_maxonsiteissueqty,
363
                    hold_fulfillment_policy => $hold_fulfillment_policy,
362
                    holdallowed              => $holdallowed,
364
                    returnbranch            => $returnbranch,
363
                    hold_fulfillment_policy  => $hold_fulfillment_policy,
364
                    returnbranch             => $returnbranch,
365
                }
365
                }
366
            }
366
            }
367
        );
367
        );
368
    } else {
369
        Koha::CirculationRules->set_rules(
368
        Koha::CirculationRules->set_rules(
370
            {
369
            {
371
                categorycode => undef,
370
                categorycode => undef,
371
                branchcode   => undef,
372
                rules        => {
373
                    patron_maxissueqty             => $patron_maxissueqty,
374
                    patron_maxonsiteissueqty       => $patron_maxonsiteissueqty,
375
                }
376
            }
377
        );
378
    } else {
379
        Koha::CirculationRules->set_rules(
380
            {
372
                itemtype     => undef,
381
                itemtype     => undef,
373
                branchcode   => $branch,
382
                branchcode   => $branch,
374
                rules        => {
383
                rules        => {
375
                    patron_maxissueqty       => $patron_maxissueqty,
384
                    holdallowed             => $holdallowed,
376
                    patron_maxonsiteissueqty => $patron_maxonsiteissueqty,
385
                    hold_fulfillment_policy => $hold_fulfillment_policy,
377
                    holdallowed              => $holdallowed,
386
                    returnbranch            => $returnbranch,
378
                    hold_fulfillment_policy  => $hold_fulfillment_policy,
387
                }
379
                    returnbranch             => $returnbranch,
388
            }
389
        );
390
        Koha::CirculationRules->set_rules(
391
            {
392
                categorycode => undef,
393
                branchcode   => $branch,
394
                rules        => {
395
                    patron_maxissueqty             => $patron_maxissueqty,
396
                    patron_maxonsiteissueqty       => $patron_maxonsiteissueqty,
380
                }
397
                }
381
            }
398
            }
382
        );
399
        );
Lines 408-414 elsif ($op eq "add-branch-cat") { Link Here
408
            Koha::CirculationRules->set_rules(
425
            Koha::CirculationRules->set_rules(
409
                {
426
                {
410
                    categorycode => undef,
427
                    categorycode => undef,
411
                    itemtype     => undef,
412
                    branchcode   => undef,
428
                    branchcode   => undef,
413
                    rules        => {
429
                    rules        => {
414
                        max_holds         => $max_holds,
430
                        max_holds         => $max_holds,
Lines 420-428 elsif ($op eq "add-branch-cat") { Link Here
420
        } else {
436
        } else {
421
            Koha::CirculationRules->set_rules(
437
            Koha::CirculationRules->set_rules(
422
                {
438
                {
423
                    branchcode   => undef,
424
                    categorycode => $categorycode,
439
                    categorycode => $categorycode,
425
                    itemtype     => undef,
440
                    branchcode   => undef,
426
                    rules        => {
441
                    rules        => {
427
                        max_holds         => $max_holds,
442
                        max_holds         => $max_holds,
428
                        patron_maxissueqty       => $patron_maxissueqty,
443
                        patron_maxissueqty       => $patron_maxissueqty,
Lines 435-441 elsif ($op eq "add-branch-cat") { Link Here
435
        Koha::CirculationRules->set_rules(
450
        Koha::CirculationRules->set_rules(
436
            {
451
            {
437
                categorycode => undef,
452
                categorycode => undef,
438
                itemtype     => undef,
439
                branchcode   => $branch,
453
                branchcode   => $branch,
440
                rules        => {
454
                rules        => {
441
                    max_holds         => $max_holds,
455
                    max_holds         => $max_holds,
Lines 448-454 elsif ($op eq "add-branch-cat") { Link Here
448
        Koha::CirculationRules->set_rules(
462
        Koha::CirculationRules->set_rules(
449
            {
463
            {
450
                categorycode => $categorycode,
464
                categorycode => $categorycode,
451
                itemtype     => undef,
452
                branchcode   => $branch,
465
                branchcode   => $branch,
453
                rules        => {
466
                rules        => {
454
                    max_holds         => $max_holds,
467
                    max_holds         => $max_holds,
Lines 472-478 elsif ($op eq "add-branch-item") { Link Here
472
        if ($itemtype eq "*") {
485
        if ($itemtype eq "*") {
473
            Koha::CirculationRules->set_rules(
486
            Koha::CirculationRules->set_rules(
474
                {
487
                {
475
                    categorycode => undef,
476
                    itemtype     => undef,
488
                    itemtype     => undef,
477
                    branchcode   => undef,
489
                    branchcode   => undef,
478
                    rules        => {
490
                    rules        => {
Lines 485-491 elsif ($op eq "add-branch-item") { Link Here
485
        } else {
497
        } else {
486
            Koha::CirculationRules->set_rules(
498
            Koha::CirculationRules->set_rules(
487
                {
499
                {
488
                    categorycode => undef,
489
                    itemtype     => $itemtype,
500
                    itemtype     => $itemtype,
490
                    branchcode   => undef,
501
                    branchcode   => undef,
491
                    rules        => {
502
                    rules        => {
Lines 499-505 elsif ($op eq "add-branch-item") { Link Here
499
    } elsif ($itemtype eq "*") {
510
    } elsif ($itemtype eq "*") {
500
            Koha::CirculationRules->set_rules(
511
            Koha::CirculationRules->set_rules(
501
                {
512
                {
502
                    categorycode => undef,
503
                    itemtype     => undef,
513
                    itemtype     => undef,
504
                    branchcode   => $branch,
514
                    branchcode   => $branch,
505
                    rules        => {
515
                    rules        => {
Lines 512-518 elsif ($op eq "add-branch-item") { Link Here
512
    } else {
522
    } else {
513
        Koha::CirculationRules->set_rules(
523
        Koha::CirculationRules->set_rules(
514
            {
524
            {
515
                categorycode => undef,
516
                itemtype     => $itemtype,
525
                itemtype     => $itemtype,
517
                branchcode   => $branch,
526
                branchcode   => $branch,
518
                rules        => {
527
                rules        => {
Lines 533-540 elsif ( $op eq 'mod-refund-lost-item-fee-rule' ) { Link Here
533
            # only do something for $refund eq '*' if branch-specific
542
            # only do something for $refund eq '*' if branch-specific
534
            Koha::CirculationRules->set_rules(
543
            Koha::CirculationRules->set_rules(
535
                {
544
                {
536
                    categorycode => undef,
537
                    itemtype     => undef,
538
                    branchcode   => $branch,
545
                    branchcode   => $branch,
539
                    rules        => {
546
                    rules        => {
540
                        refund => undef
547
                        refund => undef
Lines 545-553 elsif ( $op eq 'mod-refund-lost-item-fee-rule' ) { Link Here
545
    } else {
552
    } else {
546
        Koha::CirculationRules->set_rules(
553
        Koha::CirculationRules->set_rules(
547
            {
554
            {
548
                categorycode => undef,
555
                branchcode   => undef,
549
                itemtype     => undef,
550
                branchcode   => $branch,
551
                rules        => {
556
                rules        => {
552
                    refund => $refund
557
                    refund => $refund
553
                }
558
                }
Lines 556-563 elsif ( $op eq 'mod-refund-lost-item-fee-rule' ) { Link Here
556
    }
561
    }
557
}
562
}
558
563
559
my $refundLostItemFeeRule = Koha::RefundLostItemFeeRules->find({ branchcode => ($branch eq '*') ? undef:$branch });
564
my $refundLostItemFeeRule = Koha::RefundLostItemFeeRules->find({ branchcode => ($branch eq '*') ? undef : $branch });
560
561
$template->param(
565
$template->param(
562
    refundLostItemFeeRule => $refundLostItemFeeRule,
566
    refundLostItemFeeRule => $refundLostItemFeeRule,
563
    defaultRefundRule     => Koha::RefundLostItemFeeRules->_default_rule
567
    defaultRefundRule     => Koha::RefundLostItemFeeRules->_default_rule
Lines 572-578 $template->param(show_branch_cat_rule_form => 1); Link Here
572
$template->param(
576
$template->param(
573
    patron_categories => $patron_categories,
577
    patron_categories => $patron_categories,
574
    itemtypeloop      => $itemtypes,
578
    itemtypeloop      => $itemtypes,
575
    humanbranch       => ( $branch ne '*' ? $branch : '' ),
579
    humanbranch       => ( $branch ne '*' ? $branch : undef ),
576
    current_branch    => $branch,
580
    current_branch    => $branch,
577
);
581
);
578
output_html_with_http_headers $input, $cookie, $template->output;
582
output_html_with_http_headers $input, $cookie, $template->output;
(-)a/api/v1/swagger/definitions.json (+3 lines)
Lines 2-7 Link Here
2
  "account_line": {
2
  "account_line": {
3
    "$ref": "definitions/account_line.json"
3
    "$ref": "definitions/account_line.json"
4
  },
4
  },
5
  "circ-rule-kind": {
6
    "$ref": "definitions/circ-rule-kind.json"
7
  },
5
  "city": {
8
  "city": {
6
    "$ref": "definitions/city.json"
9
    "$ref": "definitions/city.json"
7
  },
10
  },
(-)a/api/v1/swagger/definitions/circ-rule-kind.json (+15 lines)
Line 0 Link Here
1
{
2
  "type": "object",
3
  "properties": {
4
    "scope": {
5
      "description": "levels that this rule kind can be set for",
6
      "type": "array",
7
      "items": {
8
        "type": "string",
9
        "enum": [ "branchcode", "categorycode", "itemtype" ]
10
      }
11
    }
12
  },
13
  "additionalProperties": false,
14
  "required": ["scope"]
15
}
(-)a/api/v1/swagger/paths.json (+3 lines)
Lines 20-25 Link Here
20
  "/checkouts/{checkout_id}/renewal": {
20
  "/checkouts/{checkout_id}/renewal": {
21
    "$ref": "paths/checkouts.json#/~1checkouts~1{checkout_id}~1renewal"
21
    "$ref": "paths/checkouts.json#/~1checkouts~1{checkout_id}~1renewal"
22
  },
22
  },
23
  "/circulation-rules/kinds": {
24
    "$ref": "paths/circulation-rules.json#/~1circulation-rules~1kinds"
25
  },
23
  "/cities": {
26
  "/cities": {
24
    "$ref": "paths/cities.json#/~1cities"
27
    "$ref": "paths/cities.json#/~1cities"
25
  },
28
  },
(-)a/api/v1/swagger/paths/circulation-rules.json (+35 lines)
Line 0 Link Here
1
{
2
  "/circulation-rules/kinds": {
3
    "get": {
4
      "x-mojo-controller": "Koha::REST::V1::CirculationRules",
5
      "operationId": "get_kinds",
6
      "tags": ["cities"],
7
      "produces": [
8
        "application/json"
9
      ],
10
      "responses": {
11
        "200": {
12
          "description": "A map of rule kind information",
13
          "schema": {
14
            "type": "object",
15
            "additionalProperties": {
16
              "$ref": "../definitions.json#/circ-rule-kind"
17
            }
18
          }
19
        },
20
        "403": {
21
          "description": "Access forbidden",
22
          "schema": {
23
            "$ref": "../definitions.json#/error"
24
          }
25
        },
26
        "500": {
27
          "description": "Internal error",
28
          "schema": {
29
            "$ref": "../definitions.json#/error"
30
          }
31
        }
32
      }
33
    }
34
  }
35
}
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt (-7 / +12 lines)
Lines 8-26 Link Here
8
[% USE CirculationRules %]
8
[% USE CirculationRules %]
9
[% SET footerjs = 1 %]
9
[% SET footerjs = 1 %]
10
10
11
[% SET branchcode = humanbranch || '*' %]
11
[% SET branchcode = humanbranch || undef %]
12
12
13
[% SET categorycodes = [] %]
13
[% SET categorycodes = [] %]
14
[% FOREACH pc IN patron_categories %]
14
[% FOREACH pc IN patron_categories %]
15
    [% categorycodes.push( pc.id ) %]
15
    [% categorycodes.push( pc.id ) %]
16
[% END %]
16
[% END %]
17
[% categorycodes.push('*') %]
17
[% categorycodes.push(undef) %]
18
18
19
[% SET itemtypes = [] %]
19
[% SET itemtypes = [] %]
20
[% FOREACH i IN itemtypeloop %]
20
[% FOREACH i IN itemtypeloop %]
21
    [% itemtypes.push( i.itemtype ) %]
21
    [% itemtypes.push( i.itemtype ) %]
22
[% END %]
22
[% END %]
23
[% itemtypes.push('*') %]
23
[% itemtypes.push(undef) %]
24
24
25
[% INCLUDE 'doc-head-open.inc' %]
25
[% INCLUDE 'doc-head-open.inc' %]
26
<title>Koha &rsaquo; Administration &rsaquo; Circulation and fine rules</title>
26
<title>Koha &rsaquo; Administration &rsaquo; Circulation and fine rules</title>
Lines 162-180 Link Here
162
                            [% SET row_count = row_count + 1 %]
162
                            [% SET row_count = row_count + 1 %]
163
                            <tr row_countd="row_[% row_count %]">
163
                            <tr row_countd="row_[% row_count %]">
164
                                    <td>
164
                                    <td>
165
                                        [% IF c == '*' %]
165
                                        [% IF c == undef %]
166
                                            <em>All</em>
166
                                            <em>All</em>
167
                                        [% ELSE %]
167
                                        [% ELSE %]
168
                                            [% Categories.GetName(c) %]
168
                                            [% Categories.GetName(c) %]
169
                                        [% END %]
169
                                        [% END %]
170
                                    </td>
170
                                    </td>
171
                                    <td>
171
                                    <td>
172
                                        [% IF i == '*' %]
172
                                        [% IF i == undef %]
173
                                            <em>All</em>
173
                                            <em>All</em>
174
                                        [% ELSE %]
174
                                        [% ELSE %]
175
                                            [% ItemTypes.GetDescription(i) %]
175
                                            [% ItemTypes.GetDescription(i) %]
176
                                        [% END %]
176
                                        [% END %]
177
                                    </td>
177
                                    </td>
178
                                    <td class="actions">
179
                                      <a href="#" class="editrule btn btn-default btn-xs"><i class="fa fa-pencil"></i> Edit</a>
180
                                      <a class="btn btn-default btn-xs delete" href="/cgi-bin/koha/admin/smart-rules.pl?op=delete&amp;itemtype=[% rule.itemtype || '*' %]&amp;categorycode=[% rule.categorycode || '*' %]&amp;branch=[% current_branch %]"><i class="fa fa-trash"></i> Delete</a>
181
                                    </td>
178
                                    <td>
182
                                    <td>
179
                                        [% IF rule.note %]
183
                                        [% IF rule.note %]
180
                                            <a name="viewnote" data-toggle="popover" title="Note" data-content="[% rule.note | html %]" data-placement="top" data-trigger="hover">View note</a>
184
                                            <a name="viewnote" data-toggle="popover" title="Note" data-content="[% rule.note | html %]" data-placement="top" data-trigger="hover">View note</a>
Lines 288-294 Link Here
288
                                    <td>[% rentaldiscount %]</td>
292
                                    <td>[% rentaldiscount %]</td>
289
                                    <td class="actions">
293
                                    <td class="actions">
290
                                      <a href="#" class="editrule btn btn-default btn-xs"><i class="fa fa-pencil"></i> Edit</a>
294
                                      <a href="#" class="editrule btn btn-default btn-xs"><i class="fa fa-pencil"></i> Edit</a>
291
                                      <a class="btn btn-default btn-xs delete" href="/cgi-bin/koha/admin/smart-rules.pl?op=delete&amp;itemtype=[% rule.itemtype | uri %]&amp;categorycode=[% rule.categorycode | uri %]&amp;branch=[% rule.current_branch | uri %]"><i class="fa fa-trash"></i> Delete</a>
295
                                      <a class="btn btn-default btn-xs delete" href="/cgi-bin/koha/admin/smart-rules.pl?op=delete&amp;itemtype=[% rule.itemtype || '*' | uri %]&amp;categorycode=[% rule.categorycode || '*' | uri %]&amp;branch=[% rule.current_branch | uri %]"><i class="fa fa-trash"></i> Delete</a>
292
                                    </td>
296
                                    </td>
293
                            </tr>
297
                            </tr>
294
                        [% END %]
298
                        [% END %]
Lines 597-602 Link Here
597
                    <th>&nbsp;</th>
601
                    <th>&nbsp;</th>
598
                </tr>
602
                </tr>
599
                [% FOREACH c IN categorycodes %]
603
                [% FOREACH c IN categorycodes %]
604
                    [% NEXT UNLESS c %]
600
                    [% SET patron_maxissueqty = CirculationRules.Search( branchcode, c, undef, 'patron_maxissueqty' ) %]
605
                    [% SET patron_maxissueqty = CirculationRules.Search( branchcode, c, undef, 'patron_maxissueqty' ) %]
601
                    [% SET patron_maxonsiteissueqty = CirculationRules.Search( branchcode, c, undef, 'patron_maxonsiteissueqty' ) %]
606
                    [% SET patron_maxonsiteissueqty = CirculationRules.Search( branchcode, c, undef, 'patron_maxonsiteissueqty' ) %]
602
                    [% SET max_holds = CirculationRules.Search( branchcode, c, undef, 'max_holds' ) %]
607
                    [% SET max_holds = CirculationRules.Search( branchcode, c, undef, 'max_holds' ) %]
Lines 604-610 Link Here
604
                    [% IF  ( patron_maxissueqty.defined && patron_maxissueqty != '' ) || ( patron_maxonsiteissueqty.defined && patron_maxonsiteissueqty != '' ) || ( max_holds.defined && max_holds != '' ) %]
609
                    [% IF  ( patron_maxissueqty.defined && patron_maxissueqty != '' ) || ( patron_maxonsiteissueqty.defined && patron_maxonsiteissueqty != '' ) || ( max_holds.defined && max_holds != '' ) %]
605
                    <tr>
610
                    <tr>
606
                        <td>
611
                        <td>
607
                            [% IF c == '*'%]
612
                            [% IF c == undef %]
608
                                <em>Default</em>
613
                                <em>Default</em>
609
                            [% ELSE %]
614
                            [% ELSE %]
610
                                [% Categories.GetName(c) | html %]
615
                                [% Categories.GetName(c) | html %]
(-)a/t/db_dependent/ArticleRequests.t (-12 / +12 lines)
Lines 174-182 is( $biblio->article_requests_finished()->count(), 1, 'Canceled request not retu Link Here
174
174
175
my $rule = Koha::CirculationRules->set_rule(
175
my $rule = Koha::CirculationRules->set_rule(
176
    {
176
    {
177
        categorycode => '*',
177
        categorycode => undef,
178
        itemtype     => '*',
178
        itemtype     => undef,
179
        branchcode   => '*',
179
        branchcode   => undef,
180
        rule_name    => 'article_requests',
180
        rule_name    => 'article_requests',
181
        rule_value   => 'yes',
181
        rule_value   => 'yes',
182
    }
182
    }
Lines 189-197 $rule->delete(); Link Here
189
189
190
$rule = Koha::CirculationRules->set_rule(
190
$rule = Koha::CirculationRules->set_rule(
191
    {
191
    {
192
        categorycode => '*',
192
        categorycode => undef,
193
        itemtype     => '*',
193
        itemtype     => undef,
194
        branchcode   => '*',
194
        branchcode   => undef,
195
        rule_name    => 'article_requests',
195
        rule_name    => 'article_requests',
196
        rule_value   => 'bib_only',
196
        rule_value   => 'bib_only',
197
    }
197
    }
Lines 204-212 $rule->delete(); Link Here
204
204
205
$rule = Koha::CirculationRules->set_rule(
205
$rule = Koha::CirculationRules->set_rule(
206
    {
206
    {
207
        categorycode => '*',
207
        categorycode => undef,
208
        itemtype     => '*',
208
        itemtype     => undef,
209
        branchcode   => '*',
209
        branchcode   => undef,
210
        rule_name    => 'article_requests',
210
        rule_name    => 'article_requests',
211
        rule_value   => 'item_only',
211
        rule_value   => 'item_only',
212
    }
212
    }
Lines 219-227 $rule->delete(); Link Here
219
219
220
$rule = Koha::CirculationRules->set_rule(
220
$rule = Koha::CirculationRules->set_rule(
221
    {
221
    {
222
        categorycode => '*',
222
        categorycode => undef,
223
        itemtype     => '*',
223
        itemtype     => undef,
224
        branchcode   => '*',
224
        branchcode   => undef,
225
        rule_name    => 'article_requests',
225
        rule_name    => 'article_requests',
226
        rule_value   => 'no',
226
        rule_value   => 'no',
227
    }
227
    }
(-)a/t/db_dependent/Circulation.t (-77 / +94 lines)
Lines 20-25 use utf8; Link Here
20
20
21
use Test::More tests => 45;
21
use Test::More tests => 45;
22
use Test::MockModule;
22
use Test::MockModule;
23
use Test::Deep qw( cmp_deeply );
23
24
24
use Data::Dumper;
25
use Data::Dumper;
25
use DateTime;
26
use DateTime;
Lines 254-262 is( Link Here
254
$dbh->do('DELETE FROM circulation_rules');
255
$dbh->do('DELETE FROM circulation_rules');
255
Koha::CirculationRules->set_rules(
256
Koha::CirculationRules->set_rules(
256
    {
257
    {
257
        categorycode => '*',
258
        categorycode => undef,
258
        branchcode   => '*',
259
        branchcode   => undef,
259
        itemtype     => '*',
260
        itemtype     => undef,
260
        rules        => {
261
        rules        => {
261
            reservesallowed => 25,
262
            reservesallowed => 25,
262
            issuelength     => 14,
263
            issuelength     => 14,
Lines 392-400 subtest "CanBookBeRenewed tests" => sub { Link Here
392
    # Testing of feature to allow the renewal of reserved items if other items on the record can fill all needed holds
393
    # Testing of feature to allow the renewal of reserved items if other items on the record can fill all needed holds
393
    Koha::CirculationRules->set_rule(
394
    Koha::CirculationRules->set_rule(
394
        {
395
        {
395
            categorycode => '*',
396
            categorycode => undef,
396
            branchcode   => '*',
397
            branchcode   => undef,
397
            itemtype     => '*',
398
            itemtype     => undef,
398
            rule_name    => 'onshelfholds',
399
            rule_name    => 'onshelfholds',
399
            rule_value   => '1',
400
            rule_value   => '1',
400
        }
401
        }
Lines 615-623 subtest "CanBookBeRenewed tests" => sub { Link Here
615
    # Test premature manual renewal
616
    # Test premature manual renewal
616
    Koha::CirculationRules->set_rule(
617
    Koha::CirculationRules->set_rule(
617
        {
618
        {
618
            categorycode => '*',
619
            categorycode => undef,
619
            branchcode   => '*',
620
            branchcode   => undef,
620
            itemtype     => '*',
621
            itemtype     => undef,
621
            rule_name    => 'norenewalbefore',
622
            rule_name    => 'norenewalbefore',
622
            rule_value   => '7',
623
            rule_value   => '7',
623
        }
624
        }
Lines 692-700 subtest "CanBookBeRenewed tests" => sub { Link Here
692
693
693
        Koha::CirculationRules->set_rules(
694
        Koha::CirculationRules->set_rules(
694
            {
695
            {
695
                categorycode => '*',
696
                categorycode => undef,
696
                branchcode   => '*',
697
                branchcode   => undef,
697
                itemtype     => '*',
698
                itemtype     => undef,
698
                rules        => {
699
                rules        => {
699
                    norenewalbefore       => '7',
700
                    norenewalbefore       => '7',
700
                    no_auto_renewal_after => '9',
701
                    no_auto_renewal_after => '9',
Lines 708-716 subtest "CanBookBeRenewed tests" => sub { Link Here
708
709
709
        Koha::CirculationRules->set_rules(
710
        Koha::CirculationRules->set_rules(
710
            {
711
            {
711
                categorycode => '*',
712
                categorycode => undef,
712
                branchcode   => '*',
713
                branchcode   => undef,
713
                itemtype     => '*',
714
                itemtype     => undef,
714
                rules        => {
715
                rules        => {
715
                    norenewalbefore       => '7',
716
                    norenewalbefore       => '7',
716
                    no_auto_renewal_after => '10',
717
                    no_auto_renewal_after => '10',
Lines 724-732 subtest "CanBookBeRenewed tests" => sub { Link Here
724
725
725
        Koha::CirculationRules->set_rules(
726
        Koha::CirculationRules->set_rules(
726
            {
727
            {
727
                categorycode => '*',
728
                categorycode => undef,
728
                branchcode   => '*',
729
                branchcode   => undef,
729
                itemtype     => '*',
730
                itemtype     => undef,
730
                rules        => {
731
                rules        => {
731
                    norenewalbefore       => '7',
732
                    norenewalbefore       => '7',
732
                    no_auto_renewal_after => '11',
733
                    no_auto_renewal_after => '11',
Lines 740-748 subtest "CanBookBeRenewed tests" => sub { Link Here
740
741
741
        Koha::CirculationRules->set_rules(
742
        Koha::CirculationRules->set_rules(
742
            {
743
            {
743
                categorycode => '*',
744
                categorycode => undef,
744
                branchcode   => '*',
745
                branchcode   => undef,
745
                itemtype     => '*',
746
                itemtype     => undef,
746
                rules        => {
747
                rules        => {
747
                    norenewalbefore       => '10',
748
                    norenewalbefore       => '10',
748
                    no_auto_renewal_after => '11',
749
                    no_auto_renewal_after => '11',
Lines 756-764 subtest "CanBookBeRenewed tests" => sub { Link Here
756
757
757
        Koha::CirculationRules->set_rules(
758
        Koha::CirculationRules->set_rules(
758
            {
759
            {
759
                categorycode => '*',
760
                categorycode => undef,
760
                branchcode   => '*',
761
                branchcode   => undef,
761
                itemtype     => '*',
762
                itemtype     => undef,
762
                rules        => {
763
                rules        => {
763
                    norenewalbefore       => '10',
764
                    norenewalbefore       => '10',
764
                    no_auto_renewal_after => undef,
765
                    no_auto_renewal_after => undef,
Lines 773-781 subtest "CanBookBeRenewed tests" => sub { Link Here
773
774
774
        Koha::CirculationRules->set_rules(
775
        Koha::CirculationRules->set_rules(
775
            {
776
            {
776
                categorycode => '*',
777
                categorycode => undef,
777
                branchcode   => '*',
778
                branchcode   => undef,
778
                itemtype     => '*',
779
                itemtype     => undef,
779
                rules        => {
780
                rules        => {
780
                    norenewalbefore       => '7',
781
                    norenewalbefore       => '7',
781
                    no_auto_renewal_after => '15',
782
                    no_auto_renewal_after => '15',
Lines 790-798 subtest "CanBookBeRenewed tests" => sub { Link Here
790
791
791
        Koha::CirculationRules->set_rules(
792
        Koha::CirculationRules->set_rules(
792
            {
793
            {
793
                categorycode => '*',
794
                categorycode => undef,
794
                branchcode   => '*',
795
                branchcode   => undef,
795
                itemtype     => '*',
796
                itemtype     => undef,
796
                rules        => {
797
                rules        => {
797
                    norenewalbefore       => '10',
798
                    norenewalbefore       => '10',
798
                    no_auto_renewal_after => undef,
799
                    no_auto_renewal_after => undef,
Lines 823-831 subtest "CanBookBeRenewed tests" => sub { Link Here
823
824
824
        Koha::CirculationRules->set_rules(
825
        Koha::CirculationRules->set_rules(
825
            {
826
            {
826
                categorycode => '*',
827
                categorycode => undef,
827
                branchcode   => '*',
828
                branchcode   => undef,
828
                itemtype     => '*',
829
                itemtype     => undef,
829
                rules        => {
830
                rules        => {
830
                    norenewalbefore       => '10',
831
                    norenewalbefore       => '10',
831
                    no_auto_renewal_after => '11',
832
                    no_auto_renewal_after => '11',
Lines 950-958 subtest "CanBookBeRenewed tests" => sub { Link Here
950
        AddIssue( $renewing_borrower, $item_to_auto_renew->{barcode}, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } );
951
        AddIssue( $renewing_borrower, $item_to_auto_renew->{barcode}, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } );
951
        Koha::CirculationRules->set_rules(
952
        Koha::CirculationRules->set_rules(
952
            {
953
            {
953
                categorycode => '*',
954
                categorycode => undef,
954
                branchcode   => '*',
955
                branchcode   => undef,
955
                itemtype     => '*',
956
                itemtype     => undef,
956
                rules        => {
957
                rules        => {
957
                    norenewalbefore       => '7',
958
                    norenewalbefore       => '7',
958
                    no_auto_renewal_after => '',
959
                    no_auto_renewal_after => '',
Lines 965-973 subtest "CanBookBeRenewed tests" => sub { Link Here
965
        my $five_days_before = dt_from_string->add( days => -5 );
966
        my $five_days_before = dt_from_string->add( days => -5 );
966
        Koha::CirculationRules->set_rules(
967
        Koha::CirculationRules->set_rules(
967
            {
968
            {
968
                categorycode => '*',
969
                categorycode => undef,
969
                branchcode   => '*',
970
                branchcode   => undef,
970
                itemtype     => '*',
971
                itemtype     => undef,
971
                rules        => {
972
                rules        => {
972
                    norenewalbefore       => '10',
973
                    norenewalbefore       => '10',
973
                    no_auto_renewal_after => '5',
974
                    no_auto_renewal_after => '5',
Lines 986-994 subtest "CanBookBeRenewed tests" => sub { Link Here
986
        $dbh->do(q{UPDATE circulation_rules SET rule_value = NULL WHERE rule_name = 'no_auto_renewal_after_hard_limit'});
987
        $dbh->do(q{UPDATE circulation_rules SET rule_value = NULL WHERE rule_name = 'no_auto_renewal_after_hard_limit'});
987
        Koha::CirculationRules->set_rules(
988
        Koha::CirculationRules->set_rules(
988
            {
989
            {
989
                categorycode => '*',
990
                categorycode => undef,
990
                branchcode   => '*',
991
                branchcode   => undef,
991
                itemtype     => '*',
992
                itemtype     => undef,
992
                rules        => {
993
                rules        => {
993
                    norenewalbefore       => '10',
994
                    norenewalbefore       => '10',
994
                    no_auto_renewal_after => '15',
995
                    no_auto_renewal_after => '15',
Lines 1004-1012 subtest "CanBookBeRenewed tests" => sub { Link Here
1004
        my $two_days_ahead = dt_from_string->add( days => 2 );
1005
        my $two_days_ahead = dt_from_string->add( days => 2 );
1005
        Koha::CirculationRules->set_rules(
1006
        Koha::CirculationRules->set_rules(
1006
            {
1007
            {
1007
                categorycode => '*',
1008
                categorycode => undef,
1008
                branchcode   => '*',
1009
                branchcode   => undef,
1009
                itemtype     => '*',
1010
                itemtype     => undef,
1010
                rules        => {
1011
                rules        => {
1011
                    norenewalbefore       => '10',
1012
                    norenewalbefore       => '10',
1012
                    no_auto_renewal_after => '',
1013
                    no_auto_renewal_after => '',
Lines 1021-1029 subtest "CanBookBeRenewed tests" => sub { Link Here
1021
        );
1022
        );
1022
        Koha::CirculationRules->set_rules(
1023
        Koha::CirculationRules->set_rules(
1023
            {
1024
            {
1024
                categorycode => '*',
1025
                categorycode => undef,
1025
                branchcode   => '*',
1026
                branchcode   => undef,
1026
                itemtype     => '*',
1027
                itemtype     => undef,
1027
                rules        => {
1028
                rules        => {
1028
                    norenewalbefore       => '10',
1029
                    norenewalbefore       => '10',
1029
                    no_auto_renewal_after => '15',
1030
                    no_auto_renewal_after => '15',
Lines 1043-1051 subtest "CanBookBeRenewed tests" => sub { Link Here
1043
    # set policy to forbid renewals
1044
    # set policy to forbid renewals
1044
    Koha::CirculationRules->set_rules(
1045
    Koha::CirculationRules->set_rules(
1045
        {
1046
        {
1046
            categorycode => '*',
1047
            categorycode => undef,
1047
            branchcode   => '*',
1048
            branchcode   => undef,
1048
            itemtype     => '*',
1049
            itemtype     => undef,
1049
            rules        => {
1050
            rules        => {
1050
                norenewalbefore => undef,
1051
                norenewalbefore => undef,
1051
                renewalsallowed => 0,
1052
                renewalsallowed => 0,
Lines 1289-1297 subtest "AllowRenewalIfOtherItemsAvailable tests" => sub { Link Here
1289
    $dbh->do('DELETE FROM circulation_rules');
1290
    $dbh->do('DELETE FROM circulation_rules');
1290
    Koha::CirculationRules->set_rules(
1291
    Koha::CirculationRules->set_rules(
1291
        {
1292
        {
1292
            categorycode => '*',
1293
            categorycode => undef,
1293
            itemtype     => '*',
1294
            itemtype     => undef,
1294
            branchcode   => '*',
1295
            branchcode   => undef,
1295
            rules        => {
1296
            rules        => {
1296
                reservesallowed => 25,
1297
                reservesallowed => 25,
1297
                issuelength     => 14,
1298
                issuelength     => 14,
Lines 1353-1361 subtest "AllowRenewalIfOtherItemsAvailable tests" => sub { Link Here
1353
1354
1354
    Koha::CirculationRules->set_rules(
1355
    Koha::CirculationRules->set_rules(
1355
        {
1356
        {
1356
            categorycode => '*',
1357
            categorycode => undef,
1357
            itemtype     => '*',
1358
            itemtype     => undef,
1358
            branchcode   => '*',
1359
            branchcode   => undef,
1359
            rules        => {
1360
            rules        => {
1360
                onshelfholds => 0,
1361
                onshelfholds => 0,
1361
            }
1362
            }
Lines 1367-1375 subtest "AllowRenewalIfOtherItemsAvailable tests" => sub { Link Here
1367
1368
1368
    Koha::CirculationRules->set_rules(
1369
    Koha::CirculationRules->set_rules(
1369
        {
1370
        {
1370
            categorycode => '*',
1371
            categorycode => undef,
1371
            itemtype     => '*',
1372
            itemtype     => undef,
1372
            branchcode   => '*',
1373
            branchcode   => undef,
1373
            rules        => {
1374
            rules        => {
1374
                onshelfholds => 0,
1375
                onshelfholds => 0,
1375
            }
1376
            }
Lines 1381-1389 subtest "AllowRenewalIfOtherItemsAvailable tests" => sub { Link Here
1381
1382
1382
    Koha::CirculationRules->set_rules(
1383
    Koha::CirculationRules->set_rules(
1383
        {
1384
        {
1384
            categorycode => '*',
1385
            categorycode => undef,
1385
            itemtype     => '*',
1386
            itemtype     => undef,
1386
            branchcode   => '*',
1387
            branchcode   => undef,
1387
            rules        => {
1388
            rules        => {
1388
                onshelfholds => 1,
1389
                onshelfholds => 1,
1389
            }
1390
            }
Lines 1395-1403 subtest "AllowRenewalIfOtherItemsAvailable tests" => sub { Link Here
1395
1396
1396
    Koha::CirculationRules->set_rules(
1397
    Koha::CirculationRules->set_rules(
1397
        {
1398
        {
1398
            categorycode => '*',
1399
            categorycode => undef,
1399
            itemtype     => '*',
1400
            itemtype     => undef,
1400
            branchcode   => '*',
1401
            branchcode   => undef,
1401
            rules        => {
1402
            rules        => {
1402
                onshelfholds => 1,
1403
                onshelfholds => 1,
1403
            }
1404
            }
Lines 1835-1857 subtest 'CanBookBeIssued + AllowMultipleIssuesOnABiblio' => sub { Link Here
1835
1836
1836
    t::lib::Mocks::mock_preference('AllowMultipleIssuesOnABiblio', 0);
1837
    t::lib::Mocks::mock_preference('AllowMultipleIssuesOnABiblio', 0);
1837
    ( $error, $question, $alerts ) = CanBookBeIssued( $patron, $item_2->{barcode} );
1838
    ( $error, $question, $alerts ) = CanBookBeIssued( $patron, $item_2->{barcode} );
1838
    is( keys(%$error) + keys(%$alerts),  0, 'No error or alert should be raised' . str($error, $question, $alerts) );
1839
    cmp_deeply(
1839
    is( $question->{BIBLIO_ALREADY_ISSUED}, 1, 'BIBLIO_ALREADY_ISSUED question flag should be set if AllowMultipleIssuesOnABiblio=0 and issue already exists' . str($error, $question, $alerts) );
1840
        { error => $error, alerts => $alerts },
1841
        { error => {}, alerts => {} },
1842
        'No error or alert should be raised'
1843
    );
1844
    is( $question->{BIBLIO_ALREADY_ISSUED}, 1, 'BIBLIO_ALREADY_ISSUED question flag should be set if AllowMultipleIssuesOnABiblio=0 and issue already exists' );
1840
1845
1841
    t::lib::Mocks::mock_preference('AllowMultipleIssuesOnABiblio', 1);
1846
    t::lib::Mocks::mock_preference('AllowMultipleIssuesOnABiblio', 1);
1842
    ( $error, $question, $alerts ) = CanBookBeIssued( $patron, $item_2->{barcode} );
1847
    ( $error, $question, $alerts ) = CanBookBeIssued( $patron, $item_2->{barcode} );
1843
    is( keys(%$error) + keys(%$question) + keys(%$alerts),  0, 'No BIBLIO_ALREADY_ISSUED flag should be set if AllowMultipleIssuesOnABiblio=1' . str($error, $question, $alerts) );
1848
    cmp_deeply(
1849
        { error => $error, question => $question, alerts => $alerts },
1850
        { error => {}, question => {}, alerts => {} },
1851
        'No BIBLIO_ALREADY_ISSUED flag should be set if AllowMultipleIssuesOnABiblio=1'
1852
    );
1844
1853
1845
    # Add a subscription
1854
    # Add a subscription
1846
    Koha::Subscription->new({ biblionumber => $biblionumber })->store;
1855
    Koha::Subscription->new({ biblionumber => $biblionumber })->store;
1847
1856
1848
    t::lib::Mocks::mock_preference('AllowMultipleIssuesOnABiblio', 0);
1857
    t::lib::Mocks::mock_preference('AllowMultipleIssuesOnABiblio', 0);
1849
    ( $error, $question, $alerts ) = CanBookBeIssued( $patron, $item_2->{barcode} );
1858
    ( $error, $question, $alerts ) = CanBookBeIssued( $patron, $item_2->{barcode} );
1850
    is( keys(%$error) + keys(%$question) + keys(%$alerts),  0, 'No BIBLIO_ALREADY_ISSUED flag should be set if it is a subscription' . str($error, $question, $alerts) );
1859
    cmp_deeply(
1860
        { error => $error, question => $question, alerts => $alerts },
1861
        { error => {}, question => {}, alerts => {} },
1862
        'No BIBLIO_ALREADY_ISSUED flag should be set if it is a subscription'
1863
    );
1851
1864
1852
    t::lib::Mocks::mock_preference('AllowMultipleIssuesOnABiblio', 1);
1865
    t::lib::Mocks::mock_preference('AllowMultipleIssuesOnABiblio', 1);
1853
    ( $error, $question, $alerts ) = CanBookBeIssued( $patron, $item_2->{barcode} );
1866
    ( $error, $question, $alerts ) = CanBookBeIssued( $patron, $item_2->{barcode} );
1854
    is( keys(%$error) + keys(%$question) + keys(%$alerts),  0, 'No BIBLIO_ALREADY_ISSUED flag should be set if it is a subscription' . str($error, $question, $alerts) );
1867
    cmp_deeply(
1868
        { error => $error, question => $question, alerts => $alerts },
1869
        { error => {}, question => {}, alerts => {} },
1870
        'No BIBLIO_ALREADY_ISSUED flag should be set if it is a subscription'
1871
    );
1855
};
1872
};
1856
1873
1857
subtest 'AddReturn + CumulativeRestrictionPeriods' => sub {
1874
subtest 'AddReturn + CumulativeRestrictionPeriods' => sub {
Lines 1883-1891 subtest 'AddReturn + CumulativeRestrictionPeriods' => sub { Link Here
1883
    Koha::CirculationRules->search->delete;
1900
    Koha::CirculationRules->search->delete;
1884
    Koha::CirculationRules->set_rules(
1901
    Koha::CirculationRules->set_rules(
1885
        {
1902
        {
1886
            categorycode => '*',
1903
            categorycode => undef,
1887
            itemtype     => '*',
1904
            itemtype     => undef,
1888
            branchcode   => '*',
1905
            branchcode   => undef,
1889
            rules        => {
1906
            rules        => {
1890
                issuelength => 1,
1907
                issuelength => 1,
1891
                firstremind => 1,        # 1 day of grace
1908
                firstremind => 1,        # 1 day of grace
Lines 2196-2204 subtest 'AddReturn | is_overdue' => sub { Link Here
2196
    Koha::CirculationRules->search->delete;
2213
    Koha::CirculationRules->search->delete;
2197
    my $rule = Koha::CirculationRules->set_rules(
2214
    my $rule = Koha::CirculationRules->set_rules(
2198
        {
2215
        {
2199
            categorycode => '*',
2216
            categorycode => undef,
2200
            itemtype     => '*',
2217
            itemtype     => undef,
2201
            branchcode   => '*',
2218
            branchcode   => undef,
2202
            rules        => {
2219
            rules        => {
2203
                issuelength  => 6,
2220
                issuelength  => 6,
2204
                lengthunit   => 'days',
2221
                lengthunit   => 'days',
(-)a/t/db_dependent/Circulation/Branch.t (-10 / +21 lines)
Lines 154-160 Koha::CirculationRules->set_rules( Link Here
154
    {
154
    {
155
        branchcode   => $samplebranch1->{branchcode},
155
        branchcode   => $samplebranch1->{branchcode},
156
        categorycode => $samplecat->{categorycode},
156
        categorycode => $samplecat->{categorycode},
157
        itemtype     => undef,
158
        rules        => {
157
        rules        => {
159
            patron_maxissueqty       => 5,
158
            patron_maxissueqty       => 5,
160
            patron_maxonsiteissueqty => 6,
159
            patron_maxonsiteissueqty => 6,
Lines 162-177 Koha::CirculationRules->set_rules( Link Here
162
    }
161
    }
163
);
162
);
164
163
164
165
Koha::CirculationRules->set_rules(
165
Koha::CirculationRules->set_rules(
166
    {
166
    {
167
        branchcode   => $samplebranch2->{branchcode},
167
        branchcode   => $samplebranch2->{branchcode},
168
        categorycode => undef,
168
        categorycode => undef,
169
        itemtype     => undef,
170
        rules        => {
169
        rules        => {
171
            patron_maxissueqty       => 3,
170
            patron_maxissueqty       => 3,
172
            patron_maxonsiteissueqty => 2,
171
            patron_maxonsiteissueqty => 2,
173
            holdallowed              => 1,
172
        }
174
            returnbranch             => 'holdingbranch',
173
    }
174
);
175
Koha::CirculationRules->set_rules(
176
    {
177
        branchcode   => $samplebranch2->{branchcode},
178
        itemtype     => undef,
179
        rules        => {
180
            holdallowed       => 1,
181
            returnbranch      => 'holdingbranch',
175
        }
182
        }
176
    }
183
    }
177
);
184
);
Lines 180-191 Koha::CirculationRules->set_rules( Link Here
180
    {
187
    {
181
        branchcode   => undef,
188
        branchcode   => undef,
182
        categorycode => undef,
189
        categorycode => undef,
183
        itemtype     => undef,
184
        rules        => {
190
        rules        => {
185
            patron_maxissueqty       => 4,
191
            patron_maxissueqty       => 4,
186
            patron_maxonsiteissueqty => 5,
192
            patron_maxonsiteissueqty => 5,
187
            holdallowed              => 3,
193
        }
188
            returnbranch             => 'homebranch',
194
    }
195
);
196
Koha::CirculationRules->set_rules(
197
    {
198
        branchcode   => undef,
199
        itemtype     => undef,
200
        rules        => {
201
            holdallowed       => 3,
202
            returnbranch      => 'homebranch',
189
        }
203
        }
190
    }
204
    }
191
);
205
);
Lines 193-199 Koha::CirculationRules->set_rules( Link Here
193
Koha::CirculationRules->set_rules(
207
Koha::CirculationRules->set_rules(
194
    {
208
    {
195
        branchcode   => $samplebranch1->{branchcode},
209
        branchcode   => $samplebranch1->{branchcode},
196
        categorycode => undef,
197
        itemtype     => $sampleitemtype1->{itemtype},
210
        itemtype     => $sampleitemtype1->{itemtype},
198
        rules        => {
211
        rules        => {
199
            holdallowed       => 5,
212
            holdallowed       => 5,
Lines 204-210 Koha::CirculationRules->set_rules( Link Here
204
Koha::CirculationRules->set_rules(
217
Koha::CirculationRules->set_rules(
205
    {
218
    {
206
        branchcode   => $samplebranch2->{branchcode},
219
        branchcode   => $samplebranch2->{branchcode},
207
        categorycode => undef,
208
        itemtype     => $sampleitemtype1->{itemtype},
220
        itemtype     => $sampleitemtype1->{itemtype},
209
        rules        => {
221
        rules        => {
210
            holdallowed       => 5,
222
            holdallowed       => 5,
Lines 215-221 Koha::CirculationRules->set_rules( Link Here
215
Koha::CirculationRules->set_rules(
227
Koha::CirculationRules->set_rules(
216
    {
228
    {
217
        branchcode   => $samplebranch2->{branchcode},
229
        branchcode   => $samplebranch2->{branchcode},
218
        categorycode => undef,
219
        itemtype     => $sampleitemtype2->{itemtype},
230
        itemtype     => $sampleitemtype2->{itemtype},
220
        rules        => {
231
        rules        => {
221
            holdallowed       => 5,
232
            holdallowed       => 5,
(-)a/t/db_dependent/Circulation/CalcFine.t (-6 / +6 lines)
Lines 80-88 subtest 'Test basic functionality' => sub { Link Here
80
80
81
    Koha::CirculationRules->set_rules(
81
    Koha::CirculationRules->set_rules(
82
        {
82
        {
83
            branchcode   => '*',
83
            branchcode   => undef,
84
            categorycode => '*',
84
            categorycode => undef,
85
            itemtype     => '*',
85
            itemtype     => undef,
86
            rules        => {
86
            rules        => {
87
                fine                          => '1.00',
87
                fine                          => '1.00',
88
                lengthunit                    => 'days',
88
                lengthunit                    => 'days',
Lines 120-128 subtest 'Test cap_fine_to_replacement_price' => sub { Link Here
120
    t::lib::Mocks::mock_preference('useDefaultReplacementCost', '1');
120
    t::lib::Mocks::mock_preference('useDefaultReplacementCost', '1');
121
    Koha::CirculationRules->set_rules(
121
    Koha::CirculationRules->set_rules(
122
        {
122
        {
123
            branchcode   => '*',
123
            branchcode   => undef,
124
            categorycode => '*',
124
            categorycode => undef,
125
            itemtype     => '*',
125
            itemtype     => undef,
126
            rules        => {
126
            rules        => {
127
                fine                          => '1.00',
127
                fine                          => '1.00',
128
                lengthunit                    => 'days',
128
                lengthunit                    => 'days',
(-)a/t/db_dependent/Circulation/GetHardDueDate.t (-17 / +14 lines)
Lines 8-14 use Koha::DateUtils; Link Here
8
use Koha::CirculationRules;
8
use Koha::CirculationRules;
9
use Koha::Library;
9
use Koha::Library;
10
10
11
use Test::More tests => 8;
11
use t::lib::TestBuilder;
12
13
use Test::More tests => 10;
12
14
13
BEGIN {
15
BEGIN {
14
    use_ok('C4::Circulation');
16
    use_ok('C4::Circulation');
Lines 103-108 $dbh->do( Link Here
103
    $samplecat->{category_type}
105
    $samplecat->{category_type}
104
);
106
);
105
107
108
my $builder = t::lib::TestBuilder->new;
109
my $sampleitemtype1 = $builder->build({ source => 'Itemtype' })->{itemtype};
110
my $sampleitemtype2 = $builder->build({ source => 'Itemtype' })->{itemtype};
111
106
#Begin Tests
112
#Begin Tests
107
113
108
my $default = {
114
my $default = {
Lines 115-125 my $default = { Link Here
115
my $sampleissuingrule1 = {
121
my $sampleissuingrule1 = {
116
    branchcode   => $samplebranch1->{branchcode},
122
    branchcode   => $samplebranch1->{branchcode},
117
    categorycode => $samplecat->{categorycode},
123
    categorycode => $samplecat->{categorycode},
118
    itemtype     => 'BOOK',
124
    itemtype     => $sampleitemtype1,
119
    rules        => {
125
    rules        => {
120
        reservecharge                    => '0.000000',
121
        restrictedtype                   => 0,
122
        accountsent                      => 0,
123
        finedays                         => 0,
126
        finedays                         => 0,
124
        lengthunit                       => 'days',
127
        lengthunit                       => 'days',
125
        renewalperiod                    => 5,
128
        renewalperiod                    => 5,
Lines 151-157 my $sampleissuingrule1 = { Link Here
151
my $sampleissuingrule2 = {
154
my $sampleissuingrule2 = {
152
    branchcode   => $samplebranch2->{branchcode},
155
    branchcode   => $samplebranch2->{branchcode},
153
    categorycode => $samplecat->{categorycode},
156
    categorycode => $samplecat->{categorycode},
154
    itemtype     => 'BOOK',
157
    itemtype     => $sampleitemtype1,
155
    rules        => {
158
    rules        => {
156
        renewalsallowed               => 0,
159
        renewalsallowed               => 0,
157
        renewalperiod                 => 2,
160
        renewalperiod                 => 2,
Lines 169-177 my $sampleissuingrule2 = { Link Here
169
        chargeperiod_charge_at        => 0,
172
        chargeperiod_charge_at        => 0,
170
        rentaldiscount                => 2.00,
173
        rentaldiscount                => 2.00,
171
        overduefinescap               => undef,
174
        overduefinescap               => undef,
172
        accountsent                   => undef,
173
        reservecharge                 => undef,
174
        restrictedtype                => undef,
175
        maxsuspensiondays             => 0,
175
        maxsuspensiondays             => 0,
176
        onshelfholds                  => 1,
176
        onshelfholds                  => 1,
177
        opacitemholds                 => 'Y',
177
        opacitemholds                 => 'Y',
Lines 183-189 my $sampleissuingrule2 = { Link Here
183
my $sampleissuingrule3 = {
183
my $sampleissuingrule3 = {
184
    branchcode   => $samplebranch1->{branchcode},
184
    branchcode   => $samplebranch1->{branchcode},
185
    categorycode => $samplecat->{categorycode},
185
    categorycode => $samplecat->{categorycode},
186
    itemtype     => 'DVD',
186
    itemtype     => $sampleitemtype2,
187
    rules        => {
187
    rules        => {
188
        renewalsallowed               => 0,
188
        renewalsallowed               => 0,
189
        renewalperiod                 => 3,
189
        renewalperiod                 => 3,
Lines 201-209 my $sampleissuingrule3 = { Link Here
201
        chargeperiod_charge_at        => 0,
201
        chargeperiod_charge_at        => 0,
202
        rentaldiscount                => 3.00,
202
        rentaldiscount                => 3.00,
203
        overduefinescap               => undef,
203
        overduefinescap               => undef,
204
        accountsent                   => undef,
205
        reservecharge                 => undef,
206
        restrictedtype                => undef,
207
        maxsuspensiondays             => 0,
204
        maxsuspensiondays             => 0,
208
        onshelfholds                  => 1,
205
        onshelfholds                  => 1,
209
        opacitemholds                 => 'F',
206
        opacitemholds                 => 'F',
Lines 221-227 Koha::CirculationRules->set_rules( $sampleissuingrule3 ); Link Here
221
is_deeply(
218
is_deeply(
222
    C4::Circulation::GetLoanLength(
219
    C4::Circulation::GetLoanLength(
223
        $samplecat->{categorycode},
220
        $samplecat->{categorycode},
224
        'BOOK', $samplebranch1->{branchcode}
221
        $sampleitemtype1, $samplebranch1->{branchcode}
225
    ),
222
    ),
226
    { issuelength => 5, lengthunit => 'days', renewalperiod => 5 },
223
    { issuelength => 5, lengthunit => 'days', renewalperiod => 5 },
227
    "GetLoanLength"
224
    "GetLoanLength"
Lines 243-254 is_deeply( Link Here
243
    "With only one parameter, GetLoanLength returns hardcoded values"
240
    "With only one parameter, GetLoanLength returns hardcoded values"
244
);    #NOTE : is that really what is expected?
241
);    #NOTE : is that really what is expected?
245
is_deeply(
242
is_deeply(
246
    C4::Circulation::GetLoanLength( $samplecat->{categorycode}, 'BOOK' ),
243
    C4::Circulation::GetLoanLength( $samplecat->{categorycode}, $sampleitemtype1 ),
247
    $default,
244
    $default,
248
    "With only two parameters, GetLoanLength returns hardcoded values"
245
    "With only two parameters, GetLoanLength returns hardcoded values"
249
);    #NOTE : is that really what is expected?
246
);    #NOTE : is that really what is expected?
250
is_deeply(
247
is_deeply(
251
    C4::Circulation::GetLoanLength( $samplecat->{categorycode}, 'BOOK', $samplebranch1->{branchcode} ),
248
    C4::Circulation::GetLoanLength( $samplecat->{categorycode}, $sampleitemtype1, $samplebranch1->{branchcode} ),
252
    {
249
    {
253
        issuelength   => 5,
250
        issuelength   => 5,
254
        renewalperiod => 5,
251
        renewalperiod => 5,
Lines 259-265 is_deeply( Link Here
259
256
260
#Test GetHardDueDate
257
#Test GetHardDueDate
261
my @hardduedate = C4::Circulation::GetHardDueDate( $samplecat->{categorycode},
258
my @hardduedate = C4::Circulation::GetHardDueDate( $samplecat->{categorycode},
262
    'BOOK', $samplebranch1->{branchcode} );
259
    $sampleitemtype1, $samplebranch1->{branchcode} );
263
is_deeply(
260
is_deeply(
264
    \@hardduedate,
261
    \@hardduedate,
265
    [
262
    [
(-)a/t/db_dependent/Circulation/IssuingRules/maxsuspensiondays.t (-6 / +6 lines)
Lines 32-40 t::lib::Mocks::mock_userenv({ branchcode => $branchcode }); Link Here
32
Koha::CirculationRules->search->delete;
32
Koha::CirculationRules->search->delete;
33
Koha::CirculationRules->set_rules(
33
Koha::CirculationRules->set_rules(
34
    {
34
    {
35
        categorycode => '*',
35
        categorycode => undef,
36
        itemtype     => '*',
36
        itemtype     => undef,
37
        branchcode   => '*',
37
        branchcode   => undef,
38
        rules        => {
38
        rules        => {
39
            firstremind => 0,
39
            firstremind => 0,
40
            finedays    => 2,
40
            finedays    => 2,
Lines 88-96 DelDebarment( $debarments->[0]->{borrower_debarment_id} ); Link Here
88
# Test with maxsuspensiondays = 10 days
88
# Test with maxsuspensiondays = 10 days
89
Koha::CirculationRules->set_rules(
89
Koha::CirculationRules->set_rules(
90
    {
90
    {
91
        categorycode => '*',
91
        categorycode => undef,
92
        itemtype     => '*',
92
        itemtype     => undef,
93
        branchcode   => '*',
93
        branchcode   => undef,
94
        rules        => {
94
        rules        => {
95
            maxsuspensiondays => 10,
95
            maxsuspensiondays => 10,
96
        }
96
        }
(-)a/t/db_dependent/Circulation/Returns.t (-6 / +6 lines)
Lines 60-68 my $builder = t::lib::TestBuilder->new(); Link Here
60
Koha::CirculationRules->search->delete;
60
Koha::CirculationRules->search->delete;
61
Koha::CirculationRules->set_rule(
61
Koha::CirculationRules->set_rule(
62
    {
62
    {
63
        categorycode => '*',
63
        categorycode => undef,
64
        itemtype     => '*',
64
        itemtype     => undef,
65
        branchcode   => '*',
65
        branchcode   => undef,
66
        rule_name    => 'issuelength',
66
        rule_name    => 'issuelength',
67
        rule_value   => 1,
67
        rule_value   => 1,
68
    }
68
    }
Lines 256-264 subtest 'Handle ids duplication' => sub { Link Here
256
    t::lib::Mocks::mock_preference( 'finesMode', 'production' );
256
    t::lib::Mocks::mock_preference( 'finesMode', 'production' );
257
    Koha::CirculationRules->set_rules(
257
    Koha::CirculationRules->set_rules(
258
        {
258
        {
259
            categorycode => '*',
259
            categorycode => undef,
260
            itemtype     => '*',
260
            itemtype     => undef,
261
            branchcode   => '*',
261
            branchcode   => undef,
262
            rules        => {
262
            rules        => {
263
                chargeperiod => 1,
263
                chargeperiod => 1,
264
                fine         => 1,
264
                fine         => 1,
(-)a/t/db_dependent/Circulation/SwitchOnSiteCheckouts.t (-7 / +4 lines)
Lines 85-98 Koha::CirculationRules->search()->delete(); Link Here
85
Koha::CirculationRules->set_rules(
85
Koha::CirculationRules->set_rules(
86
    {
86
    {
87
        branchcode   => $branch->{branchcode},
87
        branchcode   => $branch->{branchcode},
88
        categorycode => '*',
88
        categorycode => undef,
89
        itemtype     => '*',
89
        itemtype     => undef,
90
        rules        => {
90
        rules        => {
91
            maxissueqty       => 2,
91
            maxissueqty       => 2,
92
            maxonsiteissueqty => 1,
92
            maxonsiteissueqty => 1,
93
            branchcode        => $branch->{branchcode},
94
            categorycode      => '*',
95
            itemtype          => '*',
96
            lengthunit        => 'days',
93
            lengthunit        => 'days',
97
            issuelength       => 5,
94
            issuelength       => 5,
98
            hardduedate        => undef,
95
            hardduedate        => undef,
Lines 160-167 Koha::CirculationRules->search()->delete(); Link Here
160
Koha::CirculationRules->set_rules(
157
Koha::CirculationRules->set_rules(
161
    {
158
    {
162
        branchcode   => $branch->{branchcode},
159
        branchcode   => $branch->{branchcode},
163
        categorycode => '*',
160
        categorycode => undef,
164
        itemtype     => '*',
161
        itemtype     => undef,
165
        rules        => {
162
        rules        => {
166
            maxissueqty       => 2,
163
            maxissueqty       => 2,
167
            maxonsiteissueqty => 1,
164
            maxonsiteissueqty => 1,
(-)a/t/db_dependent/Circulation/TooMany.t (-4 / +4 lines)
Lines 107-113 subtest '1 Issuingrule exist 0 0: no issue allowed' => sub { Link Here
107
        {
107
        {
108
            branchcode   => $branch->{branchcode},
108
            branchcode   => $branch->{branchcode},
109
            categorycode => $category->{categorycode},
109
            categorycode => $category->{categorycode},
110
            itemtype     => '*',
110
            itemtype     => undef,
111
            rules        => {
111
            rules        => {
112
                maxissueqty       => 0,
112
                maxissueqty       => 0,
113
                maxonsiteissueqty => 0,
113
                maxonsiteissueqty => 0,
Lines 219-225 subtest '1 Issuingrule exist 1 1: issue is allowed' => sub { Link Here
219
        {
219
        {
220
            branchcode   => $branch->{branchcode},
220
            branchcode   => $branch->{branchcode},
221
            categorycode => $category->{categorycode},
221
            categorycode => $category->{categorycode},
222
            itemtype     => '*',
222
            itemtype     => undef,
223
            rules        => {
223
            rules        => {
224
                maxissueqty       => 1,
224
                maxissueqty       => 1,
225
                maxonsiteissueqty => 1,
225
                maxonsiteissueqty => 1,
Lines 259-265 subtest '1 Issuingrule exist: 1 CO allowed, 1 OSCO allowed. Do a CO' => sub { Link Here
259
        {
259
        {
260
            branchcode   => $branch->{branchcode},
260
            branchcode   => $branch->{branchcode},
261
            categorycode => $category->{categorycode},
261
            categorycode => $category->{categorycode},
262
            itemtype     => '*',
262
            itemtype     => undef,
263
            rules        => {
263
            rules        => {
264
                maxissueqty       => 1,
264
                maxissueqty       => 1,
265
                maxonsiteissueqty => 1,
265
                maxonsiteissueqty => 1,
Lines 315-321 subtest '1 Issuingrule exist: 1 CO allowed, 1 OSCO allowed, Do a OSCO' => sub { Link Here
315
        {
315
        {
316
            branchcode   => $branch->{branchcode},
316
            branchcode   => $branch->{branchcode},
317
            categorycode => $category->{categorycode},
317
            categorycode => $category->{categorycode},
318
            itemtype     => '*',
318
            itemtype     => undef,
319
            rules        => {
319
            rules        => {
320
                maxissueqty       => 1,
320
                maxissueqty       => 1,
321
                maxonsiteissueqty => 1,
321
                maxonsiteissueqty => 1,
(-)a/t/db_dependent/Circulation/issue.t (-3 / +3 lines)
Lines 319-327 is_deeply( Link Here
319
# Add a default rule: renewal is allowed
319
# Add a default rule: renewal is allowed
320
Koha::CirculationRules->set_rules(
320
Koha::CirculationRules->set_rules(
321
    {
321
    {
322
        categorycode => '*',
322
        categorycode => undef,
323
        itemtype     => '*',
323
        itemtype     => undef,
324
        branchcode   => '*',
324
        branchcode   => undef,
325
        rules        => {
325
        rules        => {
326
            renewalsallowed => 3,
326
            renewalsallowed => 3,
327
        }
327
        }
(-)a/t/db_dependent/DecreaseLoanHighHolds.t (-2 / +3 lines)
Lines 99-111 my $patron = pop(@patrons); Link Here
99
99
100
Koha::CirculationRules->set_rules(
100
Koha::CirculationRules->set_rules(
101
    {
101
    {
102
        branchcode   => '*',
102
        branchcode   => undef,
103
        categorycode => '*',
103
        categorycode => undef,
104
        itemtype     => $item->itype,
104
        itemtype     => $item->itype,
105
        rules        => {
105
        rules        => {
106
            issuelength     => '14',
106
            issuelength     => '14',
107
            lengthunit      => 'days',
107
            lengthunit      => 'days',
108
            reservesallowed => '99',
108
            reservesallowed => '99',
109
            holds_per_record => '99',
109
        }
110
        }
110
    }
111
    }
111
);
112
);
(-)a/t/db_dependent/Fines.t (-7 / +7 lines)
Lines 17-25 $dbh->do(q|DELETE FROM circulation_rules|); Link Here
17
17
18
my $issuingrule = Koha::CirculationRules->set_rules(
18
my $issuingrule = Koha::CirculationRules->set_rules(
19
    {
19
    {
20
        categorycode => '*',
20
        categorycode => undef,
21
        itemtype     => '*',
21
        itemtype     => undef,
22
        branchcode   => '*',
22
        branchcode   => undef,
23
        rules        => {
23
        rules        => {
24
            fine                   => 1,
24
            fine                   => 1,
25
            finedays               => 0,
25
            finedays               => 0,
Lines 44-54 $period_end = dt_from_string('2000-01-10'); Link Here
44
is( $fine, 1, '9 days overdue, charge period 7 days, charge at end of interval gives fine of $1' );
44
is( $fine, 1, '9 days overdue, charge period 7 days, charge at end of interval gives fine of $1' );
45
45
46
# Test charging fine at the *beginning* of each charge period
46
# Test charging fine at the *beginning* of each charge period
47
my $issuingrule = Koha::CirculationRules->set_rules(
47
$issuingrule = Koha::CirculationRules->set_rules(
48
    {
48
    {
49
        categorycode => '*',
49
        categorycode => undef,
50
        itemtype     => '*',
50
        itemtype     => undef,
51
        branchcode   => '*',
51
        branchcode   => undef,
52
        rules        => {
52
        rules        => {
53
            chargeperiod_charge_at => 1,
53
            chargeperiod_charge_at => 1,
54
        }
54
        }
(-)a/t/db_dependent/Holds.t (-17 / +13 lines)
Lines 245-253 my ($foreign_item_bibnum, $foreign_item_bibitemnum, $foreign_itemnumber) Link Here
245
  = AddItem({ homebranch => $branch_2, holdingbranch => $branch_2 } , $foreign_biblio->biblionumber);
245
  = AddItem({ homebranch => $branch_2, holdingbranch => $branch_2 } , $foreign_biblio->biblionumber);
246
Koha::CirculationRules->set_rules(
246
Koha::CirculationRules->set_rules(
247
    {
247
    {
248
        categorycode => '*',
248
        categorycode => undef,
249
        branchcode   => '*',
249
        branchcode   => undef,
250
        itemtype     => '*',
250
        itemtype     => undef,
251
        rules        => {
251
        rules        => {
252
            reservesallowed  => 25,
252
            reservesallowed  => 25,
253
            holds_per_record => 99,
253
            holds_per_record => 99,
Lines 256-263 Koha::CirculationRules->set_rules( Link Here
256
);
256
);
257
Koha::CirculationRules->set_rules(
257
Koha::CirculationRules->set_rules(
258
    {
258
    {
259
        categorycode => '*',
259
        categorycode => undef,
260
        branchcode   => '*',
260
        branchcode   => undef,
261
        itemtype     => 'CANNOT',
261
        itemtype     => 'CANNOT',
262
        rules        => {
262
        rules        => {
263
            reservesallowed  => 0,
263
            reservesallowed  => 0,
Lines 363-371 ok( Link Here
363
$dbh->do('DELETE FROM circulation_rules');
363
$dbh->do('DELETE FROM circulation_rules');
364
Koha::CirculationRules->set_rules(
364
Koha::CirculationRules->set_rules(
365
    {
365
    {
366
        categorycode => '*',
366
        categorycode => undef,
367
        branchcode   => '*',
367
        branchcode   => undef,
368
        itemtype     => '*',
368
        itemtype     => undef,
369
        rules        => {
369
        rules        => {
370
            reservesallowed  => 25,
370
            reservesallowed  => 25,
371
            holds_per_record => 99,
371
            holds_per_record => 99,
Lines 376-382 Koha::CirculationRules->set_rules( Link Here
376
    {
376
    {
377
        branchcode => $branch_1,
377
        branchcode => $branch_1,
378
        itemtype   => 'CANNOT',
378
        itemtype   => 'CANNOT',
379
        categorycode => undef,
380
        rules => {
379
        rules => {
381
            holdallowed => 0,
380
            holdallowed => 0,
382
            returnbranch => 'homebranch',
381
            returnbranch => 'homebranch',
Lines 387-393 Koha::CirculationRules->set_rules( Link Here
387
    {
386
    {
388
        branchcode => $branch_1,
387
        branchcode => $branch_1,
389
        itemtype   => 'CAN',
388
        itemtype   => 'CAN',
390
        categorycode => undef,
391
        rules => {
389
        rules => {
392
            holdallowed => 1,
390
            holdallowed => 1,
393
            returnbranch => 'homebranch',
391
            returnbranch => 'homebranch',
Lines 431-438 $biblio = $builder->build_sample_biblio({ itemtype => 'ONLY1' }); Link Here
431
429
432
Koha::CirculationRules->set_rules(
430
Koha::CirculationRules->set_rules(
433
    {
431
    {
434
        categorycode => '*',
432
        categorycode => undef,
435
        branchcode   => '*',
433
        branchcode   => undef,
436
        itemtype     => 'ONLY1',
434
        itemtype     => 'ONLY1',
437
        rules        => {
435
        rules        => {
438
            reservesallowed  => 1,
436
            reservesallowed  => 1,
Lines 467-475 subtest 'Test max_holds per library/patron category' => sub { Link Here
467
        $biblio->biblionumber );
465
        $biblio->biblionumber );
468
    Koha::CirculationRules->set_rules(
466
    Koha::CirculationRules->set_rules(
469
        {
467
        {
470
            categorycode => '*',
468
            categorycode => undef,
471
            branchcode   => '*',
469
            branchcode   => undef,
472
            itemtype     => 'TEST',
470
            itemtype     => $testitemtype,
473
            rules        => {
471
            rules        => {
474
                reservesallowed  => 99,
472
                reservesallowed  => 99,
475
                holds_per_record => 99,
473
                holds_per_record => 99,
Lines 491-497 subtest 'Test max_holds per library/patron category' => sub { Link Here
491
        {
489
        {
492
            categorycode => $category->{categorycode},
490
            categorycode => $category->{categorycode},
493
            branchcode   => undef,
491
            branchcode   => undef,
494
            itemtype     => undef,
495
            rule_name    => 'max_holds',
492
            rule_name    => 'max_holds',
496
            rule_value   => 3,
493
            rule_value   => 3,
497
        }
494
        }
Lines 501-507 subtest 'Test max_holds per library/patron category' => sub { Link Here
501
        {
498
        {
502
            branchcode   => $branch_1,
499
            branchcode   => $branch_1,
503
            categorycode => $category->{categorycode},
500
            categorycode => $category->{categorycode},
504
            itemtype     => undef,
505
            rule_name    => 'max_holds',
501
            rule_name    => 'max_holds',
506
            rule_value   => 5,
502
            rule_value   => 5,
507
        }
503
        }
(-)a/t/db_dependent/Holds/DisallowHoldIfItemsAvailable.t (-2 / +2 lines)
Lines 84-92 my $item2 = $builder->build_sample_item({ Link Here
84
$dbh->do("DELETE FROM circulation_rules");
84
$dbh->do("DELETE FROM circulation_rules");
85
Koha::CirculationRules->set_rules(
85
Koha::CirculationRules->set_rules(
86
    {
86
    {
87
        categorycode => '*',
87
        categorycode => undef,
88
        itemtype     => $itemtype,
88
        itemtype     => $itemtype,
89
        branchcode   => '*',
89
        branchcode   => undef,
90
        rules        => {
90
        rules        => {
91
            issuelength     => 7,
91
            issuelength     => 7,
92
            lengthunit      => 8,
92
            lengthunit      => 8,
(-)a/t/db_dependent/Holds/HoldFulfillmentPolicy.t (-3 lines)
Lines 75-81 my $itemnumber = Link Here
75
$dbh->do("DELETE FROM circulation_rules");
75
$dbh->do("DELETE FROM circulation_rules");
76
Koha::CirculationRules->set_rules(
76
Koha::CirculationRules->set_rules(
77
    {
77
    {
78
        categorycode => undef,
79
        branchcode   => undef,
78
        branchcode   => undef,
80
        itemtype     => undef,
79
        itemtype     => undef,
81
        rules        => {
80
        rules        => {
Lines 107-113 Koha::Holds->find( $reserve_id )->cancel; Link Here
107
$dbh->do("DELETE FROM circulation_rules");
106
$dbh->do("DELETE FROM circulation_rules");
108
Koha::CirculationRules->set_rules(
107
Koha::CirculationRules->set_rules(
109
    {
108
    {
110
        categorycode => undef,
111
        branchcode   => undef,
109
        branchcode   => undef,
112
        itemtype     => undef,
110
        itemtype     => undef,
113
        rules        => {
111
        rules        => {
Lines 139-145 Koha::Holds->find( $reserve_id )->cancel; Link Here
139
$dbh->do("DELETE FROM circulation_rules");
137
$dbh->do("DELETE FROM circulation_rules");
140
Koha::CirculationRules->set_rules(
138
Koha::CirculationRules->set_rules(
141
    {
139
    {
142
        categorycode => undef,
143
        branchcode   => undef,
140
        branchcode   => undef,
144
        itemtype     => undef,
141
        itemtype     => undef,
145
        rules        => {
142
        rules        => {
(-)a/t/db_dependent/Holds/HoldItemtypeLimit.t (-1 lines)
Lines 90-96 $dbh->do("DELETE FROM circulation_rules"); Link Here
90
Koha::CirculationRules->set_rules(
90
Koha::CirculationRules->set_rules(
91
    {
91
    {
92
        itemtype     => undef,
92
        itemtype     => undef,
93
        categorycode => undef,
94
        branchcode   => undef,
93
        branchcode   => undef,
95
        rules        => {
94
        rules        => {
96
            holdallowed             => 2,
95
            holdallowed             => 2,
(-)a/t/db_dependent/HoldsQueue.t (-8 lines)
Lines 296-302 Koha::CirculationRules->set_rule( Link Here
296
        rule_name    => 'holdallowed',
296
        rule_name    => 'holdallowed',
297
        rule_value   => 1,
297
        rule_value   => 1,
298
        branchcode   => undef,
298
        branchcode   => undef,
299
        categorycode => undef,
300
        itemtype     => undef,
299
        itemtype     => undef,
301
    }
300
    }
302
);
301
);
Lines 334-340 Koha::CirculationRules->set_rule( Link Here
334
        rule_name    => 'holdallowed',
333
        rule_name    => 'holdallowed',
335
        rule_value   => 2,
334
        rule_value   => 2,
336
        branchcode   => undef,
335
        branchcode   => undef,
337
        categorycode => undef,
338
        itemtype     => undef,
336
        itemtype     => undef,
339
    }
337
    }
340
);
338
);
Lines 362-368 Koha::CirculationRules->set_rule( Link Here
362
        rule_name    => 'holdallowed',
360
        rule_name    => 'holdallowed',
363
        rule_value   => 2,
361
        rule_value   => 2,
364
        branchcode   => undef,
362
        branchcode   => undef,
365
        categorycode => undef,
366
        itemtype     => undef,
363
        itemtype     => undef,
367
    }
364
    }
368
);
365
);
Lines 525-531 Koha::CirculationRules->set_rules( Link Here
525
    {
522
    {
526
        branchcode   => $library_A,
523
        branchcode   => $library_A,
527
        itemtype     => $itemtype,
524
        itemtype     => $itemtype,
528
        categorycode => undef,
529
        rules        => {
525
        rules        => {
530
            holdallowed  => 2,
526
            holdallowed  => 2,
531
            returnbranch => 'homebranch',
527
            returnbranch => 'homebranch',
Lines 624-630 Koha::CirculationRules->set_rules( Link Here
624
    {
620
    {
625
        branchcode   => undef,
621
        branchcode   => undef,
626
        itemtype     => undef,
622
        itemtype     => undef,
627
        categorycode => undef,
628
        rules        => {
623
        rules        => {
629
            holdallowed             => 2,
624
            holdallowed             => 2,
630
            hold_fulfillment_policy => 'homebranch',
625
            hold_fulfillment_policy => 'homebranch',
Lines 659-665 Koha::CirculationRules->set_rules( Link Here
659
    {
654
    {
660
        branchcode   => undef,
655
        branchcode   => undef,
661
        itemtype     => undef,
656
        itemtype     => undef,
662
        categorycode => undef,
663
        rules        => {
657
        rules        => {
664
            holdallowed             => 2,
658
            holdallowed             => 2,
665
            hold_fulfillment_policy => 'holdingbranch',
659
            hold_fulfillment_policy => 'holdingbranch',
Lines 694-700 Koha::CirculationRules->set_rules( Link Here
694
    {
688
    {
695
        branchcode   => undef,
689
        branchcode   => undef,
696
        itemtype     => undef,
690
        itemtype     => undef,
697
        categorycode => undef,
698
        rules        => {
691
        rules        => {
699
            holdallowed             => 2,
692
            holdallowed             => 2,
700
            hold_fulfillment_policy => 'any',
693
            hold_fulfillment_policy => 'any',
Lines 762-768 Koha::CirculationRules->set_rules( Link Here
762
    {
755
    {
763
        branchcode   => undef,
756
        branchcode   => undef,
764
        itemtype     => undef,
757
        itemtype     => undef,
765
        categorycode => undef,
766
        rules        => {
758
        rules        => {
767
            holdallowed             => 2,
759
            holdallowed             => 2,
768
            hold_fulfillment_policy => 'any',
760
            hold_fulfillment_policy => 'any',
(-)a/t/db_dependent/Koha/IssuingRules.t (-116 / +247 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 4;
22
use Test::More tests => 3;
23
use Test::Deep qw( cmp_methods );
24
use Test::Exception;
23
25
24
use Benchmark;
26
use Benchmark;
25
27
Lines 36-50 my $builder = t::lib::TestBuilder->new; Link Here
36
subtest 'get_effective_issuing_rule' => sub {
38
subtest 'get_effective_issuing_rule' => sub {
37
    plan tests => 3;
39
    plan tests => 3;
38
40
39
    my $patron       = $builder->build({ source => 'Borrower' });
41
    my $categorycode = $builder->build({ source => 'Category' })->{'categorycode'};
40
    my $item     = $builder->build({ source => 'Item' });
42
    my $itemtype     = $builder->build({ source => 'Itemtype' })->{'itemtype'};
41
43
    my $branchcode   = $builder->build({ source => 'Branch' })->{'branchcode'};
42
    my $categorycode = $patron->{'categorycode'};
43
    my $itemtype     = $item->{'itype'};
44
    my $branchcode   = $item->{'homebranch'};
45
44
46
    subtest 'Call with undefined values' => sub {
45
    subtest 'Call with undefined values' => sub {
47
        plan tests => 4;
46
        plan tests => 5;
48
47
49
        my $rule;
48
        my $rule;
50
        Koha::CirculationRules->delete;
49
        Koha::CirculationRules->delete;
Lines 59-83 subtest 'get_effective_issuing_rule' => sub { Link Here
59
        is($rule, undef, 'When I attempt to get effective issuing rule by'
58
        is($rule, undef, 'When I attempt to get effective issuing rule by'
60
           .' providing undefined values, then undef is returned.');
59
           .' providing undefined values, then undef is returned.');
61
        ok(Koha::CirculationRule->new({
60
        ok(Koha::CirculationRule->new({
62
            branchcode => '*',
61
            branchcode => undef,
63
            categorycode => '*',
62
            categorycode => undef,
64
            itemtype => '*',
63
            itemtype => undef,
65
            rule_name => 'fine',
64
            rule_name => 'fine',
66
        })->store, 'Given I added an issuing rule branchcode => *,'
65
        })->store, 'Given I added an issuing rule branchcode => undef,'
67
           .' categorycode => *, itemtype => *,');
66
           .' categorycode => undef, itemtype => undef,');
68
        $rule = Koha::CirculationRules->get_effective_rule({
67
        $rule = Koha::CirculationRules->get_effective_rule({
69
            branchcode   => '*',
68
            branchcode   => undef,
70
            categorycode => '*',
69
            categorycode => undef,
71
            itemtype     => '*',
70
            itemtype     => undef,
72
            rule_name    => 'fine',
71
            rule_name    => 'fine',
73
        });
72
        });
74
        ok(_row_match($rule, '*', '*', '*'), 'When I attempt to get effective'
73
        _is_row_match(
74
            $rule,
75
            {
76
                branchcode => undef,
77
                categorycode => undef,
78
                itemtype => undef
79
            },
80
            'When I attempt to get effective'
75
           .' issuing rule by providing undefined values, then the above one is'
81
           .' issuing rule by providing undefined values, then the above one is'
76
           .' returned.');
82
           .' returned.'
83
        );
77
    };
84
    };
78
85
79
    subtest 'Get effective issuing rule in correct order' => sub {
86
    subtest 'Get effective issuing rule in correct order' => sub {
80
        plan tests => 18;
87
        plan tests => 26;
81
88
82
        my $rule;
89
        my $rule;
83
        Koha::CirculationRules->delete;
90
        Koha::CirculationRules->delete;
Lines 92-200 subtest 'get_effective_issuing_rule' => sub { Link Here
92
                        .' is returned.');
99
                        .' is returned.');
93
100
94
        ok(Koha::CirculationRule->new({
101
        ok(Koha::CirculationRule->new({
95
            branchcode => '*',
102
            branchcode => undef,
96
            categorycode => '*',
103
            categorycode => undef,
97
            itemtype => '*',
104
            itemtype => undef,
98
            rule_name => 'fine',
105
            rule_name => 'fine',
99
        })->store, 'Given I added an issuing rule branchcode => *, categorycode => *, itemtype => *,');
106
        })->store, 'Given I added an issuing rule branchcode => undef, categorycode => undef, itemtype => undef,');
100
        $rule = Koha::CirculationRules->get_effective_rule({
107
        $rule = Koha::CirculationRules->get_effective_rule({
101
            branchcode   => $branchcode,
108
            branchcode   => $branchcode,
102
            categorycode => $categorycode,
109
            categorycode => $categorycode,
103
            itemtype     => $itemtype,
110
            itemtype     => $itemtype,
104
            rule_name    => 'fine',
111
            rule_name    => 'fine',
105
        });
112
        });
106
        ok(_row_match($rule, '*', '*', '*'), 'When I attempt to get effective issuing rule,'
113
        _is_row_match(
107
           .' then the above one is returned.');
114
            $rule,
115
            {
116
                branchcode => undef,
117
                categorycode => undef,
118
                itemtype => undef
119
            },
120
            'When I attempt to get effective issuing rule,'
121
           .' then the above one is returned.'
122
        );
108
123
109
        ok(Koha::CirculationRule->new({
124
        ok(Koha::CirculationRule->new({
110
            branchcode => '*',
125
            branchcode => undef,
111
            categorycode => '*',
126
            categorycode => undef,
112
            itemtype => $itemtype,
127
            itemtype => $itemtype,
113
            rule_name => 'fine',
128
            rule_name => 'fine',
114
        })->store, "Given I added an issuing rule branchcode => *, categorycode => *, itemtype => $itemtype,");
129
        })->store, "Given I added an issuing rule branchcode => undef, categorycode => undef, itemtype => $itemtype,");
115
        $rule = Koha::CirculationRules->get_effective_rule({
130
        $rule = Koha::CirculationRules->get_effective_rule({
116
            branchcode   => $branchcode,
131
            branchcode   => $branchcode,
117
            categorycode => $categorycode,
132
            categorycode => $categorycode,
118
            itemtype     => $itemtype,
133
            itemtype     => $itemtype,
119
            rule_name    => 'fine',
134
            rule_name    => 'fine',
120
        });
135
        });
121
        ok(_row_match($rule, '*', '*', $itemtype), 'When I attempt to get effective issuing rule,'
136
        _is_row_match(
122
           .' then the above one is returned.');
137
            $rule,
138
            {
139
                branchcode => undef,
140
                categorycode => undef,
141
                itemtype => $itemtype
142
            },
143
            'When I attempt to get effective issuing rule,'
144
           .' then the above one is returned.'
145
        );
123
146
124
        ok(Koha::CirculationRule->new({
147
        ok(Koha::CirculationRule->new({
125
            branchcode => '*',
148
            branchcode => undef,
126
            categorycode => $categorycode,
149
            categorycode => $categorycode,
127
            itemtype => '*',
150
            itemtype => undef,
128
            rule_name => 'fine',
151
            rule_name => 'fine',
129
        })->store, "Given I added an issuing rule branchcode => *, categorycode => $categorycode, itemtype => *,");
152
        })->store, "Given I added an issuing rule branchcode => undef, categorycode => $categorycode, itemtype => undef,");
130
        $rule = Koha::CirculationRules->get_effective_rule({
153
        $rule = Koha::CirculationRules->get_effective_rule({
131
            branchcode   => $branchcode,
154
            branchcode   => $branchcode,
132
            categorycode => $categorycode,
155
            categorycode => $categorycode,
133
            itemtype     => $itemtype,
156
            itemtype     => $itemtype,
134
            rule_name    => 'fine',
157
            rule_name    => 'fine',
135
        });
158
        });
136
        ok(_row_match($rule, '*', $categorycode, '*'), 'When I attempt to get effective issuing rule,'
159
        _is_row_match(
137
           .' then the above one is returned.');
160
            $rule,
161
            {
162
                branchcode => undef,
163
                categorycode => $categorycode,
164
                itemtype => undef
165
            },
166
            'When I attempt to get effective issuing rule,'
167
           .' then the above one is returned.'
168
        );
138
169
139
        ok(Koha::CirculationRule->new({
170
        ok(Koha::CirculationRule->new({
140
            branchcode => '*',
171
            branchcode => undef,
141
            categorycode => $categorycode,
172
            categorycode => $categorycode,
142
            itemtype => $itemtype,
173
            itemtype => $itemtype,
143
            rule_name => 'fine',
174
            rule_name => 'fine',
144
        })->store, "Given I added an issuing rule branchcode => *, categorycode => $categorycode, itemtype => $itemtype,");
175
        })->store, "Given I added an issuing rule branchcode => undef, categorycode => $categorycode, itemtype => $itemtype,");
145
        $rule = Koha::CirculationRules->get_effective_rule({
176
        $rule = Koha::CirculationRules->get_effective_rule({
146
            branchcode   => $branchcode,
177
            branchcode   => $branchcode,
147
            categorycode => $categorycode,
178
            categorycode => $categorycode,
148
            itemtype     => $itemtype,
179
            itemtype     => $itemtype,
149
            rule_name    => 'fine',
180
            rule_name    => 'fine',
150
        });
181
        });
151
        ok(_row_match($rule, '*', $categorycode, $itemtype), 'When I attempt to get effective issuing rule,'
182
        _is_row_match(
152
           .' then the above one is returned.');
183
            $rule,
184
            {
185
                branchcode => undef,
186
                categorycode => $categorycode,
187
                itemtype => $itemtype
188
            },
189
            'When I attempt to get effective issuing rule,'
190
           .' then the above one is returned.'
191
        );
153
192
154
        ok(Koha::CirculationRule->new({
193
        ok(Koha::CirculationRule->new({
155
            branchcode => $branchcode,
194
            branchcode => $branchcode,
156
            categorycode => '*',
195
            categorycode => undef,
157
            itemtype => '*',
196
            itemtype => undef,
158
            rule_name => 'fine',
197
            rule_name => 'fine',
159
        })->store, "Given I added an issuing rule branchcode => $branchcode, categorycode => '*', itemtype => '*',");
198
        })->store, "Given I added an issuing rule branchcode => $branchcode, categorycode => undef, itemtype => undef,");
160
        $rule = Koha::CirculationRules->get_effective_rule({
199
        $rule = Koha::CirculationRules->get_effective_rule({
161
            branchcode   => $branchcode,
200
            branchcode   => $branchcode,
162
            categorycode => $categorycode,
201
            categorycode => $categorycode,
163
            itemtype     => $itemtype,
202
            itemtype     => $itemtype,
164
            rule_name    => 'fine',
203
            rule_name    => 'fine',
165
        });
204
        });
166
        ok(_row_match($rule, $branchcode, '*', '*'), 'When I attempt to get effective issuing rule,'
205
        _is_row_match(
167
           .' then the above one is returned.');
206
            $rule,
207
            {
208
                branchcode => $branchcode,
209
                categorycode => undef,
210
                itemtype => undef
211
            },
212
            'When I attempt to get effective issuing rule,'
213
           .' then the above one is returned.'
214
        );
168
215
169
        ok(Koha::CirculationRule->new({
216
        ok(Koha::CirculationRule->new({
170
            branchcode => $branchcode,
217
            branchcode => $branchcode,
171
            categorycode => '*',
218
            categorycode => undef,
172
            itemtype => $itemtype,
219
            itemtype => $itemtype,
173
            rule_name => 'fine',
220
            rule_name => 'fine',
174
        })->store, "Given I added an issuing rule branchcode => $branchcode, categorycode => '*', itemtype => $itemtype,");
221
        })->store, "Given I added an issuing rule branchcode => $branchcode, categorycode => undef, itemtype => $itemtype,");
175
        $rule = Koha::CirculationRules->get_effective_rule({
222
        $rule = Koha::CirculationRules->get_effective_rule({
176
            branchcode   => $branchcode,
223
            branchcode   => $branchcode,
177
            categorycode => $categorycode,
224
            categorycode => $categorycode,
178
            itemtype     => $itemtype,
225
            itemtype     => $itemtype,
179
            rule_name    => 'fine',
226
            rule_name    => 'fine',
180
        });
227
        });
181
        ok(_row_match($rule, $branchcode, '*', $itemtype), 'When I attempt to get effective issuing rule,'
228
        _is_row_match(
182
           .' then the above one is returned.');
229
            $rule,
230
            {
231
                branchcode => $branchcode,
232
                categorycode => undef,
233
                itemtype => $itemtype
234
            },
235
            'When I attempt to get effective issuing rule,'
236
           .' then the above one is returned.'
237
        );
183
238
184
        ok(Koha::CirculationRule->new({
239
        ok(Koha::CirculationRule->new({
185
            branchcode => $branchcode,
240
            branchcode => $branchcode,
186
            categorycode => $categorycode,
241
            categorycode => $categorycode,
187
            itemtype => '*',
242
            itemtype => undef,
188
            rule_name => 'fine',
243
            rule_name => 'fine',
189
        })->store, "Given I added an issuing rule branchcode => $branchcode, categorycode => $categorycode, itemtype => '*',");
244
        })->store, "Given I added an issuing rule branchcode => $branchcode, categorycode => $categorycode, itemtype => undef,");
190
        $rule = Koha::CirculationRules->get_effective_rule({
245
        $rule = Koha::CirculationRules->get_effective_rule({
191
            branchcode   => $branchcode,
246
            branchcode   => $branchcode,
192
            categorycode => $categorycode,
247
            categorycode => $categorycode,
193
            itemtype     => $itemtype,
248
            itemtype     => $itemtype,
194
            rule_name    => 'fine',
249
            rule_name    => 'fine',
195
        });
250
        });
196
        ok(_row_match($rule, $branchcode, $categorycode, '*'), 'When I attempt to get effective issuing rule,'
251
        _is_row_match(
197
           .' then the above one is returned.');
252
            $rule,
253
            {
254
                branchcode => $branchcode,
255
                categorycode => $categorycode,
256
                itemtype => undef
257
            },
258
            'When I attempt to get effective issuing rule,'
259
           .' then the above one is returned.'
260
        );
198
261
199
        ok(Koha::CirculationRule->new({
262
        ok(Koha::CirculationRule->new({
200
            branchcode => $branchcode,
263
            branchcode => $branchcode,
Lines 208-215 subtest 'get_effective_issuing_rule' => sub { Link Here
208
            itemtype     => $itemtype,
271
            itemtype     => $itemtype,
209
            rule_name    => 'fine',
272
            rule_name    => 'fine',
210
        });
273
        });
211
        ok(_row_match($rule, $branchcode, $categorycode, $itemtype), 'When I attempt to get effective issuing rule,'
274
        _is_row_match(
212
           .' then the above one is returned.');
275
            $rule,
276
            {
277
                branchcode => $branchcode,
278
                categorycode => $categorycode,
279
                itemtype => $itemtype
280
            },
281
            'When I attempt to get effective issuing rule,'
282
           .' then the above one is returned.'
283
        );
213
    };
284
    };
214
285
215
    subtest 'Performance' => sub {
286
    subtest 'Performance' => sub {
Lines 266-333 subtest 'get_effective_issuing_rule' => sub { Link Here
266
    };
337
    };
267
};
338
};
268
339
269
subtest 'get_opacitemholds_policy' => sub {
340
subtest 'set_rule' => sub {
270
    plan tests => 4;
271
    my $itype = $builder->build_object({ class => 'Koha::ItemTypes' });
272
    my $itemtype = $builder->build_object({ class => 'Koha::ItemTypes' });
273
    my $library = $builder->build_object({ class => 'Koha::Libraries' });
274
    my $patron = $builder->build_object({ class => 'Koha::Patrons' });
275
    my $biblio = $builder->build_object({ class => 'Koha::Biblios' });
276
    my $biblioitem = $builder->build_object( { class => 'Koha::Biblioitems', value => { itemtype => $itemtype->itemtype, biblionumber => $biblio->biblionumber } } );
277
    my $item = $builder->build_object(
278
        {   class  => 'Koha::Items',
279
            value  => {
280
                homebranch    => $library->branchcode,
281
                holdingbranch => $library->branchcode,
282
                notforloan    => 0,
283
                itemlost      => 0,
284
                withdrawn     => 0,
285
                biblionumber  => $biblio->biblionumber,
286
                biblioitemnumber => $biblioitem->biblioitemnumber,
287
                itype         => $itype->itemtype,
288
            }
289
        }
290
    );
291
292
    Koha::IssuingRules->delete;
293
    Koha::IssuingRule->new({categorycode => '*', itemtype => '*',                 branchcode => '*', opacitemholds => "N"})->store;
294
    Koha::IssuingRule->new({categorycode => '*', itemtype => $itype->itemtype,    branchcode => '*', opacitemholds => "Y"})->store;
295
    Koha::IssuingRule->new({categorycode => '*', itemtype => $itemtype->itemtype, branchcode => '*', opacitemholds => "N"})->store;
296
    t::lib::Mocks::mock_preference('item-level_itypes', 1);
297
    my $opacitemholds = Koha::IssuingRules->get_opacitemholds_policy( { item => $item, patron => $patron } );
298
    is ( $opacitemholds, 'Y', 'Patrons can place a hold on this itype');
299
    t::lib::Mocks::mock_preference('item-level_itypes', 0);
300
    $opacitemholds = Koha::IssuingRules->get_opacitemholds_policy( { item => $item, patron => $patron } );
301
    is ( $opacitemholds, 'N', 'Patrons cannot place a hold on this itemtype');
302
303
    Koha::IssuingRules->delete;
304
    Koha::IssuingRule->new({categorycode => '*', itemtype => '*',                 branchcode => '*', opacitemholds => "N"})->store;
305
    Koha::IssuingRule->new({categorycode => '*', itemtype => $itype->itemtype,    branchcode => '*', opacitemholds => "N"})->store;
306
    Koha::IssuingRule->new({categorycode => '*', itemtype => $itemtype->itemtype, branchcode => '*', opacitemholds => "Y"})->store;
307
    t::lib::Mocks::mock_preference('item-level_itypes', 1);
308
    $opacitemholds = Koha::IssuingRules->get_opacitemholds_policy( { item => $item, patron => $patron } );
309
    is ( $opacitemholds, 'N', 'Patrons cannot place a hold on this itype');
310
    t::lib::Mocks::mock_preference('item-level_itypes', 0);
311
    $opacitemholds = Koha::IssuingRules->get_opacitemholds_policy( { item => $item, patron => $patron } );
312
    is ( $opacitemholds, 'Y', 'Patrons can place a hold on this itemtype');
313
314
    $patron->delete;
315
};
316
317
subtest 'get_onshelfholds_policy' => sub {
318
    plan tests => 3;
341
    plan tests => 3;
319
342
320
    t::lib::Mocks::mock_preference('item-level_itypes', 1);
343
    my $branchcode   = $builder->build({ source => 'Branch' })->{'branchcode'};
321
    Koha::IssuingRules->delete;
344
    my $categorycode = $builder->build({ source => 'Category' })->{'categorycode'};
345
    my $itemtype     = $builder->build({ source => 'Itemtype' })->{'itemtype'};
322
346
323
    my $patron = $builder->build_object({ class => 'Koha::Patrons' });
347
    subtest 'Correct call' => sub {
324
    my $item = $builder->build_object({ class => 'Koha::Items' });
348
        plan tests => 4;
325
349
326
    is( Koha::IssuingRules->get_onshelfholds_policy({ item => $item, patron => $patron }), undef, 'Should return undef when no rules can be found' );
350
        Koha::CirculationRules->delete;
327
    Koha::IssuingRule->new({ categorycode => $patron->categorycode, itemtype => $item->itype, branchcode => '*', onshelfholds => "0" })->store;
351
328
    is( Koha::IssuingRules->get_onshelfholds_policy({ item => $item, patron => $patron }), 0, 'Should be zero' );
352
        lives_ok( sub {
329
    Koha::IssuingRule->new({ categorycode => $patron->categorycode, itemtype => $item->itype, branchcode => $item->holdingbranch, onshelfholds => "2" })->store;
353
            Koha::CirculationRules->set_rule( {
330
    is( Koha::IssuingRules->get_onshelfholds_policy({ item => $item, patron => $patron }), 2, 'Should be two now' );
354
                branchcode => $branchcode,
355
                rule_name => 'refund',
356
                rule_value => '',
357
            } );
358
        }, 'setting refund with branch' );
359
360
        lives_ok( sub {
361
            Koha::CirculationRules->set_rule( {
362
                branchcode => $branchcode,
363
                categorycode => $categorycode,
364
                rule_name => 'patron_maxissueqty',
365
                rule_value => '',
366
            } );
367
        }, 'setting patron_maxissueqty with branch/category succeeds' );
368
369
        lives_ok( sub {
370
            Koha::CirculationRules->set_rule( {
371
                branchcode => $branchcode,
372
                itemtype => $itemtype,
373
                rule_name => 'holdallowed',
374
                rule_value => '',
375
            } );
376
        }, 'setting holdallowed with branch/itemtype succeeds' );
377
378
        lives_ok( sub {
379
            Koha::CirculationRules->set_rule( {
380
                branchcode => $branchcode,
381
                categorycode => $categorycode,
382
                itemtype => $itemtype,
383
                rule_name => 'fine',
384
                rule_value => '',
385
            } );
386
        }, 'setting fine with branch/category/itemtype succeeds' );
387
    };
388
389
    subtest 'Call with missing params' => sub {
390
        plan tests => 4;
391
392
        Koha::CirculationRules->delete;
393
394
        throws_ok( sub {
395
            Koha::CirculationRules->set_rule( {
396
                rule_name => 'refund',
397
                rule_value => '',
398
            } );
399
        }, qr/branchcode/, 'setting refund without branch fails' );
400
401
        throws_ok( sub {
402
            Koha::CirculationRules->set_rule( {
403
                branchcode => $branchcode,
404
                rule_name => 'patron_maxissueqty',
405
                rule_value => '',
406
            } );
407
        }, qr/categorycode/, 'setting patron_maxissueqty without categorycode fails' );
408
409
        throws_ok( sub {
410
            Koha::CirculationRules->set_rule( {
411
                branchcode => $branchcode,
412
                rule_name => 'holdallowed',
413
                rule_value => '',
414
            } );
415
        }, qr/itemtype/, 'setting holdallowed without itemtype fails' );
416
417
        throws_ok( sub {
418
            Koha::CirculationRules->set_rule( {
419
                branchcode => $branchcode,
420
                categorycode => $categorycode,
421
                rule_name => 'fine',
422
                rule_value => '',
423
            } );
424
        }, qr/itemtype/, 'setting fine without itemtype fails' );
425
    };
426
427
    subtest 'Call with extra params' => sub {
428
        plan tests => 3;
429
430
        Koha::CirculationRules->delete;
431
432
        throws_ok( sub {
433
            Koha::CirculationRules->set_rule( {
434
                branchcode => $branchcode,
435
                categorycode => $categorycode,
436
                rule_name => 'refund',
437
                rule_value => '',
438
            } );
439
        }, qr/categorycode/, 'setting refund with categorycode fails' );
440
441
        throws_ok( sub {
442
            Koha::CirculationRules->set_rule( {
443
                branchcode => $branchcode,
444
                categorycode => $categorycode,
445
                itemtype => $itemtype,
446
                rule_name => 'patron_maxissueqty',
447
                rule_value => '',
448
            } );
449
        }, qr/itemtype/, 'setting patron_maxissueqty with itemtype fails' );
450
451
        throws_ok( sub {
452
            Koha::CirculationRules->set_rule( {
453
                branchcode => $branchcode,
454
                rule_name => 'holdallowed',
455
                categorycode => $categorycode,
456
                itemtype => $itemtype,
457
                rule_value => '',
458
            } );
459
        }, qr/categorycode/, 'setting holdallowed with categorycode fails' );
460
    };
331
};
461
};
332
462
333
subtest 'delete' => sub {
463
subtest 'delete' => sub {
Lines 377-387 subtest 'delete' => sub { Link Here
377
507
378
};
508
};
379
509
380
sub _row_match {
510
sub _is_row_match {
381
    my ($rule, $branchcode, $categorycode, $itemtype) = @_;
511
    my ( $rule, $expected, $message ) = @_;
382
512
383
    return $rule->branchcode eq $branchcode && $rule->categorycode eq $categorycode
513
    ok( $rule, $message ) ?
384
            && $rule->itemtype eq $itemtype;
514
        cmp_methods( $rule, [ %$expected ], $message ) :
515
        fail( $message );
385
}
516
}
386
517
387
$schema->storage->txn_rollback;
518
$schema->storage->txn_rollback;
(-)a/t/db_dependent/RefundLostItemFeeRule.t (+14 lines)
Lines 54-63 subtest 'Koha::RefundLostItemFeeRule::delete() tests' => sub { Link Here
54
            }
54
            }
55
        }
55
        }
56
    );
56
    );
57
    my $branchcode = $builder->build( { source => 'Branch' } )->{branchcode};
57
    my $generated_other_rule = $builder->build(
58
    my $generated_other_rule = $builder->build(
58
        {
59
        {
59
            source => 'CirculationRule',
60
            source => 'CirculationRule',
60
            value  => {
61
            value  => {
62
                branchcode   => $branchcode,
61
                categorycode => undef,
63
                categorycode => undef,
62
                itemtype     => undef,
64
                itemtype     => undef,
63
                rule_name    => 'refund',
65
                rule_name    => 'refund',
Lines 117-126 subtest 'Koha::RefundLostItemFeeRules::_default_rule() tests' => sub { Link Here
117
            }
119
            }
118
        }
120
        }
119
    );
121
    );
122
    my $branchcode = $builder->build( { source => 'Branch' } )->{branchcode};
120
    my $generated_other_rule = $builder->build(
123
    my $generated_other_rule = $builder->build(
121
        {
124
        {
122
            source => 'CirculationRule',
125
            source => 'CirculationRule',
123
            value  => {
126
            value  => {
127
                branchcode   => $branchcode,
124
                categorycode => undef,
128
                categorycode => undef,
125
                itemtype     => undef,
129
                itemtype     => undef,
126
                rule_name    => 'refund',
130
                rule_name    => 'refund',
Lines 185-194 subtest 'Koha::RefundLostItemFeeRules::_effective_branch_rule() tests' => sub { Link Here
185
            }
189
            }
186
        }
190
        }
187
    );
191
    );
192
    my $branchcode = $builder->build( { source => 'Branch' } )->{branchcode};
188
    my $specific_rule_false = $builder->build(
193
    my $specific_rule_false = $builder->build(
189
        {
194
        {
190
            source => 'CirculationRule',
195
            source => 'CirculationRule',
191
            value  => {
196
            value  => {
197
                branchcode   => $branchcode,
192
                categorycode => undef,
198
                categorycode => undef,
193
                itemtype     => undef,
199
                itemtype     => undef,
194
                rule_name    => 'refund',
200
                rule_name    => 'refund',
Lines 196-205 subtest 'Koha::RefundLostItemFeeRules::_effective_branch_rule() tests' => sub { Link Here
196
            }
202
            }
197
        }
203
        }
198
    );
204
    );
205
    my $branchcode2 = $builder->build( { source => 'Branch' } )->{branchcode};
199
    my $specific_rule_true = $builder->build(
206
    my $specific_rule_true = $builder->build(
200
        {
207
        {
201
            source => 'CirculationRule',
208
            source => 'CirculationRule',
202
            value  => {
209
            value  => {
210
                branchcode   => $branchcode2,
203
                categorycode => undef,
211
                categorycode => undef,
204
                itemtype     => undef,
212
                itemtype     => undef,
205
                rule_name    => 'refund',
213
                rule_name    => 'refund',
Lines 301-310 subtest 'Koha::RefundLostItemFeeRules::should_refund() tests' => sub { Link Here
301
            }
309
            }
302
        }
310
        }
303
    );
311
    );
312
    my $branchcode = $builder->build( { source => 'Branch' } )->{branchcode};
304
    my $specific_rule_false = $builder->build(
313
    my $specific_rule_false = $builder->build(
305
        {
314
        {
306
            source => 'CirculationRule',
315
            source => 'CirculationRule',
307
            value  => {
316
            value  => {
317
                branchcode   => $branchcode,
308
                categorycode => undef,
318
                categorycode => undef,
309
                itemtype     => undef,
319
                itemtype     => undef,
310
                rule_name    => 'refund',
320
                rule_name    => 'refund',
Lines 312-321 subtest 'Koha::RefundLostItemFeeRules::should_refund() tests' => sub { Link Here
312
            }
322
            }
313
        }
323
        }
314
    );
324
    );
325
    my $branchcode2 = $builder->build( { source => 'Branch' } )->{branchcode};
315
    my $specific_rule_true = $builder->build(
326
    my $specific_rule_true = $builder->build(
316
        {
327
        {
317
            source => 'CirculationRule',
328
            source => 'CirculationRule',
318
            value  => {
329
            value  => {
330
                branchcode   => $branchcode2,
319
                categorycode => undef,
331
                categorycode => undef,
320
                itemtype     => undef,
332
                itemtype     => undef,
321
                rule_name    => 'refund',
333
                rule_name    => 'refund',
Lines 324-333 subtest 'Koha::RefundLostItemFeeRules::should_refund() tests' => sub { Link Here
324
        }
336
        }
325
    );
337
    );
326
    # Make sure we have an unused branchcode
338
    # Make sure we have an unused branchcode
339
    my $branchcode3 = $builder->build( { source => 'Branch' } )->{branchcode};
327
    my $specific_rule_dummy = $builder->build(
340
    my $specific_rule_dummy = $builder->build(
328
        {
341
        {
329
            source => 'CirculationRule',
342
            source => 'CirculationRule',
330
            value  => {
343
            value  => {
344
                branchcode   => $branchcode3,
331
                categorycode => undef,
345
                categorycode => undef,
332
                itemtype     => undef,
346
                itemtype     => undef,
333
                rule_name    => 'refund',
347
                rule_name    => 'refund',
(-)a/t/db_dependent/Reserves.t (-5 / +3 lines)
Lines 193-201 $requesters{$branch_3} = Koha::Patron->new({ Link Here
193
$dbh->do('DELETE FROM circulation_rules');
193
$dbh->do('DELETE FROM circulation_rules');
194
Koha::CirculationRules->set_rules(
194
Koha::CirculationRules->set_rules(
195
    {
195
    {
196
        branchcode   => '*',
196
        branchcode   => undef,
197
        categorycode => '*',
197
        categorycode => undef,
198
        itemtype     => '*',
198
        itemtype     => undef,
199
        rules        => {
199
        rules        => {
200
            reservesallowed => 25,
200
            reservesallowed => 25,
201
            holds_per_record => 1,
201
            holds_per_record => 1,
Lines 207-213 Koha::CirculationRules->set_rules( Link Here
207
Koha::CirculationRules->set_rules(
207
Koha::CirculationRules->set_rules(
208
    {
208
    {
209
        branchcode   => $branch_1,
209
        branchcode   => $branch_1,
210
        categorycode => undef,
211
        itemtype     => undef,
210
        itemtype     => undef,
212
        rules        => {
211
        rules        => {
213
            holdallowed  => 1,
212
            holdallowed  => 1,
Lines 220-226 Koha::CirculationRules->set_rules( Link Here
220
Koha::CirculationRules->set_rules(
219
Koha::CirculationRules->set_rules(
221
    {
220
    {
222
        branchcode   => $branch_2,
221
        branchcode   => $branch_2,
223
        categorycode => undef,
224
        itemtype     => undef,
222
        itemtype     => undef,
225
        rules        => {
223
        rules        => {
226
            holdallowed  => 2,
224
            holdallowed  => 2,
(-)a/t/db_dependent/Reserves/MultiplePerRecord.t (-17 / +17 lines)
Lines 120-128 Koha::CirculationRules->delete(); Link Here
120
# Test GetMaxPatronHoldsForRecord and GetHoldRule
120
# Test GetMaxPatronHoldsForRecord and GetHoldRule
121
Koha::CirculationRules->set_rules(
121
Koha::CirculationRules->set_rules(
122
    {
122
    {
123
        categorycode => '*',
123
        categorycode => undef,
124
        itemtype     => '*',
124
        itemtype     => undef,
125
        branchcode   => '*',
125
        branchcode   => undef,
126
        rules        => {
126
        rules        => {
127
            reservesallowed  => 1,
127
            reservesallowed  => 1,
128
            holds_per_record => 1,
128
            holds_per_record => 1,
Lines 139-155 my $rule = C4::Reserves::GetHoldRule( Link Here
139
    $itemtype1->{itemtype},
139
    $itemtype1->{itemtype},
140
    $library->{branchcode}
140
    $library->{branchcode}
141
);
141
);
142
is( $rule->{categorycode},     '*', 'Got rule with universal categorycode' );
142
is( $rule->{categorycode},     undef, 'Got rule with universal categorycode' );
143
is( $rule->{itemtype},         '*', 'Got rule with universal itemtype' );
143
is( $rule->{itemtype},         undef, 'Got rule with universal itemtype' );
144
is( $rule->{branchcode},       '*', 'Got rule with universal branchcode' );
144
is( $rule->{branchcode},       undef, 'Got rule with universal branchcode' );
145
is( $rule->{reservesallowed},  1,   'Got reservesallowed of 1' );
145
is( $rule->{reservesallowed},  1,   'Got reservesallowed of 1' );
146
is( $rule->{holds_per_record}, 1,   'Got holds_per_record of 1' );
146
is( $rule->{holds_per_record}, 1,   'Got holds_per_record of 1' );
147
147
148
Koha::CirculationRules->set_rules(
148
Koha::CirculationRules->set_rules(
149
    {
149
    {
150
        categorycode => $category->{categorycode},
150
        categorycode => $category->{categorycode},
151
        itemtype     => '*',
151
        itemtype     => undef,
152
        branchcode   => '*',
152
        branchcode   => undef,
153
        rules        => {
153
        rules        => {
154
            reservesallowed  => 2,
154
            reservesallowed  => 2,
155
            holds_per_record => 2,
155
            holds_per_record => 2,
Lines 165-172 $rule = C4::Reserves::GetHoldRule( Link Here
165
    $library->{branchcode}
165
    $library->{branchcode}
166
);
166
);
167
is( $rule->{categorycode},     $category->{categorycode}, 'Got rule with specific categorycode' );
167
is( $rule->{categorycode},     $category->{categorycode}, 'Got rule with specific categorycode' );
168
is( $rule->{itemtype},         '*',                       'Got rule with universal itemtype' );
168
is( $rule->{itemtype},         undef,                       'Got rule with universal itemtype' );
169
is( $rule->{branchcode},       '*',                       'Got rule with universal branchcode' );
169
is( $rule->{branchcode},       undef,                       'Got rule with universal branchcode' );
170
is( $rule->{reservesallowed},  2,                         'Got reservesallowed of 2' );
170
is( $rule->{reservesallowed},  2,                         'Got reservesallowed of 2' );
171
is( $rule->{holds_per_record}, 2,                         'Got holds_per_record of 2' );
171
is( $rule->{holds_per_record}, 2,                         'Got holds_per_record of 2' );
172
172
Lines 174-180 Koha::CirculationRules->set_rules( Link Here
174
    {
174
    {
175
        categorycode => $category->{categorycode},
175
        categorycode => $category->{categorycode},
176
        itemtype     => $itemtype1->{itemtype},
176
        itemtype     => $itemtype1->{itemtype},
177
        branchcode   => '*',
177
        branchcode   => undef,
178
        rules        => {
178
        rules        => {
179
            reservesallowed  => 3,
179
            reservesallowed  => 3,
180
            holds_per_record => 3,
180
            holds_per_record => 3,
Lines 191-197 $rule = C4::Reserves::GetHoldRule( Link Here
191
);
191
);
192
is( $rule->{categorycode},     $category->{categorycode}, 'Got rule with specific categorycode' );
192
is( $rule->{categorycode},     $category->{categorycode}, 'Got rule with specific categorycode' );
193
is( $rule->{itemtype},         $itemtype1->{itemtype},    'Got rule with universal itemtype' );
193
is( $rule->{itemtype},         $itemtype1->{itemtype},    'Got rule with universal itemtype' );
194
is( $rule->{branchcode},       '*',                       'Got rule with universal branchcode' );
194
is( $rule->{branchcode},       undef,                       'Got rule with universal branchcode' );
195
is( $rule->{reservesallowed},  3,                         'Got reservesallowed of 3' );
195
is( $rule->{reservesallowed},  3,                         'Got reservesallowed of 3' );
196
is( $rule->{holds_per_record}, 3,                         'Got holds_per_record of 3' );
196
is( $rule->{holds_per_record}, 3,                         'Got holds_per_record of 3' );
197
197
Lines 199-205 Koha::CirculationRules->set_rules( Link Here
199
    {
199
    {
200
        categorycode => $category->{categorycode},
200
        categorycode => $category->{categorycode},
201
        itemtype     => $itemtype2->{itemtype},
201
        itemtype     => $itemtype2->{itemtype},
202
        branchcode   => '*',
202
        branchcode   => undef,
203
        rules        => {
203
        rules        => {
204
            reservesallowed  => 4,
204
            reservesallowed  => 4,
205
            holds_per_record => 4,
205
            holds_per_record => 4,
Lines 216-222 $rule = C4::Reserves::GetHoldRule( Link Here
216
);
216
);
217
is( $rule->{categorycode},     $category->{categorycode}, 'Got rule with specific categorycode' );
217
is( $rule->{categorycode},     $category->{categorycode}, 'Got rule with specific categorycode' );
218
is( $rule->{itemtype},         $itemtype2->{itemtype},    'Got rule with universal itemtype' );
218
is( $rule->{itemtype},         $itemtype2->{itemtype},    'Got rule with universal itemtype' );
219
is( $rule->{branchcode},       '*',                       'Got rule with universal branchcode' );
219
is( $rule->{branchcode},       undef,                       'Got rule with universal branchcode' );
220
is( $rule->{reservesallowed},  4,                         'Got reservesallowed of 4' );
220
is( $rule->{reservesallowed},  4,                         'Got reservesallowed of 4' );
221
is( $rule->{holds_per_record}, 4,                         'Got holds_per_record of 4' );
221
is( $rule->{holds_per_record}, 4,                         'Got holds_per_record of 4' );
222
222
Lines 273-281 $hold->delete(); Link Here
273
# Test multi-hold via AddReserve
273
# Test multi-hold via AddReserve
274
Koha::CirculationRules->set_rules(
274
Koha::CirculationRules->set_rules(
275
    {
275
    {
276
        categorycode => '*',
276
        categorycode => undef,
277
        itemtype     => '*',
277
        itemtype     => undef,
278
        branchcode   => '*',
278
        branchcode   => undef,
279
        rules        => {
279
        rules        => {
280
            reservesallowed  => 2,
280
            reservesallowed  => 2,
281
            holds_per_record => 2,
281
            holds_per_record => 2,
(-)a/t/db_dependent/TestBuilder.t (+2 lines)
Lines 353-364 subtest 'build_object() tests' => sub { Link Here
353
353
354
    $builder = t::lib::TestBuilder->new();
354
    $builder = t::lib::TestBuilder->new();
355
355
356
    my $branchcode = $builder->build( { source => 'Branch' } )->{branchcode};
356
    my $categorycode = $builder->build( { source => 'Category' } )->{categorycode};
357
    my $categorycode = $builder->build( { source => 'Category' } )->{categorycode};
357
    my $itemtype = $builder->build( { source => 'Itemtype' } )->{itemtype};
358
    my $itemtype = $builder->build( { source => 'Itemtype' } )->{itemtype};
358
359
359
    my $issuing_rule = $builder->build_object(
360
    my $issuing_rule = $builder->build_object(
360
        {   class => 'Koha::CirculationRules',
361
        {   class => 'Koha::CirculationRules',
361
            value => {
362
            value => {
363
                branchcode   => $branchcode,
362
                categorycode => $categorycode,
364
                categorycode => $categorycode,
363
                itemtype     => $itemtype
365
                itemtype     => $itemtype
364
            }
366
            }
(-)a/t/db_dependent/api/v1/holds.t (-4 / +3 lines)
Lines 117-125 $dbh->do('DELETE FROM reserves'); Link Here
117
Koha::CirculationRules->search()->delete();
117
Koha::CirculationRules->search()->delete();
118
Koha::CirculationRules->set_rules(
118
Koha::CirculationRules->set_rules(
119
    {
119
    {
120
        categorycode => '*',
120
        categorycode => undef,
121
        branchcode   => '*',
121
        branchcode   => undef,
122
        itemtype     => '*',
122
        itemtype     => undef,
123
        rules        => {
123
        rules        => {
124
            reservesallowed => 1,
124
            reservesallowed => 1,
125
            holds_per_record => 99
125
            holds_per_record => 99
126
- 

Return to bug 18936