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

(-)a/C4/Circulation.pm (-16 / +16 lines)
Lines 425-431 sub TooMany { Link Here
425
        |;
425
        |;
426
426
427
        my $rule_itemtype = $maxissueqty_rule->itemtype;
427
        my $rule_itemtype = $maxissueqty_rule->itemtype;
428
        if ($rule_itemtype eq "*") {
428
        if (!defined $rule_itemtype) {
429
            # matching rule has the default item type, so count only
429
            # matching rule has the default item type, so count only
430
            # those existing loans that don't fall under a more
430
            # those existing loans that don't fall under a more
431
            # specific rule
431
            # specific rule
Lines 434-440 sub TooMany { Link Here
434
                                    SELECT itemtype FROM circulation_rules
434
                                    SELECT itemtype FROM circulation_rules
435
                                    WHERE branchcode = ?
435
                                    WHERE branchcode = ?
436
                                    AND   (categorycode = ? OR categorycode = ?)
436
                                    AND   (categorycode = ? OR categorycode = ?)
437
                                    AND   itemtype <> '*'
437
                                    AND   itemtype IS NOT NULL
438
                                    AND   rule_name = 'maxissueqty'
438
                                    AND   rule_name = 'maxissueqty'
439
                                  ) ";
439
                                  ) ";
440
            } else { 
440
            } else { 
Lines 443-449 sub TooMany { Link Here
443
                                    SELECT itemtype FROM circulation_rules
443
                                    SELECT itemtype FROM circulation_rules
444
                                    WHERE branchcode = ?
444
                                    WHERE branchcode = ?
445
                                    AND   (categorycode = ? OR categorycode = ?)
445
                                    AND   (categorycode = ? OR categorycode = ?)
446
                                    AND   itemtype <> '*'
446
                                    AND   itemtype IS NOT NULL
447
                                    AND   rule_name = 'maxissueqty'
447
                                    AND   rule_name = 'maxissueqty'
448
                                  ) ";
448
                                  ) ";
449
            }
449
            }
Lines 465-471 sub TooMany { Link Here
465
        $count_query .= " AND borrowernumber = ? ";
465
        $count_query .= " AND borrowernumber = ? ";
466
        push @bind_params, $borrower->{'borrowernumber'};
466
        push @bind_params, $borrower->{'borrowernumber'};
467
        my $rule_branch = $maxissueqty_rule->branchcode;
467
        my $rule_branch = $maxissueqty_rule->branchcode;
468
        if ($rule_branch ne "*") {
468
        if (defined $rule_branch) {
469
            if (C4::Context->preference('CircControl') eq 'PickupLibrary') {
469
            if (C4::Context->preference('CircControl') eq 'PickupLibrary') {
470
                $count_query .= " AND issues.branchcode = ? ";
470
                $count_query .= " AND issues.branchcode = ? ";
471
                push @bind_params, $branch;
471
                push @bind_params, $branch;
Lines 1499-1536 sub GetLoanLength { Link Here
1499
        },
1499
        },
1500
        {
1500
        {
1501
            categorycode => $categorycode,
1501
            categorycode => $categorycode,
1502
            itemtype     => '*',
1502
            itemtype     => undef,
1503
            branchcode   => $branchcode,
1503
            branchcode   => $branchcode,
1504
        },
1504
        },
1505
        {
1505
        {
1506
            categorycode => '*',
1506
            categorycode => undef,
1507
            itemtype     => $itemtype,
1507
            itemtype     => $itemtype,
1508
            branchcode   => $branchcode,
1508
            branchcode   => $branchcode,
1509
        },
1509
        },
1510
        {
1510
        {
1511
            categorycode => '*',
1511
            categorycode => undef,
1512
            itemtype     => '*',
1512
            itemtype     => undef,
1513
            branchcode   => $branchcode,
1513
            branchcode   => $branchcode,
1514
        },
1514
        },
1515
        {
1515
        {
1516
            categorycode => $categorycode,
1516
            categorycode => $categorycode,
1517
            itemtype     => $itemtype,
1517
            itemtype     => $itemtype,
1518
            branchcode   => '*',
1518
            branchcode   => undef,
1519
        },
1519
        },
1520
        {
1520
        {
1521
            categorycode => $categorycode,
1521
            categorycode => $categorycode,
1522
            itemtype     => '*',
1522
            itemtype     => undef,
1523
            branchcode   => '*',
1523
            branchcode   => undef,
1524
        },
1524
        },
1525
        {
1525
        {
1526
            categorycode => '*',
1526
            categorycode => undef,
1527
            itemtype     => $itemtype,
1527
            itemtype     => $itemtype,
1528
            branchcode   => '*',
1528
            branchcode   => undef,
1529
        },
1529
        },
1530
        {
1530
        {
1531
            categorycode => '*',
1531
            categorycode => undef,
1532
            itemtype     => '*',
1532
            itemtype     => undef,
1533
            branchcode   => '*',
1533
            branchcode   => undef,
1534
        },
1534
        },
1535
    );
1535
    );
1536
1536
(-)a/C4/Reserves.pm (-30 / +16 lines)
Lines 355-361 sub CanItemBeReserved { Link Here
355
        $holds_per_record = $rights->{holds_per_record};
355
        $holds_per_record = $rights->{holds_per_record};
356
    }
356
    }
357
    else {
357
    else {
358
        $ruleitemtype = '*';
358
        $ruleitemtype = undef;
359
    }
359
    }
360
360
361
    $item = Koha::Items->find( $itemnumber );
361
    $item = Koha::Items->find( $itemnumber );
Lines 380-394 sub CanItemBeReserved { Link Here
380
      C4::Context->preference('item-level_itypes')
380
      C4::Context->preference('item-level_itypes')
381
      ? " AND COALESCE( items.itype, biblioitems.itemtype ) = ?"
381
      ? " AND COALESCE( items.itype, biblioitems.itemtype ) = ?"
382
      : " AND biblioitems.itemtype = ?"
382
      : " AND biblioitems.itemtype = ?"
383
      if ( $ruleitemtype ne "*" );
383
      if defined $ruleitemtype;
384
384
385
    my $sthcount = $dbh->prepare($querycount);
385
    my $sthcount = $dbh->prepare($querycount);
386
386
387
    if ( $ruleitemtype eq "*" ) {
387
    if ( defined $ruleitemtype ) {
388
        $sthcount->execute( $borrowernumber, $branchcode );
388
        $sthcount->execute( $borrowernumber, $branchcode, $ruleitemtype );
389
    }
389
    }
390
    else {
390
    else {
391
        $sthcount->execute( $borrowernumber, $branchcode, $ruleitemtype );
391
        $sthcount->execute( $borrowernumber, $branchcode );
392
    }
392
    }
393
393
394
    my $reservecount = "0";
394
    my $reservecount = "0";
Lines 402-420 sub CanItemBeReserved { Link Here
402
    }
402
    }
403
403
404
    # Now we need to check hold limits by patron category
404
    # Now we need to check hold limits by patron category
405
    my $rule = Koha::CirculationRules->find(
405
    my $rule = Koha::CirculationRules->get_effective_rule(
406
        {
406
        {
407
            categorycode => $borrower->{categorycode},
408
            branchcode   => $borrower->{branchcode},
407
            branchcode   => $borrower->{branchcode},
409
            itemtype     => undef,
410
            rule_name    => 'max_holds',
411
        }
412
    );
413
    $rule ||= Koha::CirculationRules->find(
414
        {
415
            categorycode => $borrower->{categorycode},
408
            categorycode => $borrower->{categorycode},
416
            branchcode   => undef,,
417
            itemtype     => undef,
418
            rule_name    => 'max_holds',
409
            rule_name    => 'max_holds',
419
        }
410
        }
420
    );
411
    );
Lines 1819-1839 sub OPACItemHoldsAllowed { Link Here
1819
       }
1810
       }
1820
    }
1811
    }
1821
1812
1822
    my $query = "SELECT opacitemholds,categorycode,itemtype,branchcode FROM issuingrules WHERE
1813
    my $data = Koha::CirculationRules->get_effective_rule( {
1823
          (issuingrules.categorycode = ? OR issuingrules.categorycode = '*')
1814
        branchcode => $branchcode,
1824
        AND
1815
        categorycode => $borrower->{categorycode},
1825
          (issuingrules.itemtype = ? OR issuingrules.itemtype = '*')
1816
        itemtype => $itype,
1826
        AND
1817
        rule_name    => 'opacitemholds',
1827
          (issuingrules.branchcode = ? OR issuingrules.branchcode = '*')
1818
        order_by     => {
1828
        ORDER BY
1819
            -desc => [ 'categorycode', 'itemtype', 'branchcode' ]
1829
          issuingrules.categorycode desc,
1820
        }
1830
          issuingrules.itemtype desc,
1821
    } );
1831
          issuingrules.branchcode desc
1822
    my $opacitemholds = $data ? uc substr ($data->{rule_value}, 0, 1) : '';
1832
       LIMIT 1";
1833
    my $sth = $dbh->prepare($query);
1834
    $sth->execute($borrower->{categorycode},$itype,$branchcode);
1835
    my $data = $sth->fetchrow_hashref;
1836
    my $opacitemholds = uc substr ($data->{opacitemholds}, 0, 1);
1837
    return '' if $opacitemholds eq 'N';
1823
    return '' if $opacitemholds eq 'N';
1838
    return $opacitemholds;
1824
    return $opacitemholds;
1839
}
1825
}
(-)a/Koha/CirculationRules.pm (-20 / +150 lines)
Lines 35-40 Koha::CirculationRules - Koha CirculationRule Object set class Link Here
35
35
36
=cut
36
=cut
37
37
38
=head3 rule_kinds
39
40
This structure describes the possible rules that may be set, and what scopes they can be set at.
41
42
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.
43
44
=cut
45
46
our $RULE_KINDS = {
47
    refund => {
48
        scope => [ 'branchcode' ],
49
    },
50
51
    patron_maxissueqty => {
52
        scope => [ 'branchcode', 'categorycode' ],
53
    },
54
    patron_maxonsiteissueqty => {
55
        scope => [ 'branchcode', 'categorycode' ],
56
    },
57
    max_holds => {
58
        scope => [ 'branchcode', 'categorycode' ],
59
    },
60
61
    holdallowed => {
62
        scope => [ 'branchcode', 'itemtype' ],
63
    },
64
    hold_fulfillment_policy => {
65
        scope => [ 'branchcode', 'itemtype' ],
66
    },
67
    returnbranch => {
68
        scope => [ 'branchcode', 'itemtype' ],
69
    },
70
71
    article_requests => {
72
        scope => [ 'branchcode', 'categorycode', 'itemtype' ],
73
    },
74
    auto_renew => {
75
        scope => [ 'branchcode', 'categorycode', 'itemtype' ],
76
    },
77
    cap_fine_to_replacement_price => {
78
        scope => [ 'branchcode', 'categorycode', 'itemtype' ],
79
    },
80
    chargeperiod => {
81
        scope => [ 'branchcode', 'categorycode', 'itemtype' ],
82
    },
83
    chargeperiod_charge_at => {
84
        scope => [ 'branchcode', 'categorycode', 'itemtype' ],
85
    },
86
    fine => {
87
        scope => [ 'branchcode', 'categorycode', 'itemtype' ],
88
    },
89
    finedays => {
90
        scope => [ 'branchcode', 'categorycode', 'itemtype' ],
91
    },
92
    firstremind => {
93
        scope => [ 'branchcode', 'categorycode', 'itemtype' ],
94
    },
95
    hardduedate => {
96
        scope => [ 'branchcode', 'categorycode', 'itemtype' ],
97
    },
98
    hardduedatecompare => {
99
        scope => [ 'branchcode', 'categorycode', 'itemtype' ],
100
    },
101
    holds_per_record => {
102
        scope => [ 'branchcode', 'categorycode', 'itemtype' ],
103
    },
104
    issuelength => {
105
        scope => [ 'branchcode', 'categorycode', 'itemtype' ],
106
    },
107
    lengthunit => {
108
        scope => [ 'branchcode', 'categorycode', 'itemtype' ],
109
    },
110
    maxissueqty => {
111
        scope => [ 'branchcode', 'categorycode', 'itemtype' ],
112
    },
113
    maxonsiteissueqty => {
114
        scope => [ 'branchcode', 'categorycode', 'itemtype' ],
115
    },
116
    maxsuspensiondays => {
117
        scope => [ 'branchcode', 'categorycode', 'itemtype' ],
118
    },
119
    no_auto_renewal_after => {
120
        scope => [ 'branchcode', 'categorycode', 'itemtype' ],
121
    },
122
    no_auto_renewal_after_hard_limit => {
123
        scope => [ 'branchcode', 'categorycode', 'itemtype' ],
124
    },
125
    norenewalbefore => {
126
        scope => [ 'branchcode', 'categorycode', 'itemtype' ],
127
    },
128
    onshelfholds => {
129
        scope => [ 'branchcode', 'categorycode', 'itemtype' ],
130
    },
131
    opacitemholds => {
132
        scope => [ 'branchcode', 'categorycode', 'itemtype' ],
133
    },
134
    overduefinescap => {
135
        scope => [ 'branchcode', 'categorycode', 'itemtype' ],
136
    },
137
    renewalperiod => {
138
        scope => [ 'branchcode', 'categorycode', 'itemtype' ],
139
    },
140
    renewalsallowed => {
141
        scope => [ 'branchcode', 'categorycode', 'itemtype' ],
142
    },
143
    rentaldiscount => {
144
        scope => [ 'branchcode', 'categorycode', 'itemtype' ],
145
    },
146
    reservesallowed => {
147
        scope => [ 'branchcode', 'categorycode', 'itemtype' ],
148
    },
149
    # Not included (deprecated?):
150
    #   * accountsent
151
    #   * chargename
152
    #   * reservecharge
153
    #   * restrictedtype
154
};
155
156
sub rule_kinds {
157
    return $RULE_KINDS;
158
}
159
38
=head3 get_effective_rule
160
=head3 get_effective_rule
39
161
40
=cut
162
=cut
Lines 42-50 Koha::CirculationRules - Koha CirculationRule Object set class Link Here
42
sub get_effective_rule {
164
sub get_effective_rule {
43
    my ( $self, $params ) = @_;
165
    my ( $self, $params ) = @_;
44
166
45
    $params->{categorycode} = '*' if exists($params->{categorycode}) && !defined($params->{categorycode});
167
    $params->{categorycode} //= undef;
46
    $params->{branchcode}   = '*' if exists($params->{branchcode})   && !defined($params->{branchcode});
168
    $params->{branchcode}   //= undef;
47
    $params->{itemtype}     = '*' if exists($params->{itemtype})     && !defined($params->{itemtype});
169
    $params->{itemtype}     //= undef;
48
170
49
    my $rule_name    = $params->{rule_name};
171
    my $rule_name    = $params->{rule_name};
50
    my $categorycode = $params->{categorycode};
172
    my $categorycode = $params->{categorycode};
Lines 59-67 sub get_effective_rule { Link Here
59
    my $search_params;
181
    my $search_params;
60
    $search_params->{rule_name} = $rule_name;
182
    $search_params->{rule_name} = $rule_name;
61
183
62
    $search_params->{categorycode} = defined $categorycode ? { 'in' => [ $categorycode, '*' ] } : undef;
184
    $search_params->{categorycode} = defined $categorycode ? [ $categorycode, undef ] : undef;
63
    $search_params->{itemtype}     = defined $itemtype     ? { 'in' => [ $itemtype,     '*' ] } : undef;
185
    $search_params->{itemtype}     = defined $itemtype     ? [ $itemtype,     undef ] : undef;
64
    $search_params->{branchcode}   = defined $branchcode   ? { 'in' => [ $branchcode,   '*' ] } : undef;
186
    $search_params->{branchcode}   = defined $branchcode   ? [ $branchcode,   undef ] : undef;
65
187
66
    my $rule = $self->search(
188
    my $rule = $self->search(
67
        $search_params,
189
        $search_params,
Lines 110-125 sub get_effective_rules { Link Here
110
sub set_rule {
232
sub set_rule {
111
    my ( $self, $params ) = @_;
233
    my ( $self, $params ) = @_;
112
234
113
    croak q{set_rule requires the parameter 'branchcode'!}
114
      unless exists $params->{branchcode};
115
    croak q{set_rule requires the parameter 'categorycode'!}
116
      unless exists $params->{categorycode};
117
    croak q{set_rule requires the parameter 'itemtype'!}
118
      unless exists $params->{itemtype};
119
    croak q{set_rule requires the parameter 'rule_name'!}
235
    croak q{set_rule requires the parameter 'rule_name'!}
120
      unless exists $params->{rule_name};
236
        unless exists $params->{rule_name};
121
    croak q{set_rule requires the parameter 'rule_value'!}
237
    croak q{set_rule requires the parameter 'rule_value'!}
122
      unless exists $params->{rule_value};
238
        unless exists $params->{rule_value};
239
240
    my $kind_info = $RULE_KINDS->{ $params->{rule_name} };
241
    croak "set_rule given unknown rule '$params->{rule_name}'!"
242
        unless defined $kind_info;
243
244
    # Enforce scope; a rule should be set for its defined scope, no more, no less.
245
    foreach my $scope_level ( qw( branchcode categorycode itemtype ) ) {
246
        if ( grep /$scope_level/, @{ $kind_info->{scope} } ) {
247
            croak "set_rule needs '$scope_level' to set '$params->{rule_name}'!"
248
                unless exists $params->{$scope_level};
249
        } else {
250
            croak "set_rule cannot set '$params->{rule_name}' for a '$scope_level'!"
251
                if exists $params->{$scope_level};
252
        }
253
    }
123
254
124
    my $branchcode   = $params->{branchcode};
255
    my $branchcode   = $params->{branchcode};
125
    my $categorycode = $params->{categorycode};
256
    my $categorycode = $params->{categorycode};
Lines 170-187 sub set_rule { Link Here
170
sub set_rules {
301
sub set_rules {
171
    my ( $self, $params ) = @_;
302
    my ( $self, $params ) = @_;
172
303
173
    my $branchcode   = $params->{branchcode};
304
    my %set_params;
174
    my $categorycode = $params->{categorycode};
305
    $set_params{branchcode} = $params->{branchcode} if exists $params->{branchcode};
175
    my $itemtype     = $params->{itemtype};
306
    $set_params{categorycode} = $params->{categorycode} if exists $params->{categorycode};
307
    $set_params{itemtype} = $params->{itemtype} if exists $params->{itemtype};
176
    my $rules        = $params->{rules};
308
    my $rules        = $params->{rules};
177
309
178
    my $rule_objects = [];
310
    my $rule_objects = [];
179
    while ( my ( $rule_name, $rule_value ) = each %$rules ) {
311
    while ( my ( $rule_name, $rule_value ) = each %$rules ) {
180
        my $rule_object = Koha::CirculationRules->set_rule(
312
        my $rule_object = Koha::CirculationRules->set_rule(
181
            {
313
            {
182
                branchcode   => $branchcode,
314
                %set_params,
183
                categorycode => $categorycode,
184
                itemtype     => $itemtype,
185
                rule_name    => $rule_name,
315
                rule_name    => $rule_name,
186
                rule_value   => $rule_value,
316
                rule_value   => $rule_value,
187
            }
317
            }
(-)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/Koha/RefundLostItemFeeRules.pm (-1 / +1 lines)
Lines 148-154 sub _default_rule { Link Here
148
    my $self = shift;
148
    my $self = shift;
149
    my $default_rule = $self->search(
149
    my $default_rule = $self->search(
150
        {
150
        {
151
            branchcode   => '*',
151
            branchcode   => undef,
152
            categorycode => undef,
152
            categorycode => undef,
153
            itemtype     => undef,
153
            itemtype     => undef,
154
            rule_name    => 'refund',
154
            rule_name    => 'refund',
(-)a/Koha/Schema/Result/Branch.pm (-2 / +17 lines)
Lines 353-358 __PACKAGE__->has_many( Link Here
353
  { cascade_copy => 0, cascade_delete => 0 },
353
  { cascade_copy => 0, cascade_delete => 0 },
354
);
354
);
355
355
356
=head2 circulation_rules
357
358
Type: has_many
359
360
Related object: L<Koha::Schema::Result::CirculationRule>
361
362
=cut
363
364
__PACKAGE__->has_many(
365
  "circulation_rules",
366
  "Koha::Schema::Result::CirculationRule",
367
  { "foreign.branchcode" => "self.branchcode" },
368
  { cascade_copy => 0, cascade_delete => 0 },
369
);
370
356
=head2 club_enrollments
371
=head2 club_enrollments
357
372
358
Type: has_many
373
Type: has_many
Lines 589-596 Composing rels: L</branchrelations> -> categorycode Link Here
589
__PACKAGE__->many_to_many("categorycodes", "branchrelations", "categorycode");
604
__PACKAGE__->many_to_many("categorycodes", "branchrelations", "categorycode");
590
605
591
606
592
# Created by DBIx::Class::Schema::Loader v0.07042 @ 2017-07-03 15:35:15
607
# Created by DBIx::Class::Schema::Loader v0.07042 @ 2017-09-30 08:26:50
593
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:9z/UhS1n8kZ2OEvevR8KZg
608
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:SGWU+hnPENNNoIPRvxHWZw
594
609
595
610
596
# You can replace this text with custom code or comments, and it will be preserved on regeneration
611
# You can replace this text with custom code or comments, and it will be preserved on regeneration
(-)a/Koha/Schema/Result/Category.pm (-2 / +17 lines)
Lines 236-244 __PACKAGE__->has_many( Link Here
236
  { cascade_copy => 0, cascade_delete => 0 },
236
  { cascade_copy => 0, cascade_delete => 0 },
237
);
237
);
238
238
239
=head2 circulation_rules
239
240
240
# Created by DBIx::Class::Schema::Loader v0.07042 @ 2017-07-03 15:35:15
241
Type: has_many
241
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:Nyb7RzCc6y0W0izWTjksoA
242
243
Related object: L<Koha::Schema::Result::CirculationRule>
244
245
=cut
246
247
__PACKAGE__->has_many(
248
  "circulation_rules",
249
  "Koha::Schema::Result::CirculationRule",
250
  { "foreign.categorycode" => "self.categorycode" },
251
  { cascade_copy => 0, cascade_delete => 0 },
252
);
253
254
255
# Created by DBIx::Class::Schema::Loader v0.07042 @ 2017-09-30 08:26:50
256
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:fJF/fj7sCECysHEB3pDgyg
242
257
243
258
244
# You can replace this text with custom content, and it will be preserved on regeneration
259
# You can replace this text with custom content, and it will be preserved on regeneration
(-)a/Koha/Schema/Result/CirculationRule.pm (-6 / +76 lines)
Lines 32-49 __PACKAGE__->table("circulation_rules"); Link Here
32
=head2 branchcode
32
=head2 branchcode
33
33
34
  data_type: 'varchar'
34
  data_type: 'varchar'
35
  is_foreign_key: 1
35
  is_nullable: 1
36
  is_nullable: 1
36
  size: 10
37
  size: 10
37
38
38
=head2 categorycode
39
=head2 categorycode
39
40
40
  data_type: 'varchar'
41
  data_type: 'varchar'
42
  is_foreign_key: 1
41
  is_nullable: 1
43
  is_nullable: 1
42
  size: 10
44
  size: 10
43
45
44
=head2 itemtype
46
=head2 itemtype
45
47
46
  data_type: 'varchar'
48
  data_type: 'varchar'
49
  is_foreign_key: 1
47
  is_nullable: 1
50
  is_nullable: 1
48
  size: 10
51
  size: 10
49
52
Lines 65-75 __PACKAGE__->add_columns( Link Here
65
  "id",
68
  "id",
66
  { data_type => "integer", is_auto_increment => 1, is_nullable => 0 },
69
  { data_type => "integer", is_auto_increment => 1, is_nullable => 0 },
67
  "branchcode",
70
  "branchcode",
68
  { data_type => "varchar", is_nullable => 1, size => 10 },
71
  { data_type => "varchar", is_foreign_key => 1, is_nullable => 1, size => 10 },
69
  "categorycode",
72
  "categorycode",
70
  { data_type => "varchar", is_nullable => 1, size => 10 },
73
  { data_type => "varchar", is_foreign_key => 1, is_nullable => 1, size => 10 },
71
  "itemtype",
74
  "itemtype",
72
  { data_type => "varchar", is_nullable => 1, size => 10 },
75
  { data_type => "varchar", is_foreign_key => 1, is_nullable => 1, size => 10 },
73
  "rule_name",
76
  "rule_name",
74
  { data_type => "varchar", is_nullable => 0, size => 32 },
77
  { data_type => "varchar", is_nullable => 0, size => 32 },
75
  "rule_value",
78
  "rule_value",
Lines 100-114 __PACKAGE__->set_primary_key("id"); Link Here
100
103
101
=item * L</itemtype>
104
=item * L</itemtype>
102
105
106
=item * L</rule_name>
107
103
=back
108
=back
104
109
105
=cut
110
=cut
106
111
107
__PACKAGE__->add_unique_constraint("branchcode_2", ["branchcode", "categorycode", "itemtype"]);
112
__PACKAGE__->add_unique_constraint(
113
  "branchcode_2",
114
  ["branchcode", "categorycode", "itemtype", "rule_name"],
115
);
116
117
=head1 RELATIONS
118
119
=head2 branchcode
120
121
Type: belongs_to
122
123
Related object: L<Koha::Schema::Result::Branch>
124
125
=cut
126
127
__PACKAGE__->belongs_to(
128
  "branchcode",
129
  "Koha::Schema::Result::Branch",
130
  { branchcode => "branchcode" },
131
  {
132
    is_deferrable => 1,
133
    join_type     => "LEFT",
134
    on_delete     => "CASCADE",
135
    on_update     => "CASCADE",
136
  },
137
);
138
139
=head2 categorycode
140
141
Type: belongs_to
142
143
Related object: L<Koha::Schema::Result::Category>
144
145
=cut
146
147
__PACKAGE__->belongs_to(
148
  "categorycode",
149
  "Koha::Schema::Result::Category",
150
  { categorycode => "categorycode" },
151
  {
152
    is_deferrable => 1,
153
    join_type     => "LEFT",
154
    on_delete     => "CASCADE",
155
    on_update     => "CASCADE",
156
  },
157
);
158
159
=head2 itemtype
160
161
Type: belongs_to
162
163
Related object: L<Koha::Schema::Result::Itemtype>
164
165
=cut
166
167
__PACKAGE__->belongs_to(
168
  "itemtype",
169
  "Koha::Schema::Result::Itemtype",
170
  { itemtype => "itemtype" },
171
  {
172
    is_deferrable => 1,
173
    join_type     => "LEFT",
174
    on_delete     => "CASCADE",
175
    on_update     => "CASCADE",
176
  },
177
);
108
178
109
179
110
# Created by DBIx::Class::Schema::Loader v0.07042 @ 2017-07-03 15:35:15
180
# Created by DBIx::Class::Schema::Loader v0.07042 @ 2017-09-30 08:26:50
111
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:ok1AzADM8/wcfU9xS7LgNQ
181
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:sK9+Iwm8emAhqv9ETdCQAg
112
182
113
183
114
# You can replace this text with custom code or comments, and it will be preserved on regeneration
184
# You can replace this text with custom code or comments, and it will be preserved on regeneration
(-)a/Koha/Schema/Result/Itemtype.pm (-2 / +17 lines)
Lines 149-154 __PACKAGE__->has_many( Link Here
149
  { cascade_copy => 0, cascade_delete => 0 },
149
  { cascade_copy => 0, cascade_delete => 0 },
150
);
150
);
151
151
152
=head2 circulation_rules
153
154
Type: has_many
155
156
Related object: L<Koha::Schema::Result::CirculationRule>
157
158
=cut
159
160
__PACKAGE__->has_many(
161
  "circulation_rules",
162
  "Koha::Schema::Result::CirculationRule",
163
  { "foreign.itemtype" => "self.itemtype" },
164
  { cascade_copy => 0, cascade_delete => 0 },
165
);
166
152
=head2 default_branch_item_rule
167
=head2 default_branch_item_rule
153
168
154
Type: might_have
169
Type: might_have
Lines 195-202 __PACKAGE__->has_many( Link Here
195
);
210
);
196
211
197
212
198
# Created by DBIx::Class::Schema::Loader v0.07042 @ 2017-07-03 15:35:15
213
# Created by DBIx::Class::Schema::Loader v0.07042 @ 2017-09-30 08:26:50
199
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:tXTiZk4HKLEBWm/tBXJ9Dw
214
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:D1B+jh+5hkb5U3OOQoepXA
200
215
201
# Use the ItemtypeLocalization view to create the join on localization
216
# Use the ItemtypeLocalization view to create the join on localization
202
our $LANGUAGE;
217
our $LANGUAGE;
(-)a/admin/smart-rules.pl (-47 / +49 lines)
Lines 70-78 if ($op eq 'delete') { Link Here
70
70
71
    Koha::CirculationRules->set_rules(
71
    Koha::CirculationRules->set_rules(
72
        {
72
        {
73
            categorycode => $categorycode,
73
            categorycode => $categorycode eq '*' ? undef : $categorycode,
74
            branchcode   => $branch,
74
            branchcode   => $branch eq '*' ? undef : $branch,
75
            itemtype     => $itemtype,
75
            itemtype     => $itemtype eq '*' ? undef : $itemtype,
76
            rules        => {
76
            rules        => {
77
                restrictedtype                   => undef,
77
                restrictedtype                   => undef,
78
                rentaldiscount                   => undef,
78
                rentaldiscount                   => undef,
Lines 110-121 elsif ($op eq 'delete-branch-cat') { Link Here
110
        if ($categorycode eq "*") {
110
        if ($categorycode eq "*") {
111
            Koha::CirculationRules->set_rules(
111
            Koha::CirculationRules->set_rules(
112
                {
112
                {
113
                    categorycode => undef,
114
                    branchcode   => undef,
113
                    branchcode   => undef,
115
                    itemtype     => undef,
114
                    categorycode => undef,
116
                    rules        => {
115
                    rules        => {
117
                        patron_maxissueqty             => undef,
116
                        patron_maxissueqty             => undef,
118
                        patron_maxonsiteissueqty       => undef,
117
                        patron_maxonsiteissueqty       => undef,
118
                    }
119
                }
120
            );
121
            Koha::CirculationRules->set_rules(
122
                {
123
                    branchcode   => undef,
124
                    itemtype     => undef,
125
                    rules        => {
119
                        holdallowed             => undef,
126
                        holdallowed             => undef,
120
                        hold_fulfillment_policy => undef,
127
                        hold_fulfillment_policy => undef,
121
                        returnbranch            => undef,
128
                        returnbranch            => undef,
Lines 127-133 elsif ($op eq 'delete-branch-cat') { Link Here
127
                {
134
                {
128
                    categorycode => $categorycode,
135
                    categorycode => $categorycode,
129
                    branchcode   => undef,
136
                    branchcode   => undef,
130
                    itemtype     => undef,
131
                    rules        => {
137
                    rules        => {
132
                        max_holds         => undef,
138
                        max_holds         => undef,
133
                        patron_maxissueqty       => undef,
139
                        patron_maxissueqty       => undef,
Lines 139-150 elsif ($op eq 'delete-branch-cat') { Link Here
139
    } elsif ($categorycode eq "*") {
145
    } elsif ($categorycode eq "*") {
140
        Koha::CirculationRules->set_rules(
146
        Koha::CirculationRules->set_rules(
141
            {
147
            {
148
                branchcode   => $branch,
142
                categorycode => undef,
149
                categorycode => undef,
150
                rules        => {
151
                    patron_maxissueqty       => undef,
152
                    patron_maxonsiteissueqty => undef,
153
                }
154
            }
155
        );
156
        Koha::CirculationRules->set_rules(
157
            {
143
                branchcode   => $branch,
158
                branchcode   => $branch,
144
                itemtype     => undef,
145
                rules        => {
159
                rules        => {
146
                    patron_maxissueqty             => undef,
147
                    patron_maxonsiteissueqty       => undef,
148
                    holdallowed             => undef,
160
                    holdallowed             => undef,
149
                    hold_fulfillment_policy => undef,
161
                    hold_fulfillment_policy => undef,
150
                    returnbranch            => undef,
162
                    returnbranch            => undef,
Lines 156-162 elsif ($op eq 'delete-branch-cat') { Link Here
156
            {
168
            {
157
                categorycode => $categorycode,
169
                categorycode => $categorycode,
158
                branchcode   => $branch,
170
                branchcode   => $branch,
159
                itemtype     => undef,
160
                rules        => {
171
                rules        => {
161
                    max_holds         => undef,
172
                    max_holds         => undef,
162
                    maxissueqty       => undef,
173
                    maxissueqty       => undef,
Lines 172-183 elsif ($op eq 'delete-branch-item') { Link Here
172
        if ($itemtype eq "*") {
183
        if ($itemtype eq "*") {
173
            Koha::CirculationRules->set_rules(
184
            Koha::CirculationRules->set_rules(
174
                {
185
                {
175
                    categorycode => undef,
176
                    branchcode   => undef,
186
                    branchcode   => undef,
177
                    itemtype     => undef,
187
                    itemtype     => undef,
178
                    rules        => {
188
                    rules        => {
179
                        patron_maxissueqty             => undef,
180
                        patron_maxonsiteissueqty       => undef,
181
                        holdallowed             => undef,
189
                        holdallowed             => undef,
182
                        hold_fulfillment_policy => undef,
190
                        hold_fulfillment_policy => undef,
183
                        returnbranch            => undef,
191
                        returnbranch            => undef,
Lines 187-193 elsif ($op eq 'delete-branch-item') { Link Here
187
        } else {
195
        } else {
188
            Koha::CirculationRules->set_rules(
196
            Koha::CirculationRules->set_rules(
189
                {
197
                {
190
                    categorycode => undef,
191
                    branchcode   => undef,
198
                    branchcode   => undef,
192
                    itemtype     => $itemtype,
199
                    itemtype     => $itemtype,
193
                    rules        => {
200
                    rules        => {
Lines 201-212 elsif ($op eq 'delete-branch-item') { Link Here
201
    } elsif ($itemtype eq "*") {
208
    } elsif ($itemtype eq "*") {
202
        Koha::CirculationRules->set_rules(
209
        Koha::CirculationRules->set_rules(
203
            {
210
            {
204
                categorycode => undef,
205
                branchcode   => $branch,
211
                branchcode   => $branch,
206
                itemtype     => undef,
212
                itemtype     => undef,
207
                rules        => {
213
                rules        => {
208
                    patron_maxissueqty             => undef,
209
                    patron_maxonsiteissueqty       => undef,
210
                    holdallowed             => undef,
214
                    holdallowed             => undef,
211
                    hold_fulfillment_policy => undef,
215
                    hold_fulfillment_policy => undef,
212
                    returnbranch            => undef,
216
                    returnbranch            => undef,
Lines 216-222 elsif ($op eq 'delete-branch-item') { Link Here
216
    } else {
220
    } else {
217
        Koha::CirculationRules->set_rules(
221
        Koha::CirculationRules->set_rules(
218
            {
222
            {
219
                categorycode => undef,
220
                branchcode   => $branch,
223
                branchcode   => $branch,
221
                itemtype     => $itemtype,
224
                itemtype     => $itemtype,
222
                rules        => {
225
                rules        => {
Lines 271-282 elsif ($op eq 'add') { Link Here
271
    my $article_requests = $input->param('article_requests') || 'no';
274
    my $article_requests = $input->param('article_requests') || 'no';
272
    my $overduefinescap = $input->param('overduefinescap') || undef;
275
    my $overduefinescap = $input->param('overduefinescap') || undef;
273
    my $cap_fine_to_replacement_price = $input->param('cap_fine_to_replacement_price') eq 'on';
276
    my $cap_fine_to_replacement_price = $input->param('cap_fine_to_replacement_price') eq 'on';
274
    $debug and warn "Adding $br, $bor, $itemtype, $fine, $maxissueqty, $maxonsiteissueqty, $cap_fine_to_replacement_price";
277
    warn "Adding $br, $bor, $itemtype, $fine, $maxissueqty, $maxonsiteissueqty, $cap_fine_to_replacement_price";
275
278
276
    my $params = {
279
    my $params = {
277
        branchcode                    => $br,
278
        categorycode                  => $bor,
279
        itemtype                      => $itemtype,
280
        fine                          => $fine,
280
        fine                          => $fine,
281
        finedays                      => $finedays,
281
        finedays                      => $finedays,
282
        maxsuspensiondays             => $maxsuspensiondays,
282
        maxsuspensiondays             => $maxsuspensiondays,
Lines 305-313 elsif ($op eq 'add') { Link Here
305
305
306
    Koha::CirculationRules->set_rules(
306
    Koha::CirculationRules->set_rules(
307
        {
307
        {
308
            categorycode => $bor,
308
            categorycode => $bor eq '*' ? undef : $bor,
309
            itemtype     => $itemtype,
309
            itemtype     => $itemtype eq '*' ? undef : $itemtype,
310
            branchcode   => $br,
310
            branchcode   => $br eq '*' ? undef : $br,
311
            rules        => {
311
            rules        => {
312
                maxissueqty       => $maxissueqty,
312
                maxissueqty       => $maxissueqty,
313
                maxonsiteissueqty => $maxonsiteissueqty,
313
                maxonsiteissueqty => $maxonsiteissueqty,
Lines 337-369 elsif ($op eq "set-branch-defaults") { Link Here
337
    if ($branch eq "*") {
337
    if ($branch eq "*") {
338
        Koha::CirculationRules->set_rules(
338
        Koha::CirculationRules->set_rules(
339
            {
339
            {
340
                categorycode => undef,
341
                itemtype     => undef,
340
                itemtype     => undef,
342
                branchcode   => undef,
341
                branchcode   => undef,
343
                rules        => {
342
                rules        => {
344
                    patron_maxissueqty             => $patron_maxissueqty,
345
                    patron_maxonsiteissueqty       => $patron_maxonsiteissueqty,
346
                    holdallowed             => $holdallowed,
343
                    holdallowed             => $holdallowed,
347
                    hold_fulfillment_policy => $hold_fulfillment_policy,
344
                    hold_fulfillment_policy => $hold_fulfillment_policy,
348
                    returnbranch            => $returnbranch,
345
                    returnbranch            => $returnbranch,
349
                }
346
                }
350
            }
347
            }
351
        );
348
        );
352
    } else {
353
        Koha::CirculationRules->set_rules(
349
        Koha::CirculationRules->set_rules(
354
            {
350
            {
355
                categorycode => undef,
351
                categorycode => undef,
356
                itemtype     => undef,
352
                branchcode   => undef,
357
                branchcode   => $branch,
358
                rules        => {
353
                rules        => {
359
                    patron_maxissueqty             => $patron_maxissueqty,
354
                    patron_maxissueqty             => $patron_maxissueqty,
360
                    patron_maxonsiteissueqty       => $patron_maxonsiteissueqty,
355
                    patron_maxonsiteissueqty       => $patron_maxonsiteissueqty,
356
                }
357
            }
358
        );
359
    } else {
360
        Koha::CirculationRules->set_rules(
361
            {
362
                itemtype     => undef,
363
                branchcode   => $branch,
364
                rules        => {
361
                    holdallowed             => $holdallowed,
365
                    holdallowed             => $holdallowed,
362
                    hold_fulfillment_policy => $hold_fulfillment_policy,
366
                    hold_fulfillment_policy => $hold_fulfillment_policy,
363
                    returnbranch            => $returnbranch,
367
                    returnbranch            => $returnbranch,
364
                }
368
                }
365
            }
369
            }
366
        );
370
        );
371
        Koha::CirculationRules->set_rules(
372
            {
373
                categorycode => undef,
374
                branchcode   => $branch,
375
                rules        => {
376
                    patron_maxissueqty             => $patron_maxissueqty,
377
                    patron_maxonsiteissueqty       => $patron_maxonsiteissueqty,
378
                }
379
            }
380
        );
367
    }
381
    }
368
    Koha::CirculationRules->set_rule(
382
    Koha::CirculationRules->set_rule(
369
        {
383
        {
Lines 392-398 elsif ($op eq "add-branch-cat") { Link Here
392
            Koha::CirculationRules->set_rules(
406
            Koha::CirculationRules->set_rules(
393
                {
407
                {
394
                    categorycode => undef,
408
                    categorycode => undef,
395
                    itemtype     => undef,
396
                    branchcode   => undef,
409
                    branchcode   => undef,
397
                    rules        => {
410
                    rules        => {
398
                        max_holds         => $max_holds,
411
                        max_holds         => $max_holds,
Lines 404-412 elsif ($op eq "add-branch-cat") { Link Here
404
        } else {
417
        } else {
405
            Koha::CirculationRules->set_rules(
418
            Koha::CirculationRules->set_rules(
406
                {
419
                {
407
                    branchcode   => '*',
408
                    categorycode => $categorycode,
420
                    categorycode => $categorycode,
409
                    itemtype     => undef,
421
                    branchcode   => undef,
410
                    rules        => {
422
                    rules        => {
411
                        max_holds         => $max_holds,
423
                        max_holds         => $max_holds,
412
                        patron_maxissueqty       => $patron_maxissueqty,
424
                        patron_maxissueqty       => $patron_maxissueqty,
Lines 419-425 elsif ($op eq "add-branch-cat") { Link Here
419
        Koha::CirculationRules->set_rules(
431
        Koha::CirculationRules->set_rules(
420
            {
432
            {
421
                categorycode => undef,
433
                categorycode => undef,
422
                itemtype     => undef,
423
                branchcode   => $branch,
434
                branchcode   => $branch,
424
                rules        => {
435
                rules        => {
425
                    max_holds         => $max_holds,
436
                    max_holds         => $max_holds,
Lines 432-438 elsif ($op eq "add-branch-cat") { Link Here
432
        Koha::CirculationRules->set_rules(
443
        Koha::CirculationRules->set_rules(
433
            {
444
            {
434
                categorycode => $categorycode,
445
                categorycode => $categorycode,
435
                itemtype     => undef,
436
                branchcode   => $branch,
446
                branchcode   => $branch,
437
                rules        => {
447
                rules        => {
438
                    max_holds         => $max_holds,
448
                    max_holds         => $max_holds,
Lines 456-462 elsif ($op eq "add-branch-item") { Link Here
456
        if ($itemtype eq "*") {
466
        if ($itemtype eq "*") {
457
            Koha::CirculationRules->set_rules(
467
            Koha::CirculationRules->set_rules(
458
                {
468
                {
459
                    categorycode => undef,
460
                    itemtype     => undef,
469
                    itemtype     => undef,
461
                    branchcode   => undef,
470
                    branchcode   => undef,
462
                    rules        => {
471
                    rules        => {
Lines 469-475 elsif ($op eq "add-branch-item") { Link Here
469
        } else {
478
        } else {
470
            Koha::CirculationRules->set_rules(
479
            Koha::CirculationRules->set_rules(
471
                {
480
                {
472
                    categorycode => undef,
473
                    itemtype     => $itemtype,
481
                    itemtype     => $itemtype,
474
                    branchcode   => undef,
482
                    branchcode   => undef,
475
                    rules        => {
483
                    rules        => {
Lines 483-489 elsif ($op eq "add-branch-item") { Link Here
483
    } elsif ($itemtype eq "*") {
491
    } elsif ($itemtype eq "*") {
484
            Koha::CirculationRules->set_rules(
492
            Koha::CirculationRules->set_rules(
485
                {
493
                {
486
                    categorycode => undef,
487
                    itemtype     => undef,
494
                    itemtype     => undef,
488
                    branchcode   => $branch,
495
                    branchcode   => $branch,
489
                    rules        => {
496
                    rules        => {
Lines 496-502 elsif ($op eq "add-branch-item") { Link Here
496
    } else {
503
    } else {
497
        Koha::CirculationRules->set_rules(
504
        Koha::CirculationRules->set_rules(
498
            {
505
            {
499
                categorycode => undef,
500
                itemtype     => $itemtype,
506
                itemtype     => $itemtype,
501
                branchcode   => $branch,
507
                branchcode   => $branch,
502
                rules        => {
508
                rules        => {
Lines 517-524 elsif ( $op eq 'mod-refund-lost-item-fee-rule' ) { Link Here
517
            # only do something for $refund eq '*' if branch-specific
523
            # only do something for $refund eq '*' if branch-specific
518
            Koha::CirculationRules->set_rules(
524
            Koha::CirculationRules->set_rules(
519
                {
525
                {
520
                    categorycode => undef,
521
                    itemtype     => undef,
522
                    branchcode   => $branch,
526
                    branchcode   => $branch,
523
                    rules        => {
527
                    rules        => {
524
                        refund => undef
528
                        refund => undef
Lines 529-537 elsif ( $op eq 'mod-refund-lost-item-fee-rule' ) { Link Here
529
    } else {
533
    } else {
530
        Koha::CirculationRules->set_rules(
534
        Koha::CirculationRules->set_rules(
531
            {
535
            {
532
                categorycode => undef,
536
                branchcode   => undef,
533
                itemtype     => undef,
534
                branchcode   => $branch,
535
                rules        => {
537
                rules        => {
536
                    refund => $refund
538
                    refund => $refund
537
                }
539
                }
Lines 540-546 elsif ( $op eq 'mod-refund-lost-item-fee-rule' ) { Link Here
540
    }
542
    }
541
}
543
}
542
544
543
my $refundLostItemFeeRule = Koha::RefundLostItemFeeRules->find({ branchcode => $branch });
545
my $refundLostItemFeeRule = Koha::RefundLostItemFeeRules->find({ branchcode => $branch eq '*' ? undef : $branch });
544
$template->param(
546
$template->param(
545
    refundLostItemFeeRule => $refundLostItemFeeRule,
547
    refundLostItemFeeRule => $refundLostItemFeeRule,
546
    defaultRefundRule     => Koha::RefundLostItemFeeRules->_default_rule
548
    defaultRefundRule     => Koha::RefundLostItemFeeRules->_default_rule
Lines 555-561 $template->param(show_branch_cat_rule_form => 1); Link Here
555
$template->param(
557
$template->param(
556
    patron_categories => $patron_categories,
558
    patron_categories => $patron_categories,
557
    itemtypeloop      => $itemtypes,
559
    itemtypeloop      => $itemtypes,
558
    humanbranch       => ( $branch ne '*' ? $branch : '' ),
560
    humanbranch       => ( $branch ne '*' ? $branch : undef ),
559
    current_branch    => $branch,
561
    current_branch    => $branch,
560
);
562
);
561
output_html_with_http_headers $input, $cookie, $template->output;
563
output_html_with_http_headers $input, $cookie, $template->output;
(-)a/api/v1/swagger/definitions.json (+3 lines)
Lines 1-4 Link Here
1
{
1
{
2
  "circ-rule-kind": {
3
    "$ref": "definitions/circ-rule-kind.json"
4
  },
2
  "city": {
5
  "city": {
3
    "$ref": "definitions/city.json"
6
    "$ref": "definitions/city.json"
4
  },
7
  },
(-)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 5-10 Link Here
5
  "/acquisitions/vendors/{vendor_id}": {
5
  "/acquisitions/vendors/{vendor_id}": {
6
    "$ref": "paths/acquisitions_vendors.json#/~1acquisitions~1vendors~1{vendor_id}"
6
    "$ref": "paths/acquisitions_vendors.json#/~1acquisitions~1vendors~1{vendor_id}"
7
  },
7
  },
8
  "/circulation-rules/kinds": {
9
    "$ref": "paths/circulation-rules.json#/~1circulation-rules~1kinds"
10
  },
8
  "/cities": {
11
  "/cities": {
9
    "$ref": "paths/cities.json#/~1cities"
12
    "$ref": "paths/cities.json#/~1cities"
10
  },
13
  },
(-)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/installer/data/mysql/atomicupdate/bug_18887.perl (-1 / +4 lines)
Lines 14-20 if( CheckVersion( $DBversion ) ) { Link Here
14
          KEY `categorycode` (`categorycode`),
14
          KEY `categorycode` (`categorycode`),
15
          KEY `itemtype` (`itemtype`),
15
          KEY `itemtype` (`itemtype`),
16
          KEY `rule_name` (`rule_name`),
16
          KEY `rule_name` (`rule_name`),
17
          UNIQUE (`branchcode`,`categorycode`,`itemtype`,`rule_name`)
17
          UNIQUE (`branchcode`,`categorycode`,`itemtype`,`rule_name`),
18
          FOREIGN KEY (branchcode) REFERENCES branches (branchcode) ON DELETE CASCADE ON UPDATE CASCADE,
19
          FOREIGN KEY (categorycode) REFERENCES categories (categorycode) ON DELETE CASCADE ON UPDATE CASCADE,
20
          FOREIGN KEY (itemtype) REFERENCES itemtypes (itemtype) ON DELETE CASCADE ON UPDATE CASCADE
18
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
21
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
19
    });
22
    });
20
23
(-)a/installer/data/mysql/kohastructure.sql (-1 / +4 lines)
Lines 4082-4088 CREATE TABLE `circulation_rules` ( Link Here
4082
  KEY `branchcode` (`branchcode`),
4082
  KEY `branchcode` (`branchcode`),
4083
  KEY `categorycode` (`categorycode`),
4083
  KEY `categorycode` (`categorycode`),
4084
  KEY `itemtype` (`itemtype`),
4084
  KEY `itemtype` (`itemtype`),
4085
  UNIQUE (`branchcode`,`categorycode`,`itemtype`)
4085
  UNIQUE (`branchcode`,`categorycode`,`itemtype`,`rule_name`),
4086
  FOREIGN KEY (branchcode) REFERENCES branches (branchcode) ON DELETE CASCADE ON UPDATE CASCADE,
4087
  FOREIGN KEY (categorycode) REFERENCES categories (categorycode) ON DELETE CASCADE ON UPDATE CASCADE,
4088
  FOREIGN KEY (itemtype) REFERENCES itemtypes (itemtype) ON DELETE CASCADE ON UPDATE CASCADE
4086
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
4089
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
4087
4090
4088
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
4091
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt (-7 / +12 lines)
Lines 4-22 Link Here
4
[% USE ItemTypes %]
4
[% USE ItemTypes %]
5
[% USE CirculationRules %]
5
[% USE CirculationRules %]
6
6
7
[% SET branchcode = humanbranch || '*' %]
7
[% SET branchcode = humanbranch || undef %]
8
8
9
[% SET categorycodes = [] %]
9
[% SET categorycodes = [] %]
10
[% FOREACH pc IN patron_categories %]
10
[% FOREACH pc IN patron_categories %]
11
    [% categorycodes.push( pc.id ) %]
11
    [% categorycodes.push( pc.id ) %]
12
[% END %]
12
[% END %]
13
[% categorycodes.push('*') %]
13
[% categorycodes.push(undef) %]
14
14
15
[% SET itemtypes = [] %]
15
[% SET itemtypes = [] %]
16
[% FOREACH i IN itemtypeloop %]
16
[% FOREACH i IN itemtypeloop %]
17
    [% itemtypes.push( i.itemtype ) %]
17
    [% itemtypes.push( i.itemtype ) %]
18
[% END %]
18
[% END %]
19
[% itemtypes.push('*') %]
19
[% itemtypes.push(undef) %]
20
20
21
[% INCLUDE 'doc-head-open.inc' %]
21
[% INCLUDE 'doc-head-open.inc' %]
22
<title>Koha &rsaquo; Administration &rsaquo; Circulation and fine rules</title>
22
<title>Koha &rsaquo; Administration &rsaquo; Circulation and fine rules</title>
Lines 255-273 $(document).ready(function() { Link Here
255
                            [% SET row_count = row_count + 1 %]
255
                            [% SET row_count = row_count + 1 %]
256
                            <tr row_countd="row_[% row_count %]">
256
                            <tr row_countd="row_[% row_count %]">
257
                                    <td>
257
                                    <td>
258
                                        [% IF c == '*' %]
258
                                        [% IF c == undef %]
259
                                            <em>All</em>
259
                                            <em>All</em>
260
                                        [% ELSE %]
260
                                        [% ELSE %]
261
                                            [% Categories.GetName(c) %]
261
                                            [% Categories.GetName(c) %]
262
                                        [% END %]
262
                                        [% END %]
263
                                    </td>
263
                                    </td>
264
                                    <td>
264
                                    <td>
265
                                        [% IF i == '*' %]
265
                                        [% IF i == undef %]
266
                                            <em>All</em>
266
                                            <em>All</em>
267
                                        [% ELSE %]
267
                                        [% ELSE %]
268
                                            [% ItemTypes.GetDescription(i) %]
268
                                            [% ItemTypes.GetDescription(i) %]
269
                                        [% END %]
269
                                        [% END %]
270
                                    </td>
270
                                    </td>
271
                                    <td class="actions">
272
                                      <a href="#" class="editrule btn btn-default btn-xs"><i class="fa fa-pencil"></i> Edit</a>
273
                                      <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>
274
                                    </td>
271
                                    <td>
275
                                    <td>
272
                                        [% IF maxissueqty  %]
276
                                        [% IF maxissueqty  %]
273
                                            [% maxissueqty %]
277
                                            [% maxissueqty %]
Lines 354-360 $(document).ready(function() { Link Here
354
                                    <td>[% rentaldiscount %]</td>
358
                                    <td>[% rentaldiscount %]</td>
355
                                    <td class="actions">
359
                                    <td class="actions">
356
                                      <a href="#" class="editrule btn btn-default btn-xs"><i class="fa fa-pencil"></i> Edit</a>
360
                                      <a href="#" class="editrule btn btn-default btn-xs"><i class="fa fa-pencil"></i> Edit</a>
357
                                      <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=[% rule.current_branch %]"><i class="fa fa-trash"></i> Delete</a>
361
                                      <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>
358
                                    </td>
362
                                    </td>
359
                            </tr>
363
                            </tr>
360
                        [% END %]
364
                        [% END %]
Lines 658-663 $(document).ready(function() { Link Here
658
                    <th>&nbsp;</th>
662
                    <th>&nbsp;</th>
659
                </tr>
663
                </tr>
660
                [% FOREACH c IN categorycodes %]
664
                [% FOREACH c IN categorycodes %]
665
                    [% NEXT UNLESS c %]
661
                    [% SET patron_maxissueqty = CirculationRules.Get( branchcode, c, undef, 'patron_maxissueqty' ) %]
666
                    [% SET patron_maxissueqty = CirculationRules.Get( branchcode, c, undef, 'patron_maxissueqty' ) %]
662
                    [% SET patron_maxonsiteissueqty = CirculationRules.Get( branchcode, c, undef, 'patron_maxonsiteissueqty' ) %]
667
                    [% SET patron_maxonsiteissueqty = CirculationRules.Get( branchcode, c, undef, 'patron_maxonsiteissueqty' ) %]
663
                    [% SET max_holds = CirculationRules.Get( branchcode, c, undef, 'max_holds' ) %]
668
                    [% SET max_holds = CirculationRules.Get( branchcode, c, undef, 'max_holds' ) %]
Lines 665-671 $(document).ready(function() { Link Here
665
                    [% IF patron_maxissueqty || patron_maxonsiteissueqty || max_holds %]
670
                    [% IF patron_maxissueqty || patron_maxonsiteissueqty || max_holds %]
666
                    <tr>
671
                    <tr>
667
                        <td>
672
                        <td>
668
                            [% IF c == '*'%]
673
                            [% IF c == undef %]
669
                                <em>Default</em>
674
                                <em>Default</em>
670
                            [% ELSE %]
675
                            [% ELSE %]
671
                                [% Categories.GetName(c) %]
676
                                [% Categories.GetName(c) %]
(-)a/t/db_dependent/ArticleRequests.t (-12 / +12 lines)
Lines 147-155 is( $biblio->article_requests_finished()->count(), 1, 'Canceled request not retu Link Here
147
147
148
my $rule = Koha::CirculationRules->set_rule(
148
my $rule = Koha::CirculationRules->set_rule(
149
    {
149
    {
150
        categorycode => '*',
150
        categorycode => undef,
151
        itemtype     => '*',
151
        itemtype     => undef,
152
        branchcode   => '*',
152
        branchcode   => undef,
153
        rule_name    => 'article_requests',
153
        rule_name    => 'article_requests',
154
        rule_value   => 'yes',
154
        rule_value   => 'yes',
155
    }
155
    }
Lines 162-170 $rule->delete(); Link Here
162
162
163
$rule = Koha::CirculationRules->set_rule(
163
$rule = Koha::CirculationRules->set_rule(
164
    {
164
    {
165
        categorycode => '*',
165
        categorycode => undef,
166
        itemtype     => '*',
166
        itemtype     => undef,
167
        branchcode   => '*',
167
        branchcode   => undef,
168
        rule_name    => 'article_requests',
168
        rule_name    => 'article_requests',
169
        rule_value   => 'bib_only',
169
        rule_value   => 'bib_only',
170
    }
170
    }
Lines 177-185 $rule->delete(); Link Here
177
177
178
$rule = Koha::CirculationRules->set_rule(
178
$rule = Koha::CirculationRules->set_rule(
179
    {
179
    {
180
        categorycode => '*',
180
        categorycode => undef,
181
        itemtype     => '*',
181
        itemtype     => undef,
182
        branchcode   => '*',
182
        branchcode   => undef,
183
        rule_name    => 'article_requests',
183
        rule_name    => 'article_requests',
184
        rule_value   => 'item_only',
184
        rule_value   => 'item_only',
185
    }
185
    }
Lines 192-200 $rule->delete(); Link Here
192
192
193
$rule = Koha::CirculationRules->set_rule(
193
$rule = Koha::CirculationRules->set_rule(
194
    {
194
    {
195
        categorycode => '*',
195
        categorycode => undef,
196
        itemtype     => '*',
196
        itemtype     => undef,
197
        branchcode   => '*',
197
        branchcode   => undef,
198
        rule_name    => 'article_requests',
198
        rule_name    => 'article_requests',
199
        rule_value   => 'no',
199
        rule_value   => 'no',
200
    }
200
    }
(-)a/t/db_dependent/Circulation.t (-77 / +94 lines)
Lines 18-23 Link Here
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 102;
20
use Test::More tests => 102;
21
use Test::Deep qw( cmp_deeply );
21
22
22
use DateTime;
23
use DateTime;
23
24
Lines 170-178 is( Link Here
170
$dbh->do('DELETE FROM circulation_rules');
171
$dbh->do('DELETE FROM circulation_rules');
171
Koha::CirculationRules->set_rules(
172
Koha::CirculationRules->set_rules(
172
    {
173
    {
173
        categorycode => '*',
174
        categorycode => undef,
174
        branchcode   => '*',
175
        branchcode   => undef,
175
        itemtype     => '*',
176
        itemtype     => undef,
176
        rules        => {
177
        rules        => {
177
            reservesallowed => 25,
178
            reservesallowed => 25,
178
            issuelength     => 14,
179
            issuelength     => 14,
Lines 330-338 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
330
    # Testing of feature to allow the renewal of reserved items if other items on the record can fill all needed holds
331
    # Testing of feature to allow the renewal of reserved items if other items on the record can fill all needed holds
331
    Koha::CirculationRules->set_rule(
332
    Koha::CirculationRules->set_rule(
332
        {
333
        {
333
            categorycode => '*',
334
            categorycode => undef,
334
            branchcode   => '*',
335
            branchcode   => undef,
335
            itemtype     => '*',
336
            itemtype     => undef,
336
            rule_name    => 'onshelfholds',
337
            rule_name    => 'onshelfholds',
337
            rule_value   => '1',
338
            rule_value   => '1',
338
        }
339
        }
Lines 551-559 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
551
    # Test premature manual renewal
552
    # Test premature manual renewal
552
    Koha::CirculationRules->set_rule(
553
    Koha::CirculationRules->set_rule(
553
        {
554
        {
554
            categorycode => '*',
555
            categorycode => undef,
555
            branchcode   => '*',
556
            branchcode   => undef,
556
            itemtype     => '*',
557
            itemtype     => undef,
557
            rule_name    => 'norenewalbefore',
558
            rule_name    => 'norenewalbefore',
558
            rule_value   => '7',
559
            rule_value   => '7',
559
        }
560
        }
Lines 628-636 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
628
629
629
        Koha::CirculationRules->set_rules(
630
        Koha::CirculationRules->set_rules(
630
            {
631
            {
631
                categorycode => '*',
632
                categorycode => undef,
632
                branchcode   => '*',
633
                branchcode   => undef,
633
                itemtype     => '*',
634
                itemtype     => undef,
634
                rules        => {
635
                rules        => {
635
                    norenewalbefore       => '7',
636
                    norenewalbefore       => '7',
636
                    no_auto_renewal_after => '9',
637
                    no_auto_renewal_after => '9',
Lines 644-652 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
644
645
645
        Koha::CirculationRules->set_rules(
646
        Koha::CirculationRules->set_rules(
646
            {
647
            {
647
                categorycode => '*',
648
                categorycode => undef,
648
                branchcode   => '*',
649
                branchcode   => undef,
649
                itemtype     => '*',
650
                itemtype     => undef,
650
                rules        => {
651
                rules        => {
651
                    norenewalbefore       => '7',
652
                    norenewalbefore       => '7',
652
                    no_auto_renewal_after => '10',
653
                    no_auto_renewal_after => '10',
Lines 660-668 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
660
661
661
        Koha::CirculationRules->set_rules(
662
        Koha::CirculationRules->set_rules(
662
            {
663
            {
663
                categorycode => '*',
664
                categorycode => undef,
664
                branchcode   => '*',
665
                branchcode   => undef,
665
                itemtype     => '*',
666
                itemtype     => undef,
666
                rules        => {
667
                rules        => {
667
                    norenewalbefore       => '7',
668
                    norenewalbefore       => '7',
668
                    no_auto_renewal_after => '11',
669
                    no_auto_renewal_after => '11',
Lines 676-684 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
676
677
677
        Koha::CirculationRules->set_rules(
678
        Koha::CirculationRules->set_rules(
678
            {
679
            {
679
                categorycode => '*',
680
                categorycode => undef,
680
                branchcode   => '*',
681
                branchcode   => undef,
681
                itemtype     => '*',
682
                itemtype     => undef,
682
                rules        => {
683
                rules        => {
683
                    norenewalbefore       => '10',
684
                    norenewalbefore       => '10',
684
                    no_auto_renewal_after => '11',
685
                    no_auto_renewal_after => '11',
Lines 692-700 C4::Context->dbh->do("DELETE FROM accountlines"); 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       => '10',
700
                    norenewalbefore       => '10',
700
                    no_auto_renewal_after => undef,
701
                    no_auto_renewal_after => undef,
Lines 709-717 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
709
710
710
        Koha::CirculationRules->set_rules(
711
        Koha::CirculationRules->set_rules(
711
            {
712
            {
712
                categorycode => '*',
713
                categorycode => undef,
713
                branchcode   => '*',
714
                branchcode   => undef,
714
                itemtype     => '*',
715
                itemtype     => undef,
715
                rules        => {
716
                rules        => {
716
                    norenewalbefore       => '7',
717
                    norenewalbefore       => '7',
717
                    no_auto_renewal_after => '15',
718
                    no_auto_renewal_after => '15',
Lines 726-734 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
726
727
727
        Koha::CirculationRules->set_rules(
728
        Koha::CirculationRules->set_rules(
728
            {
729
            {
729
                categorycode => '*',
730
                categorycode => undef,
730
                branchcode   => '*',
731
                branchcode   => undef,
731
                itemtype     => '*',
732
                itemtype     => undef,
732
                rules        => {
733
                rules        => {
733
                    norenewalbefore       => '10',
734
                    norenewalbefore       => '10',
734
                    no_auto_renewal_after => undef,
735
                    no_auto_renewal_after => undef,
Lines 759-767 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
759
760
760
        Koha::CirculationRules->set_rules(
761
        Koha::CirculationRules->set_rules(
761
            {
762
            {
762
                categorycode => '*',
763
                categorycode => undef,
763
                branchcode   => '*',
764
                branchcode   => undef,
764
                itemtype     => '*',
765
                itemtype     => undef,
765
                rules        => {
766
                rules        => {
766
                    norenewalbefore       => '10',
767
                    norenewalbefore       => '10',
767
                    no_auto_renewal_after => '11',
768
                    no_auto_renewal_after => '11',
Lines 809-817 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
809
        AddIssue( $renewing_borrower, $item_to_auto_renew->{barcode}, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } );
810
        AddIssue( $renewing_borrower, $item_to_auto_renew->{barcode}, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } );
810
        Koha::CirculationRules->set_rules(
811
        Koha::CirculationRules->set_rules(
811
            {
812
            {
812
                categorycode => '*',
813
                categorycode => undef,
813
                branchcode   => '*',
814
                branchcode   => undef,
814
                itemtype     => '*',
815
                itemtype     => undef,
815
                rules        => {
816
                rules        => {
816
                    norenewalbefore       => '7',
817
                    norenewalbefore       => '7',
817
                    no_auto_renewal_after => '',
818
                    no_auto_renewal_after => '',
Lines 824-832 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
824
        my $five_days_before = dt_from_string->add( days => -5 );
825
        my $five_days_before = dt_from_string->add( days => -5 );
825
        Koha::CirculationRules->set_rules(
826
        Koha::CirculationRules->set_rules(
826
            {
827
            {
827
                categorycode => '*',
828
                categorycode => undef,
828
                branchcode   => '*',
829
                branchcode   => undef,
829
                itemtype     => '*',
830
                itemtype     => undef,
830
                rules        => {
831
                rules        => {
831
                    norenewalbefore       => '10',
832
                    norenewalbefore       => '10',
832
                    no_auto_renewal_after => '5',
833
                    no_auto_renewal_after => '5',
Lines 845-853 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
845
        $dbh->do(q{UPDATE circulation_rules SET rule_value = NULL WHERE rule_name = 'no_auto_renewal_after_hard_limit'});
846
        $dbh->do(q{UPDATE circulation_rules SET rule_value = NULL WHERE rule_name = 'no_auto_renewal_after_hard_limit'});
846
        Koha::CirculationRules->set_rules(
847
        Koha::CirculationRules->set_rules(
847
            {
848
            {
848
                categorycode => '*',
849
                categorycode => undef,
849
                branchcode   => '*',
850
                branchcode   => undef,
850
                itemtype     => '*',
851
                itemtype     => undef,
851
                rules        => {
852
                rules        => {
852
                    norenewalbefore       => '10',
853
                    norenewalbefore       => '10',
853
                    no_auto_renewal_after => '15',
854
                    no_auto_renewal_after => '15',
Lines 863-871 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
863
        my $two_days_ahead = dt_from_string->add( days => 2 );
864
        my $two_days_ahead = dt_from_string->add( days => 2 );
864
        Koha::CirculationRules->set_rules(
865
        Koha::CirculationRules->set_rules(
865
            {
866
            {
866
                categorycode => '*',
867
                categorycode => undef,
867
                branchcode   => '*',
868
                branchcode   => undef,
868
                itemtype     => '*',
869
                itemtype     => undef,
869
                rules        => {
870
                rules        => {
870
                    norenewalbefore       => '10',
871
                    norenewalbefore       => '10',
871
                    no_auto_renewal_after => '',
872
                    no_auto_renewal_after => '',
Lines 880-888 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
880
        );
881
        );
881
        Koha::CirculationRules->set_rules(
882
        Koha::CirculationRules->set_rules(
882
            {
883
            {
883
                categorycode => '*',
884
                categorycode => undef,
884
                branchcode   => '*',
885
                branchcode   => undef,
885
                itemtype     => '*',
886
                itemtype     => undef,
886
                rules        => {
887
                rules        => {
887
                    norenewalbefore       => '10',
888
                    norenewalbefore       => '10',
888
                    no_auto_renewal_after => '15',
889
                    no_auto_renewal_after => '15',
Lines 902-910 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
902
    # set policy to forbid renewals
903
    # set policy to forbid renewals
903
    Koha::CirculationRules->set_rules(
904
    Koha::CirculationRules->set_rules(
904
        {
905
        {
905
            categorycode => '*',
906
            categorycode => undef,
906
            branchcode   => '*',
907
            branchcode   => undef,
907
            itemtype     => '*',
908
            itemtype     => undef,
908
            rules        => {
909
            rules        => {
909
                norenewalbefore => undef,
910
                norenewalbefore => undef,
910
                renewalsallowed => 0,
911
                renewalsallowed => 0,
Lines 1126-1134 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
1126
    $dbh->do('DELETE FROM circulation_rules');
1127
    $dbh->do('DELETE FROM circulation_rules');
1127
    Koha::CirculationRules->set_rules(
1128
    Koha::CirculationRules->set_rules(
1128
        {
1129
        {
1129
            categorycode => '*',
1130
            categorycode => undef,
1130
            itemtype     => '*',
1131
            itemtype     => undef,
1131
            branchcode   => '*',
1132
            branchcode   => undef,
1132
            rules        => {
1133
            rules        => {
1133
                reservesallowed => 25,
1134
                reservesallowed => 25,
1134
                issuelength     => 14,
1135
                issuelength     => 14,
Lines 1196-1204 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
1196
1197
1197
    Koha::CirculationRules->set_rules(
1198
    Koha::CirculationRules->set_rules(
1198
        {
1199
        {
1199
            categorycode => '*',
1200
            categorycode => undef,
1200
            itemtype     => '*',
1201
            itemtype     => undef,
1201
            branchcode   => '*',
1202
            branchcode   => undef,
1202
            rules        => {
1203
            rules        => {
1203
                onshelfholds => 0,
1204
                onshelfholds => 0,
1204
            }
1205
            }
Lines 1210-1218 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
1210
1211
1211
    Koha::CirculationRules->set_rules(
1212
    Koha::CirculationRules->set_rules(
1212
        {
1213
        {
1213
            categorycode => '*',
1214
            categorycode => undef,
1214
            itemtype     => '*',
1215
            itemtype     => undef,
1215
            branchcode   => '*',
1216
            branchcode   => undef,
1216
            rules        => {
1217
            rules        => {
1217
                onshelfholds => 0,
1218
                onshelfholds => 0,
1218
            }
1219
            }
Lines 1224-1232 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
1224
1225
1225
    Koha::CirculationRules->set_rules(
1226
    Koha::CirculationRules->set_rules(
1226
        {
1227
        {
1227
            categorycode => '*',
1228
            categorycode => undef,
1228
            itemtype     => '*',
1229
            itemtype     => undef,
1229
            branchcode   => '*',
1230
            branchcode   => undef,
1230
            rules        => {
1231
            rules        => {
1231
                onshelfholds => 1,
1232
                onshelfholds => 1,
1232
            }
1233
            }
Lines 1238-1246 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
1238
1239
1239
    Koha::CirculationRules->set_rules(
1240
    Koha::CirculationRules->set_rules(
1240
        {
1241
        {
1241
            categorycode => '*',
1242
            categorycode => undef,
1242
            itemtype     => '*',
1243
            itemtype     => undef,
1243
            branchcode   => '*',
1244
            branchcode   => undef,
1244
            rules        => {
1245
            rules        => {
1245
                onshelfholds => 1,
1246
                onshelfholds => 1,
1246
            }
1247
            }
Lines 1754-1776 subtest 'CanBookBeIssued + AllowMultipleIssuesOnABiblio' => sub { Link Here
1754
1755
1755
    t::lib::Mocks::mock_preference('AllowMultipleIssuesOnABiblio', 0);
1756
    t::lib::Mocks::mock_preference('AllowMultipleIssuesOnABiblio', 0);
1756
    ( $error, $question, $alerts ) = CanBookBeIssued( $patron, $item_2->{barcode} );
1757
    ( $error, $question, $alerts ) = CanBookBeIssued( $patron, $item_2->{barcode} );
1757
    is( keys(%$error) + keys(%$alerts),  0, 'No error or alert should be raised' . str($error, $question, $alerts) );
1758
    cmp_deeply(
1758
    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) );
1759
        { error => $error, alerts => $alerts },
1760
        { error => {}, alerts => {} },
1761
        'No error or alert should be raised'
1762
    );
1763
    is( $question->{BIBLIO_ALREADY_ISSUED}, 1, 'BIBLIO_ALREADY_ISSUED question flag should be set if AllowMultipleIssuesOnABiblio=0 and issue already exists' );
1759
1764
1760
    t::lib::Mocks::mock_preference('AllowMultipleIssuesOnABiblio', 1);
1765
    t::lib::Mocks::mock_preference('AllowMultipleIssuesOnABiblio', 1);
1761
    ( $error, $question, $alerts ) = CanBookBeIssued( $patron, $item_2->{barcode} );
1766
    ( $error, $question, $alerts ) = CanBookBeIssued( $patron, $item_2->{barcode} );
1762
    is( keys(%$error) + keys(%$question) + keys(%$alerts),  0, 'No BIBLIO_ALREADY_ISSUED flag should be set if AllowMultipleIssuesOnABiblio=1' . str($error, $question, $alerts) );
1767
    cmp_deeply(
1768
        { error => $error, question => $question, alerts => $alerts },
1769
        { error => {}, question => {}, alerts => {} },
1770
        'No BIBLIO_ALREADY_ISSUED flag should be set if AllowMultipleIssuesOnABiblio=1'
1771
    );
1763
1772
1764
    # Add a subscription
1773
    # Add a subscription
1765
    Koha::Subscription->new({ biblionumber => $biblionumber })->store;
1774
    Koha::Subscription->new({ biblionumber => $biblionumber })->store;
1766
1775
1767
    t::lib::Mocks::mock_preference('AllowMultipleIssuesOnABiblio', 0);
1776
    t::lib::Mocks::mock_preference('AllowMultipleIssuesOnABiblio', 0);
1768
    ( $error, $question, $alerts ) = CanBookBeIssued( $patron, $item_2->{barcode} );
1777
    ( $error, $question, $alerts ) = CanBookBeIssued( $patron, $item_2->{barcode} );
1769
    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) );
1778
    cmp_deeply(
1779
        { error => $error, question => $question, alerts => $alerts },
1780
        { error => {}, question => {}, alerts => {} },
1781
        'No BIBLIO_ALREADY_ISSUED flag should be set if it is a subscription'
1782
    );
1770
1783
1771
    t::lib::Mocks::mock_preference('AllowMultipleIssuesOnABiblio', 1);
1784
    t::lib::Mocks::mock_preference('AllowMultipleIssuesOnABiblio', 1);
1772
    ( $error, $question, $alerts ) = CanBookBeIssued( $patron, $item_2->{barcode} );
1785
    ( $error, $question, $alerts ) = CanBookBeIssued( $patron, $item_2->{barcode} );
1773
    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) );
1786
    cmp_deeply(
1787
        { error => $error, question => $question, alerts => $alerts },
1788
        { error => {}, question => {}, alerts => {} },
1789
        'No BIBLIO_ALREADY_ISSUED flag should be set if it is a subscription'
1790
    );
1774
};
1791
};
1775
1792
1776
subtest 'AddReturn + CumulativeRestrictionPeriods' => sub {
1793
subtest 'AddReturn + CumulativeRestrictionPeriods' => sub {
Lines 1813-1821 subtest 'AddReturn + CumulativeRestrictionPeriods' => sub { Link Here
1813
    Koha::CirculationRules->search->delete;
1830
    Koha::CirculationRules->search->delete;
1814
    Koha::CirculationRules->set_rules(
1831
    Koha::CirculationRules->set_rules(
1815
        {
1832
        {
1816
            categorycode => '*',
1833
            categorycode => undef,
1817
            itemtype     => '*',
1834
            itemtype     => undef,
1818
            branchcode   => '*',
1835
            branchcode   => undef,
1819
            rules        => {
1836
            rules        => {
1820
                issuelength => 1,
1837
                issuelength => 1,
1821
                firstremind => 1,        # 1 day of grace
1838
                firstremind => 1,        # 1 day of grace
Lines 1928-1936 subtest 'AddReturn | is_overdue' => sub { Link Here
1928
    Koha::CirculationRules->search->delete;
1945
    Koha::CirculationRules->search->delete;
1929
    my $rule = Koha::CirculationRules->set_rules(
1946
    my $rule = Koha::CirculationRules->set_rules(
1930
        {
1947
        {
1931
            categorycode => '*',
1948
            categorycode => undef,
1932
            itemtype     => '*',
1949
            itemtype     => undef,
1933
            branchcode   => '*',
1950
            branchcode   => undef,
1934
            rules        => {
1951
            rules        => {
1935
                maxissueqty  => 99,
1952
                maxissueqty  => 99,
1936
                issuelength  => 6,
1953
                issuelength  => 6,
(-)a/t/db_dependent/Circulation/Branch.t (-6 / +17 lines)
Lines 153-159 Koha::CirculationRules->set_rules( Link Here
153
    {
153
    {
154
        branchcode   => $samplebranch1->{branchcode},
154
        branchcode   => $samplebranch1->{branchcode},
155
        categorycode => $samplecat->{categorycode},
155
        categorycode => $samplecat->{categorycode},
156
        itemtype     => undef,
157
        rules        => {
156
        rules        => {
158
            patron_maxissueqty       => 5,
157
            patron_maxissueqty       => 5,
159
            patron_maxonsiteissueqty => 6,
158
            patron_maxonsiteissueqty => 6,
Lines 161-174 Koha::CirculationRules->set_rules( Link Here
161
    }
160
    }
162
);
161
);
163
162
163
164
Koha::CirculationRules->set_rules(
164
Koha::CirculationRules->set_rules(
165
    {
165
    {
166
        branchcode   => $samplebranch2->{branchcode},
166
        branchcode   => $samplebranch2->{branchcode},
167
        categorycode => undef,
167
        categorycode => undef,
168
        itemtype     => undef,
169
        rules        => {
168
        rules        => {
170
            patron_maxissueqty       => 3,
169
            patron_maxissueqty       => 3,
171
            patron_maxonsiteissueqty => 2,
170
            patron_maxonsiteissueqty => 2,
171
        }
172
    }
173
);
174
Koha::CirculationRules->set_rules(
175
    {
176
        branchcode   => $samplebranch2->{branchcode},
177
        itemtype     => undef,
178
        rules        => {
172
            holdallowed       => 1,
179
            holdallowed       => 1,
173
            returnbranch      => 'holdingbranch',
180
            returnbranch      => 'holdingbranch',
174
        }
181
        }
Lines 179-188 Koha::CirculationRules->set_rules( Link Here
179
    {
186
    {
180
        branchcode   => undef,
187
        branchcode   => undef,
181
        categorycode => undef,
188
        categorycode => undef,
182
        itemtype     => undef,
183
        rules        => {
189
        rules        => {
184
            patron_maxissueqty       => 4,
190
            patron_maxissueqty       => 4,
185
            patron_maxonsiteissueqty => 5,
191
            patron_maxonsiteissueqty => 5,
192
        }
193
    }
194
);
195
Koha::CirculationRules->set_rules(
196
    {
197
        branchcode   => undef,
198
        itemtype     => undef,
199
        rules        => {
186
            holdallowed       => 3,
200
            holdallowed       => 3,
187
            returnbranch      => 'homebranch',
201
            returnbranch      => 'homebranch',
188
        }
202
        }
Lines 192-198 Koha::CirculationRules->set_rules( Link Here
192
Koha::CirculationRules->set_rules(
206
Koha::CirculationRules->set_rules(
193
    {
207
    {
194
        branchcode   => $samplebranch1->{branchcode},
208
        branchcode   => $samplebranch1->{branchcode},
195
        categorycode => undef,
196
        itemtype     => $sampleitemtype1->{itemtype},
209
        itemtype     => $sampleitemtype1->{itemtype},
197
        rules        => {
210
        rules        => {
198
            holdallowed       => 5,
211
            holdallowed       => 5,
Lines 203-209 Koha::CirculationRules->set_rules( Link Here
203
Koha::CirculationRules->set_rules(
216
Koha::CirculationRules->set_rules(
204
    {
217
    {
205
        branchcode   => $samplebranch2->{branchcode},
218
        branchcode   => $samplebranch2->{branchcode},
206
        categorycode => undef,
207
        itemtype     => $sampleitemtype1->{itemtype},
219
        itemtype     => $sampleitemtype1->{itemtype},
208
        rules        => {
220
        rules        => {
209
            holdallowed       => 5,
221
            holdallowed       => 5,
Lines 214-220 Koha::CirculationRules->set_rules( Link Here
214
Koha::CirculationRules->set_rules(
226
Koha::CirculationRules->set_rules(
215
    {
227
    {
216
        branchcode   => $samplebranch2->{branchcode},
228
        branchcode   => $samplebranch2->{branchcode},
217
        categorycode => undef,
218
        itemtype     => $sampleitemtype2->{itemtype},
229
        itemtype     => $sampleitemtype2->{itemtype},
219
        rules        => {
230
        rules        => {
220
            holdallowed       => 5,
231
            holdallowed       => 5,
(-)a/t/db_dependent/Circulation/CalcFine.t (-6 / +6 lines)
Lines 68-76 subtest 'Test basic functionality' => sub { Link Here
68
68
69
    Koha::CirculationRules->set_rules(
69
    Koha::CirculationRules->set_rules(
70
        {
70
        {
71
            branchcode   => '*',
71
            branchcode   => undef,
72
            categorycode => '*',
72
            categorycode => undef,
73
            itemtype     => '*',
73
            itemtype     => undef,
74
            rules        => {
74
            rules        => {
75
                fine                          => '1.00',
75
                fine                          => '1.00',
76
                lengthunit                    => 'days',
76
                lengthunit                    => 'days',
Lines 106-114 subtest 'Test cap_fine_to_replacement_price' => sub { Link Here
106
    plan tests => 1;
106
    plan tests => 1;
107
    Koha::CirculationRules->set_rules(
107
    Koha::CirculationRules->set_rules(
108
        {
108
        {
109
            branchcode   => '*',
109
            branchcode   => undef,
110
            categorycode => '*',
110
            categorycode => undef,
111
            itemtype     => '*',
111
            itemtype     => undef,
112
            rules        => {
112
            rules        => {
113
                fine                          => '1.00',
113
                fine                          => '1.00',
114
                lengthunit                    => 'days',
114
                lengthunit                    => 'days',
(-)a/t/db_dependent/Circulation/GetHardDueDate.t (-19 / +13 lines)
Lines 7-12 use Koha::DateUtils; Link Here
7
use Koha::CirculationRules;
7
use Koha::CirculationRules;
8
use Koha::Library;
8
use Koha::Library;
9
9
10
use t::lib::TestBuilder;
11
10
use Test::More tests => 10;
12
use Test::More tests => 10;
11
13
12
BEGIN {
14
BEGIN {
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-126 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
        chargename                       => 'Null',
122
        restrictedtype                   => 0,
123
        accountsent                      => 0,
124
        finedays                         => 0,
126
        finedays                         => 0,
125
        lengthunit                       => 'days',
127
        lengthunit                       => 'days',
126
        renewalperiod                    => 5,
128
        renewalperiod                    => 5,
Lines 148-154 my $sampleissuingrule1 = { Link Here
148
my $sampleissuingrule2 = {
150
my $sampleissuingrule2 = {
149
    branchcode   => $samplebranch2->{branchcode},
151
    branchcode   => $samplebranch2->{branchcode},
150
    categorycode => $samplecat->{categorycode},
152
    categorycode => $samplecat->{categorycode},
151
    itemtype     => 'BOOK',
153
    itemtype     => $sampleitemtype1,
152
    rules        => {
154
    rules        => {
153
        renewalsallowed               => 'Null',
155
        renewalsallowed               => 'Null',
154
        renewalperiod                 => 2,
156
        renewalperiod                 => 2,
Lines 166-175 my $sampleissuingrule2 = { Link Here
166
        chargeperiod_charge_at        => 0,
168
        chargeperiod_charge_at        => 0,
167
        rentaldiscount                => 2.00,
169
        rentaldiscount                => 2.00,
168
        overduefinescap               => 'Null',
170
        overduefinescap               => 'Null',
169
        accountsent                   => 'Null',
170
        reservecharge                 => 'Null',
171
        chargename                    => 'Null',
172
        restrictedtype                => 'Null',
173
        maxsuspensiondays             => 0,
171
        maxsuspensiondays             => 0,
174
        onshelfholds                  => 1,
172
        onshelfholds                  => 1,
175
        opacitemholds                 => 'Y',
173
        opacitemholds                 => 'Y',
Lines 181-187 my $sampleissuingrule2 = { Link Here
181
my $sampleissuingrule3 = {
179
my $sampleissuingrule3 = {
182
    branchcode   => $samplebranch1->{branchcode},
180
    branchcode   => $samplebranch1->{branchcode},
183
    categorycode => $samplecat->{categorycode},
181
    categorycode => $samplecat->{categorycode},
184
    itemtype     => 'DVD',
182
    itemtype     => $sampleitemtype2,
185
    rules        => {
183
    rules        => {
186
        renewalsallowed               => 'Null',
184
        renewalsallowed               => 'Null',
187
        renewalperiod                 => 3,
185
        renewalperiod                 => 3,
Lines 199-208 my $sampleissuingrule3 = { Link Here
199
        chargeperiod_charge_at        => 0,
197
        chargeperiod_charge_at        => 0,
200
        rentaldiscount                => 3.00,
198
        rentaldiscount                => 3.00,
201
        overduefinescap               => 'Null',
199
        overduefinescap               => 'Null',
202
        accountsent                   => 'Null',
203
        reservecharge                 => 'Null',
204
        chargename                    => 'Null',
205
        restrictedtype                => 'Null',
206
        maxsuspensiondays             => 0,
200
        maxsuspensiondays             => 0,
207
        onshelfholds                  => 1,
201
        onshelfholds                  => 1,
208
        opacitemholds                 => 'F',
202
        opacitemholds                 => 'F',
Lines 235-241 is_deeply( Link Here
235
is_deeply(
229
is_deeply(
236
    C4::Circulation::GetLoanLength(
230
    C4::Circulation::GetLoanLength(
237
        $samplecat->{categorycode},
231
        $samplecat->{categorycode},
238
        'BOOK', $samplebranch1->{branchcode}
232
        $sampleitemtype1, $samplebranch1->{branchcode}
239
    ),
233
    ),
240
    { issuelength => 5, lengthunit => 'days', renewalperiod => 5 },
234
    { issuelength => 5, lengthunit => 'days', renewalperiod => 5 },
241
    "GetLoanLength"
235
    "GetLoanLength"
Lines 257-268 is_deeply( Link Here
257
    "With only one parameter, GetLoanLength returns hardcoded values"
251
    "With only one parameter, GetLoanLength returns hardcoded values"
258
);    #NOTE : is that really what is expected?
252
);    #NOTE : is that really what is expected?
259
is_deeply(
253
is_deeply(
260
    C4::Circulation::GetLoanLength( $samplecat->{categorycode}, 'BOOK' ),
254
    C4::Circulation::GetLoanLength( $samplecat->{categorycode}, $sampleitemtype1 ),
261
    $default,
255
    $default,
262
    "With only two parameters, GetLoanLength returns hardcoded values"
256
    "With only two parameters, GetLoanLength returns hardcoded values"
263
);    #NOTE : is that really what is expected?
257
);    #NOTE : is that really what is expected?
264
is_deeply(
258
is_deeply(
265
    C4::Circulation::GetLoanLength( $samplecat->{categorycode}, 'BOOK', $samplebranch1->{branchcode} ),
259
    C4::Circulation::GetLoanLength( $samplecat->{categorycode}, $sampleitemtype1, $samplebranch1->{branchcode} ),
266
    {
260
    {
267
        issuelength   => 5,
261
        issuelength   => 5,
268
        renewalperiod => 5,
262
        renewalperiod => 5,
Lines 273-279 is_deeply( Link Here
273
267
274
#Test GetHardDueDate
268
#Test GetHardDueDate
275
my @hardduedate = C4::Circulation::GetHardDueDate( $samplecat->{categorycode},
269
my @hardduedate = C4::Circulation::GetHardDueDate( $samplecat->{categorycode},
276
    'BOOK', $samplebranch1->{branchcode} );
270
    $sampleitemtype1, $samplebranch1->{branchcode} );
277
is_deeply(
271
is_deeply(
278
    \@hardduedate,
272
    \@hardduedate,
279
    [
273
    [
(-)a/t/db_dependent/Circulation/IssuingRules/maxsuspensiondays.t (-6 / +6 lines)
Lines 33-41 my $userenv->{branch} = $branchcode; Link Here
33
Koha::CirculationRules->search->delete;
33
Koha::CirculationRules->search->delete;
34
Koha::CirculationRules->set_rules(
34
Koha::CirculationRules->set_rules(
35
    {
35
    {
36
        categorycode => '*',
36
        categorycode => undef,
37
        itemtype     => '*',
37
        itemtype     => undef,
38
        branchcode   => '*',
38
        branchcode   => undef,
39
        rules        => {
39
        rules        => {
40
            firstremind => 0,
40
            firstremind => 0,
41
            finedays    => 2,
41
            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 51-59 my $builder = t::lib::TestBuilder->new(); Link Here
51
Koha::CirculationRules->search->delete;
51
Koha::CirculationRules->search->delete;
52
Koha::CirculationRules->set_rule(
52
Koha::CirculationRules->set_rule(
53
    {
53
    {
54
        categorycode => '*',
54
        categorycode => undef,
55
        itemtype     => '*',
55
        itemtype     => undef,
56
        branchcode   => '*',
56
        branchcode   => undef,
57
        rule_name    => 'issuelength',
57
        rule_name    => 'issuelength',
58
        rule_value   => 1,
58
        rule_value   => 1,
59
    }
59
    }
Lines 285-293 subtest 'Handle ids duplication' => sub { Link Here
285
    t::lib::Mocks::mock_preference( 'finesMode', 'production' );
285
    t::lib::Mocks::mock_preference( 'finesMode', 'production' );
286
    Koha::CirculationRules->set_rules(
286
    Koha::CirculationRules->set_rules(
287
        {
287
        {
288
            categorycode => '*',
288
            categorycode => undef,
289
            itemtype     => '*',
289
            itemtype     => undef,
290
            branchcode   => '*',
290
            branchcode   => undef,
291
            rules        => {
291
            rules        => {
292
                chargeperiod => 1,
292
                chargeperiod => 1,
293
                fine         => 1,
293
                fine         => 1,
(-)a/t/db_dependent/Circulation/SwitchOnSiteCheckouts.t (-7 / +4 lines)
Lines 76-89 Koha::CirculationRules->search()->delete(); Link Here
76
Koha::CirculationRules->set_rules(
76
Koha::CirculationRules->set_rules(
77
    {
77
    {
78
        branchcode   => $branch->{branchcode},
78
        branchcode   => $branch->{branchcode},
79
        categorycode => '*',
79
        categorycode => undef,
80
        itemtype     => '*',
80
        itemtype     => undef,
81
        rules        => {
81
        rules        => {
82
            maxissueqty       => 2,
82
            maxissueqty       => 2,
83
            maxonsiteissueqty => 1,
83
            maxonsiteissueqty => 1,
84
            branchcode        => $branch->{branchcode},
85
            categorycode      => '*',
86
            itemtype          => '*',
87
            lengthunit        => 'days',
84
            lengthunit        => 'days',
88
            issuelength       => 5,
85
            issuelength       => 5,
89
        }
86
        }
Lines 150-157 Koha::CirculationRules->search()->delete(); Link Here
150
Koha::CirculationRules->set_rules(
147
Koha::CirculationRules->set_rules(
151
    {
148
    {
152
        branchcode   => $branch->{branchcode},
149
        branchcode   => $branch->{branchcode},
153
        categorycode => '*',
150
        categorycode => undef,
154
        itemtype     => '*',
151
        itemtype     => undef,
155
        rules        => {
152
        rules        => {
156
            maxissueqty       => 2,
153
            maxissueqty       => 2,
157
            maxonsiteissueqty => 1,
154
            maxonsiteissueqty => 1,
(-)a/t/db_dependent/Circulation/TooMany.t (-4 / +4 lines)
Lines 106-112 subtest '1 Issuingrule exist 0 0: no issue allowed' => sub { Link Here
106
        {
106
        {
107
            branchcode   => $branch->{branchcode},
107
            branchcode   => $branch->{branchcode},
108
            categorycode => $category->{categorycode},
108
            categorycode => $category->{categorycode},
109
            itemtype     => '*',
109
            itemtype     => undef,
110
            rules        => {
110
            rules        => {
111
                maxissueqty       => 0,
111
                maxissueqty       => 0,
112
                maxonsiteissueqty => 0,
112
                maxonsiteissueqty => 0,
Lines 162-168 subtest '1 Issuingrule exist 1 1: issue is allowed' => sub { Link Here
162
        {
162
        {
163
            branchcode   => $branch->{branchcode},
163
            branchcode   => $branch->{branchcode},
164
            categorycode => $category->{categorycode},
164
            categorycode => $category->{categorycode},
165
            itemtype     => '*',
165
            itemtype     => undef,
166
            rules        => {
166
            rules        => {
167
                maxissueqty       => 1,
167
                maxissueqty       => 1,
168
                maxonsiteissueqty => 1,
168
                maxonsiteissueqty => 1,
Lines 202-208 subtest '1 Issuingrule exist: 1 CO allowed, 1 OSCO allowed. Do a CO' => sub { Link Here
202
        {
202
        {
203
            branchcode   => $branch->{branchcode},
203
            branchcode   => $branch->{branchcode},
204
            categorycode => $category->{categorycode},
204
            categorycode => $category->{categorycode},
205
            itemtype     => '*',
205
            itemtype     => undef,
206
            rules        => {
206
            rules        => {
207
                maxissueqty       => 1,
207
                maxissueqty       => 1,
208
                maxonsiteissueqty => 1,
208
                maxonsiteissueqty => 1,
Lines 258-264 subtest '1 Issuingrule exist: 1 CO allowed, 1 OSCO allowed, Do a OSCO' => sub { Link Here
258
        {
258
        {
259
            branchcode   => $branch->{branchcode},
259
            branchcode   => $branch->{branchcode},
260
            categorycode => $category->{categorycode},
260
            categorycode => $category->{categorycode},
261
            itemtype     => '*',
261
            itemtype     => undef,
262
            rules        => {
262
            rules        => {
263
                maxissueqty       => 1,
263
                maxissueqty       => 1,
264
                maxonsiteissueqty => 1,
264
                maxonsiteissueqty => 1,
(-)a/t/db_dependent/Circulation/issue.t (-6 / +6 lines)
Lines 290-298 is_deeply( Link Here
290
# Add a default rule: No renewal allowed
290
# Add a default rule: No renewal allowed
291
Koha::CirculationRules->set_rules(
291
Koha::CirculationRules->set_rules(
292
    {
292
    {
293
        categorycode => '*',
293
        categorycode => undef,
294
        itemtype     => '*',
294
        itemtype     => undef,
295
        branchcode   => '*',
295
        branchcode   => undef,
296
        rules        => {
296
        rules        => {
297
            issuelength     => 10,
297
            issuelength     => 10,
298
            renewalsallowed => 0,
298
            renewalsallowed => 0,
Lines 321-329 is_deeply( Link Here
321
# Add a default rule: renewal is allowed
321
# Add a default rule: renewal is allowed
322
Koha::CirculationRules->set_rules(
322
Koha::CirculationRules->set_rules(
323
    {
323
    {
324
        categorycode => '*',
324
        categorycode => undef,
325
        itemtype     => '*',
325
        itemtype     => undef,
326
        branchcode   => '*',
326
        branchcode   => undef,
327
        rules        => {
327
        rules        => {
328
            renewalsallowed => 3,
328
            renewalsallowed => 3,
329
        }
329
        }
(-)a/t/db_dependent/DecreaseLoanHighHolds.t (-3 / +4 lines)
Lines 90-102 for my $i ( 0 .. 5 ) { Link Here
90
90
91
Koha::CirculationRules->set_rules(
91
Koha::CirculationRules->set_rules(
92
    {
92
    {
93
        branchcode   => '*',
93
        branchcode   => undef,
94
        categorycode => '*',
94
        categorycode => undef,
95
        itemtype     => '*',
95
        itemtype     => undef,
96
        rules        => {
96
        rules        => {
97
            issuelength     => '14',
97
            issuelength     => '14',
98
            lengthunit      => 'days',
98
            lengthunit      => 'days',
99
            reservesallowed => '99',
99
            reservesallowed => '99',
100
            holds_per_record => '99',
100
        }
101
        }
101
    }
102
    }
102
);
103
);
(-)a/t/db_dependent/Fines.t (-7 / +7 lines)
Lines 20-28 $dbh->do(q|DELETE FROM circulation_rules|); Link Here
20
20
21
my $issuingrule = Koha::CirculationRules->set_rules(
21
my $issuingrule = Koha::CirculationRules->set_rules(
22
    {
22
    {
23
        categorycode => '*',
23
        categorycode => undef,
24
        itemtype     => '*',
24
        itemtype     => undef,
25
        branchcode   => '*',
25
        branchcode   => undef,
26
        rules        => {
26
        rules        => {
27
            fine                   => 1,
27
            fine                   => 1,
28
            finedays               => 0,
28
            finedays               => 0,
Lines 47-57 $period_end = dt_from_string('2000-01-10'); Link Here
47
is( $fine, 1, '9 days overdue, charge period 7 days, charge at end of interval gives fine of $1' );
47
is( $fine, 1, '9 days overdue, charge period 7 days, charge at end of interval gives fine of $1' );
48
48
49
# Test charging fine at the *beginning* of each charge period
49
# Test charging fine at the *beginning* of each charge period
50
my $issuingrule = Koha::CirculationRules->set_rules(
50
$issuingrule = Koha::CirculationRules->set_rules(
51
    {
51
    {
52
        categorycode => '*',
52
        categorycode => undef,
53
        itemtype     => '*',
53
        itemtype     => undef,
54
        branchcode   => '*',
54
        branchcode   => undef,
55
        rules        => {
55
        rules        => {
56
            chargeperiod_charge_at => 1,
56
            chargeperiod_charge_at => 1,
57
        }
57
        }
(-)a/t/db_dependent/Holds.t (-18 / +15 lines)
Lines 235-243 my ($foreign_item_bibnum, $foreign_item_bibitemnum, $foreign_itemnumber) Link Here
235
$dbh->do('DELETE FROM circulation_rules');
235
$dbh->do('DELETE FROM circulation_rules');
236
Koha::CirculationRules->set_rules(
236
Koha::CirculationRules->set_rules(
237
    {
237
    {
238
        categorycode => '*',
238
        categorycode => undef,
239
        branchcode   => '*',
239
        branchcode   => undef,
240
        itemtype     => '*',
240
        itemtype     => undef,
241
        rules        => {
241
        rules        => {
242
            reservesallowed  => 25,
242
            reservesallowed  => 25,
243
            holds_per_record => 99,
243
            holds_per_record => 99,
Lines 246-253 Koha::CirculationRules->set_rules( Link Here
246
);
246
);
247
Koha::CirculationRules->set_rules(
247
Koha::CirculationRules->set_rules(
248
    {
248
    {
249
        categorycode => '*',
249
        categorycode => undef,
250
        branchcode   => '*',
250
        branchcode   => undef,
251
        itemtype     => 'CANNOT',
251
        itemtype     => 'CANNOT',
252
        rules        => {
252
        rules        => {
253
            reservesallowed  => 0,
253
            reservesallowed  => 0,
Lines 353-361 ok( Link Here
353
$dbh->do('DELETE FROM circulation_rules');
353
$dbh->do('DELETE FROM circulation_rules');
354
Koha::CirculationRules->set_rules(
354
Koha::CirculationRules->set_rules(
355
    {
355
    {
356
        categorycode => '*',
356
        categorycode => undef,
357
        branchcode   => '*',
357
        branchcode   => undef,
358
        itemtype     => '*',
358
        itemtype     => undef,
359
        rules        => {
359
        rules        => {
360
            reservesallowed  => 25,
360
            reservesallowed  => 25,
361
            holds_per_record => 99,
361
            holds_per_record => 99,
Lines 366-372 Koha::CirculationRules->set_rules( Link Here
366
    {
366
    {
367
        branchcode => $branch_1,
367
        branchcode => $branch_1,
368
        itemtype   => 'CANNOT',
368
        itemtype   => 'CANNOT',
369
        categorycode => undef,
370
        rules => {
369
        rules => {
371
            holdallowed => 0,
370
            holdallowed => 0,
372
            returnbranch => 'homebranch',
371
            returnbranch => 'homebranch',
Lines 377-383 Koha::CirculationRules->set_rules( Link Here
377
    {
376
    {
378
        branchcode => $branch_1,
377
        branchcode => $branch_1,
379
        itemtype   => 'CAN',
378
        itemtype   => 'CAN',
380
        categorycode => undef,
381
        rules => {
379
        rules => {
382
            holdallowed => 1,
380
            holdallowed => 1,
383
            returnbranch => 'homebranch',
381
            returnbranch => 'homebranch',
Lines 416-423 $dbh->do('DELETE FROM biblio'); Link Here
416
414
417
Koha::CirculationRules->set_rules(
415
Koha::CirculationRules->set_rules(
418
    {
416
    {
419
        categorycode => '*',
417
        categorycode => undef,
420
        branchcode   => '*',
418
        branchcode   => undef,
421
        itemtype     => 'ONLY1',
419
        itemtype     => 'ONLY1',
422
        rules        => {
420
        rules        => {
423
            reservesallowed  => 1,
421
            reservesallowed  => 1,
Lines 439-453 subtest 'Test max_holds per library/patron category' => sub { Link Here
439
    $dbh->do('DELETE FROM reserves');
437
    $dbh->do('DELETE FROM reserves');
440
    $dbh->do('DELETE FROM circulation_rules');
438
    $dbh->do('DELETE FROM circulation_rules');
441
439
442
    ( $bibnum, $title, $bibitemnum ) = create_helper_biblio('TEST');
440
    my $testitemtype = $builder->build({ source => 'Itemtype' })->{itemtype};
441
    ( $bibnum, $title, $bibitemnum ) = create_helper_biblio($testitemtype);
443
    ( $item_bibnum, $item_bibitemnum, $itemnumber ) =
442
    ( $item_bibnum, $item_bibitemnum, $itemnumber ) =
444
      AddItem( { homebranch => $branch_1, holdingbranch => $branch_1 },
443
      AddItem( { homebranch => $branch_1, holdingbranch => $branch_1 },
445
        $bibnum );
444
        $bibnum );
446
    Koha::CirculationRules->set_rules(
445
    Koha::CirculationRules->set_rules(
447
        {
446
        {
448
            categorycode => '*',
447
            categorycode => undef,
449
            branchcode   => '*',
448
            branchcode   => undef,
450
            itemtype     => 'TEST',
449
            itemtype     => $testitemtype,
451
            rules        => {
450
            rules        => {
452
                reservesallowed  => 99,
451
                reservesallowed  => 99,
453
                holds_per_record => 99,
452
                holds_per_record => 99,
Lines 469-475 subtest 'Test max_holds per library/patron category' => sub { Link Here
469
        {
468
        {
470
            categorycode => $category->{categorycode},
469
            categorycode => $category->{categorycode},
471
            branchcode   => undef,
470
            branchcode   => undef,
472
            itemtype     => undef,
473
            rule_name    => 'max_holds',
471
            rule_name    => 'max_holds',
474
            rule_value   => 3,
472
            rule_value   => 3,
475
        }
473
        }
Lines 479-485 subtest 'Test max_holds per library/patron category' => sub { Link Here
479
        {
477
        {
480
            branchcode   => $branch_1,
478
            branchcode   => $branch_1,
481
            categorycode => $category->{categorycode},
479
            categorycode => $category->{categorycode},
482
            itemtype     => undef,
483
            rule_name    => 'max_holds',
480
            rule_name    => 'max_holds',
484
            rule_value   => 5,
481
            rule_value   => 5,
485
        }
482
        }
(-)a/t/db_dependent/Holds/DisallowHoldIfItemsAvailable.t (-3 / +3 lines)
Lines 89-97 my $item2 = GetItem( $itemnumber2 ); Link Here
89
$dbh->do("DELETE FROM circulation_rules");
89
$dbh->do("DELETE FROM circulation_rules");
90
Koha::CirculationRules->set_rules(
90
Koha::CirculationRules->set_rules(
91
    {
91
    {
92
        categorycode => '*',
92
        categorycode => undef,
93
        itemtype     => '*',
93
        itemtype     => undef,
94
        branchcode   => '*',
94
        branchcode   => undef,
95
        rules        => {
95
        rules        => {
96
            issuelength     => 7,
96
            issuelength     => 7,
97
            lengthunit      => 8,
97
            lengthunit      => 8,
(-)a/t/db_dependent/Holds/HoldFulfillmentPolicy.t (-3 lines)
Lines 74-80 my $itemnumber = Link Here
74
$dbh->do("DELETE FROM circulation_rules");
74
$dbh->do("DELETE FROM circulation_rules");
75
Koha::CirculationRules->set_rules(
75
Koha::CirculationRules->set_rules(
76
    {
76
    {
77
        categorycode => undef,
78
        branchcode   => undef,
77
        branchcode   => undef,
79
        itemtype     => undef,
78
        itemtype     => undef,
80
        rules        => {
79
        rules        => {
Lines 106-112 Koha::Holds->find( $reserve_id )->cancel; Link Here
106
$dbh->do("DELETE FROM circulation_rules");
105
$dbh->do("DELETE FROM circulation_rules");
107
Koha::CirculationRules->set_rules(
106
Koha::CirculationRules->set_rules(
108
    {
107
    {
109
        categorycode => undef,
110
        branchcode   => undef,
108
        branchcode   => undef,
111
        itemtype     => undef,
109
        itemtype     => undef,
112
        rules        => {
110
        rules        => {
Lines 138-144 Koha::Holds->find( $reserve_id )->cancel; Link Here
138
$dbh->do("DELETE FROM circulation_rules");
136
$dbh->do("DELETE FROM circulation_rules");
139
Koha::CirculationRules->set_rules(
137
Koha::CirculationRules->set_rules(
140
    {
138
    {
141
        categorycode => undef,
142
        branchcode   => undef,
139
        branchcode   => undef,
143
        itemtype     => undef,
140
        itemtype     => undef,
144
        rules        => {
141
        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 293-299 Koha::CirculationRules->set_rule( Link Here
293
        rule_name    => 'holdallowed',
293
        rule_name    => 'holdallowed',
294
        rule_value   => 1,
294
        rule_value   => 1,
295
        branchcode   => undef,
295
        branchcode   => undef,
296
        categorycode => undef,
297
        itemtype     => undef,
296
        itemtype     => undef,
298
    }
297
    }
299
);
298
);
Lines 331-337 Koha::CirculationRules->set_rule( Link Here
331
        rule_name    => 'holdallowed',
330
        rule_name    => 'holdallowed',
332
        rule_value   => 2,
331
        rule_value   => 2,
333
        branchcode   => undef,
332
        branchcode   => undef,
334
        categorycode => undef,
335
        itemtype     => undef,
333
        itemtype     => undef,
336
    }
334
    }
337
);
335
);
Lines 359-365 Koha::CirculationRules->set_rule( Link Here
359
        rule_name    => 'holdallowed',
357
        rule_name    => 'holdallowed',
360
        rule_value   => 2,
358
        rule_value   => 2,
361
        branchcode   => undef,
359
        branchcode   => undef,
362
        categorycode => undef,
363
        itemtype     => undef,
360
        itemtype     => undef,
364
    }
361
    }
365
);
362
);
Lines 479-485 Koha::CirculationRules->set_rules( Link Here
479
    {
476
    {
480
        branchcode   => $library_A,
477
        branchcode   => $library_A,
481
        itemtype     => $itemtype,
478
        itemtype     => $itemtype,
482
        categorycode => undef,
483
        rules        => {
479
        rules        => {
484
            holdallowed  => 2,
480
            holdallowed  => 2,
485
            returnbranch => 'homebranch',
481
            returnbranch => 'homebranch',
Lines 578-584 Koha::CirculationRules->set_rules( Link Here
578
    {
574
    {
579
        branchcode   => undef,
575
        branchcode   => undef,
580
        itemtype     => undef,
576
        itemtype     => undef,
581
        categorycode => undef,
582
        rules        => {
577
        rules        => {
583
            holdallowed             => 2,
578
            holdallowed             => 2,
584
            hold_fulfillment_policy => 'homebranch',
579
            hold_fulfillment_policy => 'homebranch',
Lines 613-619 Koha::CirculationRules->set_rules( Link Here
613
    {
608
    {
614
        branchcode   => undef,
609
        branchcode   => undef,
615
        itemtype     => undef,
610
        itemtype     => undef,
616
        categorycode => undef,
617
        rules        => {
611
        rules        => {
618
            holdallowed             => 2,
612
            holdallowed             => 2,
619
            hold_fulfillment_policy => 'holdingbranch',
613
            hold_fulfillment_policy => 'holdingbranch',
Lines 648-654 Koha::CirculationRules->set_rules( Link Here
648
    {
642
    {
649
        branchcode   => undef,
643
        branchcode   => undef,
650
        itemtype     => undef,
644
        itemtype     => undef,
651
        categorycode => undef,
652
        rules        => {
645
        rules        => {
653
            holdallowed             => 2,
646
            holdallowed             => 2,
654
            hold_fulfillment_policy => 'any',
647
            hold_fulfillment_policy => 'any',
Lines 716-722 Koha::CirculationRules->set_rules( Link Here
716
    {
709
    {
717
        branchcode   => undef,
710
        branchcode   => undef,
718
        itemtype     => undef,
711
        itemtype     => undef,
719
        categorycode => undef,
720
        rules        => {
712
        rules        => {
721
            holdallowed             => 2,
713
            holdallowed             => 2,
722
            hold_fulfillment_policy => 'any',
714
            hold_fulfillment_policy => 'any',
(-)a/t/db_dependent/Koha/IssuingRules.t (-58 / +253 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 1;
22
use Test::More tests => 2;
23
use Test::Deep qw( cmp_methods );
24
use Test::Exception;
23
25
24
use Benchmark;
26
use Benchmark;
25
27
Lines 35-49 my $builder = t::lib::TestBuilder->new; Link Here
35
subtest 'get_effective_issuing_rule' => sub {
37
subtest 'get_effective_issuing_rule' => sub {
36
    plan tests => 3;
38
    plan tests => 3;
37
39
38
    my $patron       = $builder->build({ source => 'Borrower' });
40
    my $categorycode = $builder->build({ source => 'Category' })->{'categorycode'};
39
    my $item     = $builder->build({ source => 'Item' });
41
    my $itemtype     = $builder->build({ source => 'Itemtype' })->{'itemtype'};
40
42
    my $branchcode   = $builder->build({ source => 'Branch' })->{'branchcode'};
41
    my $categorycode = $patron->{'categorycode'};
42
    my $itemtype     = $item->{'itype'};
43
    my $branchcode   = $item->{'homebranch'};
44
43
45
    subtest 'Call with undefined values' => sub {
44
    subtest 'Call with undefined values' => sub {
46
        plan tests => 4;
45
        plan tests => 5;
47
46
48
        my $rule;
47
        my $rule;
49
        Koha::CirculationRules->delete;
48
        Koha::CirculationRules->delete;
Lines 58-82 subtest 'get_effective_issuing_rule' => sub { Link Here
58
        is($rule, undef, 'When I attempt to get effective issuing rule by'
57
        is($rule, undef, 'When I attempt to get effective issuing rule by'
59
           .' providing undefined values, then undef is returned.');
58
           .' providing undefined values, then undef is returned.');
60
        ok(Koha::CirculationRule->new({
59
        ok(Koha::CirculationRule->new({
61
            branchcode => '*',
60
            branchcode => undef,
62
            categorycode => '*',
61
            categorycode => undef,
63
            itemtype => '*',
62
            itemtype => undef,
64
            rule_name => 'fine',
63
            rule_name => 'fine',
65
        })->store, 'Given I added an issuing rule branchcode => *,'
64
        })->store, 'Given I added an issuing rule branchcode => undef,'
66
           .' categorycode => *, itemtype => *,');
65
           .' categorycode => undef, itemtype => undef,');
67
        $rule = Koha::CirculationRules->get_effective_rule({
66
        $rule = Koha::CirculationRules->get_effective_rule({
68
            branchcode   => '*',
67
            branchcode   => undef,
69
            categorycode => '*',
68
            categorycode => undef,
70
            itemtype     => '*',
69
            itemtype     => undef,
71
            rule_name    => 'fine',
70
            rule_name    => 'fine',
72
        });
71
        });
73
        ok(_row_match($rule, '*', '*', '*'), 'When I attempt to get effective'
72
        _is_row_match(
73
            $rule,
74
            {
75
                branchcode => undef,
76
                categorycode => undef,
77
                itemtype => undef
78
            },
79
            'When I attempt to get effective'
74
           .' issuing rule by providing undefined values, then the above one is'
80
           .' issuing rule by providing undefined values, then the above one is'
75
           .' returned.');
81
           .' returned.'
82
        );
76
    };
83
    };
77
84
78
    subtest 'Get effective issuing rule in correct order' => sub {
85
    subtest 'Get effective issuing rule in correct order' => sub {
79
        plan tests => 18;
86
        plan tests => 26;
80
87
81
        my $rule;
88
        my $rule;
82
        Koha::CirculationRules->delete;
89
        Koha::CirculationRules->delete;
Lines 91-199 subtest 'get_effective_issuing_rule' => sub { Link Here
91
                        .' is returned.');
98
                        .' is returned.');
92
99
93
        ok(Koha::CirculationRule->new({
100
        ok(Koha::CirculationRule->new({
94
            branchcode => '*',
101
            branchcode => undef,
95
            categorycode => '*',
102
            categorycode => undef,
96
            itemtype => '*',
103
            itemtype => undef,
97
            rule_name => 'fine',
104
            rule_name => 'fine',
98
        })->store, 'Given I added an issuing rule branchcode => *, categorycode => *, itemtype => *,');
105
        })->store, 'Given I added an issuing rule branchcode => undef, categorycode => undef, itemtype => undef,');
99
        $rule = Koha::CirculationRules->get_effective_rule({
106
        $rule = Koha::CirculationRules->get_effective_rule({
100
            branchcode   => $branchcode,
107
            branchcode   => $branchcode,
101
            categorycode => $categorycode,
108
            categorycode => $categorycode,
102
            itemtype     => $itemtype,
109
            itemtype     => $itemtype,
103
            rule_name    => 'fine',
110
            rule_name    => 'fine',
104
        });
111
        });
105
        ok(_row_match($rule, '*', '*', '*'), 'When I attempt to get effective issuing rule,'
112
        _is_row_match(
106
           .' then the above one is returned.');
113
            $rule,
114
            {
115
                branchcode => undef,
116
                categorycode => undef,
117
                itemtype => undef
118
            },
119
            'When I attempt to get effective issuing rule,'
120
           .' then the above one is returned.'
121
        );
107
122
108
        ok(Koha::CirculationRule->new({
123
        ok(Koha::CirculationRule->new({
109
            branchcode => '*',
124
            branchcode => undef,
110
            categorycode => '*',
125
            categorycode => undef,
111
            itemtype => $itemtype,
126
            itemtype => $itemtype,
112
            rule_name => 'fine',
127
            rule_name => 'fine',
113
        })->store, "Given I added an issuing rule branchcode => *, categorycode => *, itemtype => $itemtype,");
128
        })->store, "Given I added an issuing rule branchcode => undef, categorycode => undef, itemtype => $itemtype,");
114
        $rule = Koha::CirculationRules->get_effective_rule({
129
        $rule = Koha::CirculationRules->get_effective_rule({
115
            branchcode   => $branchcode,
130
            branchcode   => $branchcode,
116
            categorycode => $categorycode,
131
            categorycode => $categorycode,
117
            itemtype     => $itemtype,
132
            itemtype     => $itemtype,
118
            rule_name    => 'fine',
133
            rule_name    => 'fine',
119
        });
134
        });
120
        ok(_row_match($rule, '*', '*', $itemtype), 'When I attempt to get effective issuing rule,'
135
        _is_row_match(
121
           .' then the above one is returned.');
136
            $rule,
137
            {
138
                branchcode => undef,
139
                categorycode => undef,
140
                itemtype => $itemtype
141
            },
142
            'When I attempt to get effective issuing rule,'
143
           .' then the above one is returned.'
144
        );
122
145
123
        ok(Koha::CirculationRule->new({
146
        ok(Koha::CirculationRule->new({
124
            branchcode => '*',
147
            branchcode => undef,
125
            categorycode => $categorycode,
148
            categorycode => $categorycode,
126
            itemtype => '*',
149
            itemtype => undef,
127
            rule_name => 'fine',
150
            rule_name => 'fine',
128
        })->store, "Given I added an issuing rule branchcode => *, categorycode => $categorycode, itemtype => *,");
151
        })->store, "Given I added an issuing rule branchcode => undef, categorycode => $categorycode, itemtype => undef,");
129
        $rule = Koha::CirculationRules->get_effective_rule({
152
        $rule = Koha::CirculationRules->get_effective_rule({
130
            branchcode   => $branchcode,
153
            branchcode   => $branchcode,
131
            categorycode => $categorycode,
154
            categorycode => $categorycode,
132
            itemtype     => $itemtype,
155
            itemtype     => $itemtype,
133
            rule_name    => 'fine',
156
            rule_name    => 'fine',
134
        });
157
        });
135
        ok(_row_match($rule, '*', $categorycode, '*'), 'When I attempt to get effective issuing rule,'
158
        _is_row_match(
136
           .' then the above one is returned.');
159
            $rule,
160
            {
161
                branchcode => undef,
162
                categorycode => $categorycode,
163
                itemtype => undef
164
            },
165
            'When I attempt to get effective issuing rule,'
166
           .' then the above one is returned.'
167
        );
137
168
138
        ok(Koha::CirculationRule->new({
169
        ok(Koha::CirculationRule->new({
139
            branchcode => '*',
170
            branchcode => undef,
140
            categorycode => $categorycode,
171
            categorycode => $categorycode,
141
            itemtype => $itemtype,
172
            itemtype => $itemtype,
142
            rule_name => 'fine',
173
            rule_name => 'fine',
143
        })->store, "Given I added an issuing rule branchcode => *, categorycode => $categorycode, itemtype => $itemtype,");
174
        })->store, "Given I added an issuing rule branchcode => undef, categorycode => $categorycode, itemtype => $itemtype,");
144
        $rule = Koha::CirculationRules->get_effective_rule({
175
        $rule = Koha::CirculationRules->get_effective_rule({
145
            branchcode   => $branchcode,
176
            branchcode   => $branchcode,
146
            categorycode => $categorycode,
177
            categorycode => $categorycode,
147
            itemtype     => $itemtype,
178
            itemtype     => $itemtype,
148
            rule_name    => 'fine',
179
            rule_name    => 'fine',
149
        });
180
        });
150
        ok(_row_match($rule, '*', $categorycode, $itemtype), 'When I attempt to get effective issuing rule,'
181
        _is_row_match(
151
           .' then the above one is returned.');
182
            $rule,
183
            {
184
                branchcode => undef,
185
                categorycode => $categorycode,
186
                itemtype => $itemtype
187
            },
188
            'When I attempt to get effective issuing rule,'
189
           .' then the above one is returned.'
190
        );
152
191
153
        ok(Koha::CirculationRule->new({
192
        ok(Koha::CirculationRule->new({
154
            branchcode => $branchcode,
193
            branchcode => $branchcode,
155
            categorycode => '*',
194
            categorycode => undef,
156
            itemtype => '*',
195
            itemtype => undef,
157
            rule_name => 'fine',
196
            rule_name => 'fine',
158
        })->store, "Given I added an issuing rule branchcode => $branchcode, categorycode => '*', itemtype => '*',");
197
        })->store, "Given I added an issuing rule branchcode => $branchcode, categorycode => undef, itemtype => undef,");
159
        $rule = Koha::CirculationRules->get_effective_rule({
198
        $rule = Koha::CirculationRules->get_effective_rule({
160
            branchcode   => $branchcode,
199
            branchcode   => $branchcode,
161
            categorycode => $categorycode,
200
            categorycode => $categorycode,
162
            itemtype     => $itemtype,
201
            itemtype     => $itemtype,
163
            rule_name    => 'fine',
202
            rule_name    => 'fine',
164
        });
203
        });
165
        ok(_row_match($rule, $branchcode, '*', '*'), 'When I attempt to get effective issuing rule,'
204
        _is_row_match(
166
           .' then the above one is returned.');
205
            $rule,
206
            {
207
                branchcode => $branchcode,
208
                categorycode => undef,
209
                itemtype => undef
210
            },
211
            'When I attempt to get effective issuing rule,'
212
           .' then the above one is returned.'
213
        );
167
214
168
        ok(Koha::CirculationRule->new({
215
        ok(Koha::CirculationRule->new({
169
            branchcode => $branchcode,
216
            branchcode => $branchcode,
170
            categorycode => '*',
217
            categorycode => undef,
171
            itemtype => $itemtype,
218
            itemtype => $itemtype,
172
            rule_name => 'fine',
219
            rule_name => 'fine',
173
        })->store, "Given I added an issuing rule branchcode => $branchcode, categorycode => '*', itemtype => $itemtype,");
220
        })->store, "Given I added an issuing rule branchcode => $branchcode, categorycode => undef, itemtype => $itemtype,");
174
        $rule = Koha::CirculationRules->get_effective_rule({
221
        $rule = Koha::CirculationRules->get_effective_rule({
175
            branchcode   => $branchcode,
222
            branchcode   => $branchcode,
176
            categorycode => $categorycode,
223
            categorycode => $categorycode,
177
            itemtype     => $itemtype,
224
            itemtype     => $itemtype,
178
            rule_name    => 'fine',
225
            rule_name    => 'fine',
179
        });
226
        });
180
        ok(_row_match($rule, $branchcode, '*', $itemtype), 'When I attempt to get effective issuing rule,'
227
        _is_row_match(
181
           .' then the above one is returned.');
228
            $rule,
229
            {
230
                branchcode => $branchcode,
231
                categorycode => undef,
232
                itemtype => $itemtype
233
            },
234
            'When I attempt to get effective issuing rule,'
235
           .' then the above one is returned.'
236
        );
182
237
183
        ok(Koha::CirculationRule->new({
238
        ok(Koha::CirculationRule->new({
184
            branchcode => $branchcode,
239
            branchcode => $branchcode,
185
            categorycode => $categorycode,
240
            categorycode => $categorycode,
186
            itemtype => '*',
241
            itemtype => undef,
187
            rule_name => 'fine',
242
            rule_name => 'fine',
188
        })->store, "Given I added an issuing rule branchcode => $branchcode, categorycode => $categorycode, itemtype => '*',");
243
        })->store, "Given I added an issuing rule branchcode => $branchcode, categorycode => $categorycode, itemtype => undef,");
189
        $rule = Koha::CirculationRules->get_effective_rule({
244
        $rule = Koha::CirculationRules->get_effective_rule({
190
            branchcode   => $branchcode,
245
            branchcode   => $branchcode,
191
            categorycode => $categorycode,
246
            categorycode => $categorycode,
192
            itemtype     => $itemtype,
247
            itemtype     => $itemtype,
193
            rule_name    => 'fine',
248
            rule_name    => 'fine',
194
        });
249
        });
195
        ok(_row_match($rule, $branchcode, $categorycode, '*'), 'When I attempt to get effective issuing rule,'
250
        _is_row_match(
196
           .' then the above one is returned.');
251
            $rule,
252
            {
253
                branchcode => $branchcode,
254
                categorycode => $categorycode,
255
                itemtype => undef
256
            },
257
            'When I attempt to get effective issuing rule,'
258
           .' then the above one is returned.'
259
        );
197
260
198
        ok(Koha::CirculationRule->new({
261
        ok(Koha::CirculationRule->new({
199
            branchcode => $branchcode,
262
            branchcode => $branchcode,
Lines 207-214 subtest 'get_effective_issuing_rule' => sub { Link Here
207
            itemtype     => $itemtype,
270
            itemtype     => $itemtype,
208
            rule_name    => 'fine',
271
            rule_name    => 'fine',
209
        });
272
        });
210
        ok(_row_match($rule, $branchcode, $categorycode, $itemtype), 'When I attempt to get effective issuing rule,'
273
        _is_row_match(
211
           .' then the above one is returned.');
274
            $rule,
275
            {
276
                branchcode => $branchcode,
277
                categorycode => $categorycode,
278
                itemtype => $itemtype
279
            },
280
            'When I attempt to get effective issuing rule,'
281
           .' then the above one is returned.'
282
        );
212
    };
283
    };
213
284
214
    subtest 'Performance' => sub {
285
    subtest 'Performance' => sub {
Lines 265-275 subtest 'get_effective_issuing_rule' => sub { Link Here
265
    };
336
    };
266
};
337
};
267
338
268
sub _row_match {
339
subtest 'set_rule' => sub {
269
    my ($rule, $branchcode, $categorycode, $itemtype) = @_;
340
    plan tests => 3;
341
342
    my $branchcode   = $builder->build({ source => 'Branch' })->{'branchcode'};
343
    my $categorycode = $builder->build({ source => 'Category' })->{'categorycode'};
344
    my $itemtype     = $builder->build({ source => 'Itemtype' })->{'itemtype'};
345
346
    subtest 'Correct call' => sub {
347
        plan tests => 4;
348
349
        Koha::CirculationRules->delete;
350
351
        lives_ok( sub {
352
            Koha::CirculationRules->set_rule( {
353
                branchcode => $branchcode,
354
                rule_name => 'refund',
355
                rule_value => '',
356
            } );
357
        }, 'setting refund with branch' );
358
359
        lives_ok( sub {
360
            Koha::CirculationRules->set_rule( {
361
                branchcode => $branchcode,
362
                categorycode => $categorycode,
363
                rule_name => 'patron_maxissueqty',
364
                rule_value => '',
365
            } );
366
        }, 'setting patron_maxissueqty with branch/category succeeds' );
367
368
        lives_ok( sub {
369
            Koha::CirculationRules->set_rule( {
370
                branchcode => $branchcode,
371
                itemtype => $itemtype,
372
                rule_name => 'holdallowed',
373
                rule_value => '',
374
            } );
375
        }, 'setting holdallowed with branch/itemtype succeeds' );
376
377
        lives_ok( sub {
378
            Koha::CirculationRules->set_rule( {
379
                branchcode => $branchcode,
380
                categorycode => $categorycode,
381
                itemtype => $itemtype,
382
                rule_name => 'fine',
383
                rule_value => '',
384
            } );
385
        }, 'setting fine with branch/category/itemtype succeeds' );
386
    };
387
388
    subtest 'Call with missing params' => sub {
389
        plan tests => 4;
390
391
        Koha::CirculationRules->delete;
392
393
        throws_ok( sub {
394
            Koha::CirculationRules->set_rule( {
395
                rule_name => 'refund',
396
                rule_value => '',
397
            } );
398
        }, qr/branchcode/, 'setting refund without branch fails' );
399
400
        throws_ok( sub {
401
            Koha::CirculationRules->set_rule( {
402
                branchcode => $branchcode,
403
                rule_name => 'patron_maxissueqty',
404
                rule_value => '',
405
            } );
406
        }, qr/categorycode/, 'setting patron_maxissueqty without categorycode fails' );
407
408
        throws_ok( sub {
409
            Koha::CirculationRules->set_rule( {
410
                branchcode => $branchcode,
411
                rule_name => 'holdallowed',
412
                rule_value => '',
413
            } );
414
        }, qr/itemtype/, 'setting holdallowed without itemtype fails' );
415
416
        throws_ok( sub {
417
            Koha::CirculationRules->set_rule( {
418
                branchcode => $branchcode,
419
                categorycode => $categorycode,
420
                rule_name => 'fine',
421
                rule_value => '',
422
            } );
423
        }, qr/itemtype/, 'setting fine without itemtype fails' );
424
    };
425
426
    subtest 'Call with extra params' => sub {
427
        plan tests => 3;
428
429
        Koha::CirculationRules->delete;
430
431
        throws_ok( sub {
432
            Koha::CirculationRules->set_rule( {
433
                branchcode => $branchcode,
434
                categorycode => $categorycode,
435
                rule_name => 'refund',
436
                rule_value => '',
437
            } );
438
        }, qr/categorycode/, 'setting refund with categorycode fails' );
439
440
        throws_ok( sub {
441
            Koha::CirculationRules->set_rule( {
442
                branchcode => $branchcode,
443
                categorycode => $categorycode,
444
                itemtype => $itemtype,
445
                rule_name => 'patron_maxissueqty',
446
                rule_value => '',
447
            } );
448
        }, qr/itemtype/, 'setting patron_maxissueqty with itemtype fails' );
449
450
        throws_ok( sub {
451
            Koha::CirculationRules->set_rule( {
452
                branchcode => $branchcode,
453
                rule_name => 'holdallowed',
454
                categorycode => $categorycode,
455
                itemtype => $itemtype,
456
                rule_value => '',
457
            } );
458
        }, qr/categorycode/, 'setting holdallowed with categorycode fails' );
459
    };
460
};
461
462
sub _is_row_match {
463
    my ( $rule, $expected, $message ) = @_;
270
464
271
    return $rule->branchcode eq $branchcode && $rule->categorycode eq $categorycode
465
    ok( $rule, $message ) ?
272
            && $rule->itemtype eq $itemtype;
466
        cmp_methods( $rule, [ %$expected ], $message ) :
467
        fail( $message );
273
}
468
}
274
469
275
$schema->storage->txn_rollback;
470
$schema->storage->txn_rollback;
(-)a/t/db_dependent/RefundLostItemFeeRule.t (-8 / +22 lines)
Lines 47-63 subtest 'Koha::RefundLostItemFeeRule::delete() tests' => sub { Link Here
47
        {
47
        {
48
            source => 'CirculationRule',
48
            source => 'CirculationRule',
49
            value  => {
49
            value  => {
50
                branchcode   => '*',
50
                branchcode   => undef,
51
                categorycode => undef,
51
                categorycode => undef,
52
                itemtype     => undef,
52
                itemtype     => undef,
53
                rule_name    => 'refund',
53
                rule_name    => 'refund',
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 67-73 subtest 'Koha::RefundLostItemFeeRule::delete() tests' => sub { Link Here
67
69
68
    my $default_rule = Koha::CirculationRules->search(
70
    my $default_rule = Koha::CirculationRules->search(
69
        {
71
        {
70
            branchcode   => '*',
72
            branchcode   => undef,
71
            categorycode => undef,
73
            categorycode => undef,
72
            itemtype     => undef,
74
            itemtype     => undef,
73
            rule_name    => 'refund',
75
            rule_name    => 'refund',
Lines 109-115 subtest 'Koha::RefundLostItemFeeRules::_default_rule() tests' => sub { Link Here
109
        {
111
        {
110
            source => 'CirculationRule',
112
            source => 'CirculationRule',
111
            value  => {
113
            value  => {
112
                branchcode   => '*',
114
                branchcode   => undef,
113
                categorycode => undef,
115
                categorycode => undef,
114
                itemtype     => undef,
116
                itemtype     => undef,
115
                rule_name    => 'refund',
117
                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 130-136 subtest 'Koha::RefundLostItemFeeRules::_default_rule() tests' => sub { Link Here
130
134
131
    my $default_rule = Koha::CirculationRules->search(
135
    my $default_rule = Koha::CirculationRules->search(
132
        {
136
        {
133
            branchcode   => '*',
137
            branchcode   => undef,
134
            categorycode => undef,
138
            categorycode => undef,
135
            itemtype     => undef,
139
            itemtype     => undef,
136
            rule_name    => 'refund',
140
            rule_name    => 'refund',
Lines 146-152 subtest 'Koha::RefundLostItemFeeRules::_default_rule() tests' => sub { Link Here
146
    # Re-read from DB, to be sure
150
    # Re-read from DB, to be sure
147
    $default_rule = Koha::CirculationRules->search(
151
    $default_rule = Koha::CirculationRules->search(
148
        {
152
        {
149
            branchcode   => '*',
153
            branchcode   => undef,
150
            categorycode => undef,
154
            categorycode => undef,
151
            itemtype     => undef,
155
            itemtype     => undef,
152
            rule_name    => 'refund',
156
            rule_name    => 'refund',
Lines 177-183 subtest 'Koha::RefundLostItemFeeRules::_effective_branch_rule() tests' => sub { Link Here
177
        {
181
        {
178
            source => 'CirculationRule',
182
            source => 'CirculationRule',
179
            value  => {
183
            value  => {
180
                branchcode   => '*',
184
                branchcode   => undef,
181
                categorycode => undef,
185
                categorycode => undef,
182
                itemtype     => undef,
186
                itemtype     => undef,
183
                rule_name    => 'refund',
187
                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 293-299 subtest 'Koha::RefundLostItemFeeRules::should_refund() tests' => sub { Link Here
293
        {
301
        {
294
            source => 'CirculationRule',
302
            source => 'CirculationRule',
295
            value  => {
303
            value  => {
296
                branchcode   => '*',
304
                branchcode   => undef,
297
                categorycode => undef,
305
                categorycode => undef,
298
                itemtype     => undef,
306
                itemtype     => undef,
299
                rule_name    => 'refund',
307
                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',
Lines 363-369 subtest 'Koha::RefundLostItemFeeRules::should_refund() tests' => sub { Link Here
363
         1,'No rule for branch, global rule applied (true)');
377
         1,'No rule for branch, global rule applied (true)');
364
378
365
    # Change the default value just to try
379
    # Change the default value just to try
366
    Koha::CirculationRules->search({ branchcode => '*', rule_name => 'refund' })->next->rule_value(0)->store;
380
    Koha::CirculationRules->search({ branchcode => undef, rule_name => 'refund' })->next->rule_value(0)->store;
367
    t::lib::Mocks::mock_preference( 'RefundLostOnReturnControl', 'ItemHoldingBranch' );
381
    t::lib::Mocks::mock_preference( 'RefundLostOnReturnControl', 'ItemHoldingBranch' );
368
    is( Koha::RefundLostItemFeeRules->should_refund( $params ),
382
    is( Koha::RefundLostItemFeeRules->should_refund( $params ),
369
         0,'No rule for branch, global rule applied (false)');
383
         0,'No rule for branch, global rule applied (false)');
(-)a/t/db_dependent/Reserves.t (-5 / +3 lines)
Lines 201-209 $requesters{$branch_3} = AddMember( Link Here
201
$dbh->do('DELETE FROM circulation_rules');
201
$dbh->do('DELETE FROM circulation_rules');
202
Koha::CirculationRules->set_rules(
202
Koha::CirculationRules->set_rules(
203
    {
203
    {
204
        branchcode   => '*',
204
        branchcode   => undef,
205
        categorycode => '*',
205
        categorycode => undef,
206
        itemtype     => '*',
206
        itemtype     => undef,
207
        rules        => {
207
        rules        => {
208
            reservesallowed => 25,
208
            reservesallowed => 25,
209
            holds_per_record => 1,
209
            holds_per_record => 1,
Lines 215-221 Koha::CirculationRules->set_rules( Link Here
215
Koha::CirculationRules->set_rules(
215
Koha::CirculationRules->set_rules(
216
    {
216
    {
217
        branchcode   => $branch_1,
217
        branchcode   => $branch_1,
218
        categorycode => undef,
219
        itemtype     => undef,
218
        itemtype     => undef,
220
        rules        => {
219
        rules        => {
221
            holdallowed  => 1,
220
            holdallowed  => 1,
Lines 228-234 Koha::CirculationRules->set_rules( Link Here
228
Koha::CirculationRules->set_rules(
227
Koha::CirculationRules->set_rules(
229
    {
228
    {
230
        branchcode   => $branch_2,
229
        branchcode   => $branch_2,
231
        categorycode => undef,
232
        itemtype     => undef,
230
        itemtype     => undef,
233
        rules        => {
231
        rules        => {
234
            holdallowed  => 2,
232
            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 351-362 subtest 'build_object() tests' => sub { Link Here
351
351
352
    $builder = t::lib::TestBuilder->new();
352
    $builder = t::lib::TestBuilder->new();
353
353
354
    my $branchcode = $builder->build( { source => 'Branch' } )->{branchcode};
354
    my $categorycode = $builder->build( { source => 'Category' } )->{categorycode};
355
    my $categorycode = $builder->build( { source => 'Category' } )->{categorycode};
355
    my $itemtype = $builder->build( { source => 'Itemtype' } )->{itemtype};
356
    my $itemtype = $builder->build( { source => 'Itemtype' } )->{itemtype};
356
357
357
    my $issuing_rule = $builder->build_object(
358
    my $issuing_rule = $builder->build_object(
358
        {   class => 'Koha::CirculationRules',
359
        {   class => 'Koha::CirculationRules',
359
            value => {
360
            value => {
361
                branchcode   => $branchcode,
360
                categorycode => $categorycode,
362
                categorycode => $categorycode,
361
                itemtype     => $itemtype
363
                itemtype     => $itemtype
362
            }
364
            }
(-)a/t/db_dependent/api/v1/holds.t (-4 / +3 lines)
Lines 133-141 $dbh->do('DELETE FROM reserves'); Link Here
133
Koha::CirculationRules->search()->delete();
133
Koha::CirculationRules->search()->delete();
134
Koha::CirculationRules->set_rules(
134
Koha::CirculationRules->set_rules(
135
    {
135
    {
136
        categorycode => '*',
136
        categorycode => undef,
137
        branchcode   => '*',
137
        branchcode   => undef,
138
        itemtype     => '*',
138
        itemtype     => undef,
139
        rules        => {
139
        rules        => {
140
            reservesallowed => 1,
140
            reservesallowed => 1,
141
            holds_per_record => 99
141
            holds_per_record => 99
142
- 

Return to bug 18936