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

(-)a/C4/Circulation.pm (-16 / +16 lines)
Lines 414-420 sub TooMany { Link Here
414
        |;
414
        |;
415
415
416
        my $rule_itemtype = $maxissueqty_rule->itemtype;
416
        my $rule_itemtype = $maxissueqty_rule->itemtype;
417
        if ($rule_itemtype eq "*") {
417
        if (!defined $rule_itemtype) {
418
            # matching rule has the default item type, so count only
418
            # matching rule has the default item type, so count only
419
            # those existing loans that don't fall under a more
419
            # those existing loans that don't fall under a more
420
            # specific rule
420
            # specific rule
Lines 423-429 sub TooMany { Link Here
423
                                    SELECT itemtype FROM circulation_rules
423
                                    SELECT itemtype FROM circulation_rules
424
                                    WHERE branchcode = ?
424
                                    WHERE branchcode = ?
425
                                    AND   (categorycode = ? OR categorycode = ?)
425
                                    AND   (categorycode = ? OR categorycode = ?)
426
                                    AND   itemtype <> '*'
426
                                    AND   itemtype IS NOT NULL
427
                                    AND   rule_name = 'maxissueqty'
427
                                    AND   rule_name = 'maxissueqty'
428
                                  ) ";
428
                                  ) ";
429
            } else {
429
            } else {
Lines 432-438 sub TooMany { Link Here
432
                                    SELECT itemtype FROM circulation_rules
432
                                    SELECT itemtype FROM circulation_rules
433
                                    WHERE branchcode = ?
433
                                    WHERE branchcode = ?
434
                                    AND   (categorycode = ? OR categorycode = ?)
434
                                    AND   (categorycode = ? OR categorycode = ?)
435
                                    AND   itemtype <> '*'
435
                                    AND   itemtype IS NOT NULL
436
                                    AND   rule_name = 'maxissueqty'
436
                                    AND   rule_name = 'maxissueqty'
437
                                  ) ";
437
                                  ) ";
438
            }
438
            }
Lines 454-460 sub TooMany { Link Here
454
        $count_query .= " AND borrowernumber = ? ";
454
        $count_query .= " AND borrowernumber = ? ";
455
        push @bind_params, $borrower->{'borrowernumber'};
455
        push @bind_params, $borrower->{'borrowernumber'};
456
        my $rule_branch = $maxissueqty_rule->branchcode;
456
        my $rule_branch = $maxissueqty_rule->branchcode;
457
        if ($rule_branch ne "*") {
457
        if (defined $rule_branch) {
458
            if (C4::Context->preference('CircControl') eq 'PickupLibrary') {
458
            if (C4::Context->preference('CircControl') eq 'PickupLibrary') {
459
                $count_query .= " AND issues.branchcode = ? ";
459
                $count_query .= " AND issues.branchcode = ? ";
460
                push @bind_params, $branch;
460
                push @bind_params, $branch;
Lines 1485-1522 sub GetLoanLength { Link Here
1485
        },
1485
        },
1486
        {
1486
        {
1487
            categorycode => $categorycode,
1487
            categorycode => $categorycode,
1488
            itemtype     => '*',
1488
            itemtype     => undef,
1489
            branchcode   => $branchcode,
1489
            branchcode   => $branchcode,
1490
        },
1490
        },
1491
        {
1491
        {
1492
            categorycode => '*',
1492
            categorycode => undef,
1493
            itemtype     => $itemtype,
1493
            itemtype     => $itemtype,
1494
            branchcode   => $branchcode,
1494
            branchcode   => $branchcode,
1495
        },
1495
        },
1496
        {
1496
        {
1497
            categorycode => '*',
1497
            categorycode => undef,
1498
            itemtype     => '*',
1498
            itemtype     => undef,
1499
            branchcode   => $branchcode,
1499
            branchcode   => $branchcode,
1500
        },
1500
        },
1501
        {
1501
        {
1502
            categorycode => $categorycode,
1502
            categorycode => $categorycode,
1503
            itemtype     => $itemtype,
1503
            itemtype     => $itemtype,
1504
            branchcode   => '*',
1504
            branchcode   => undef,
1505
        },
1505
        },
1506
        {
1506
        {
1507
            categorycode => $categorycode,
1507
            categorycode => $categorycode,
1508
            itemtype     => '*',
1508
            itemtype     => undef,
1509
            branchcode   => '*',
1509
            branchcode   => undef,
1510
        },
1510
        },
1511
        {
1511
        {
1512
            categorycode => '*',
1512
            categorycode => undef,
1513
            itemtype     => $itemtype,
1513
            itemtype     => $itemtype,
1514
            branchcode   => '*',
1514
            branchcode   => undef,
1515
        },
1515
        },
1516
        {
1516
        {
1517
            categorycode => '*',
1517
            categorycode => undef,
1518
            itemtype     => '*',
1518
            itemtype     => undef,
1519
            branchcode   => '*',
1519
            branchcode   => undef,
1520
        },
1520
        },
1521
    );
1521
    );
1522
1522
(-)a/C4/Reserves.pm (-15 / +6 lines)
Lines 352-358 sub CanItemBeReserved { Link Here
352
        $holds_per_record = $rights->{holds_per_record};
352
        $holds_per_record = $rights->{holds_per_record};
353
    }
353
    }
354
    else {
354
    else {
355
        $ruleitemtype = '*';
355
        $ruleitemtype = undef;
356
    }
356
    }
357
357
358
    $item = Koha::Items->find( $itemnumber );
358
    $item = Koha::Items->find( $itemnumber );
Lines 377-391 sub CanItemBeReserved { Link Here
377
      C4::Context->preference('item-level_itypes')
377
      C4::Context->preference('item-level_itypes')
378
      ? " AND COALESCE( items.itype, biblioitems.itemtype ) = ?"
378
      ? " AND COALESCE( items.itype, biblioitems.itemtype ) = ?"
379
      : " AND biblioitems.itemtype = ?"
379
      : " AND biblioitems.itemtype = ?"
380
      if ( $ruleitemtype ne "*" );
380
      if defined $ruleitemtype;
381
381
382
    my $sthcount = $dbh->prepare($querycount);
382
    my $sthcount = $dbh->prepare($querycount);
383
383
384
    if ( $ruleitemtype eq "*" ) {
384
    if ( defined $ruleitemtype ) {
385
        $sthcount->execute( $borrowernumber, $branchcode );
385
        $sthcount->execute( $borrowernumber, $branchcode, $ruleitemtype );
386
    }
386
    }
387
    else {
387
    else {
388
        $sthcount->execute( $borrowernumber, $branchcode, $ruleitemtype );
388
        $sthcount->execute( $borrowernumber, $branchcode );
389
    }
389
    }
390
390
391
    my $reservecount = "0";
391
    my $reservecount = "0";
Lines 399-417 sub CanItemBeReserved { Link Here
399
    }
399
    }
400
400
401
    # Now we need to check hold limits by patron category
401
    # Now we need to check hold limits by patron category
402
    my $rule = Koha::CirculationRules->find(
402
    my $rule = Koha::CirculationRules->get_effective_rule(
403
        {
403
        {
404
            categorycode => $borrower->{categorycode},
405
            branchcode   => $borrower->{branchcode},
404
            branchcode   => $borrower->{branchcode},
406
            itemtype     => undef,
407
            rule_name    => 'max_holds',
408
        }
409
    );
410
    $rule ||= Koha::CirculationRules->find(
411
        {
412
            categorycode => $borrower->{categorycode},
405
            categorycode => $borrower->{categorycode},
413
            branchcode   => undef,,
414
            itemtype     => undef,
415
            rule_name    => 'max_holds',
406
            rule_name    => 'max_holds',
416
        }
407
        }
417
    );
408
    );
(-)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 (+15 lines)
Lines 338-343 __PACKAGE__->has_many( Link Here
338
  { cascade_copy => 0, cascade_delete => 0 },
338
  { cascade_copy => 0, cascade_delete => 0 },
339
);
339
);
340
340
341
=head2 circulation_rules
342
343
Type: has_many
344
345
Related object: L<Koha::Schema::Result::CirculationRule>
346
347
=cut
348
349
__PACKAGE__->has_many(
350
  "circulation_rules",
351
  "Koha::Schema::Result::CirculationRule",
352
  { "foreign.branchcode" => "self.branchcode" },
353
  { cascade_copy => 0, cascade_delete => 0 },
354
);
355
341
=head2 club_enrollments
356
=head2 club_enrollments
342
357
343
Type: has_many
358
Type: has_many
(-)a/Koha/Schema/Result/Category.pm (+15 lines)
Lines 236-241 __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
240
241
Type: has_many
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
239
254
240
# Created by DBIx::Class::Schema::Loader v0.07042 @ 2018-02-16 17:54:53
255
# Created by DBIx::Class::Schema::Loader v0.07042 @ 2018-02-16 17:54:53
241
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:TGAiiFICSjlKNvnfa87kFQ
256
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:TGAiiFICSjlKNvnfa87kFQ
(-)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 (+15 lines)
Lines 165-170 __PACKAGE__->has_many( Link Here
165
  { cascade_copy => 0, cascade_delete => 0 },
165
  { cascade_copy => 0, cascade_delete => 0 },
166
);
166
);
167
167
168
=head2 circulation_rules
169
170
Type: has_many
171
172
Related object: L<Koha::Schema::Result::CirculationRule>
173
174
=cut
175
176
__PACKAGE__->has_many(
177
  "circulation_rules",
178
  "Koha::Schema::Result::CirculationRule",
179
  { "foreign.itemtype" => "self.itemtype" },
180
  { cascade_copy => 0, cascade_delete => 0 },
181
);
182
168
=head2 default_branch_item_rule
183
=head2 default_branch_item_rule
169
184
170
Type: might_have
185
Type: might_have
(-)a/admin/smart-rules.pl (-77 / +79 lines)
Lines 69-77 if ($op eq 'delete') { Link Here
69
69
70
    Koha::CirculationRules->set_rules(
70
    Koha::CirculationRules->set_rules(
71
        {
71
        {
72
            categorycode => $categorycode,
72
            categorycode => $categorycode eq '*' ? undef : $categorycode,
73
            branchcode   => $branch,
73
            branchcode   => $branch eq '*' ? undef : $branch,
74
            itemtype     => $itemtype,
74
            itemtype     => $itemtype eq '*' ? undef : $itemtype,
75
            rules        => {
75
            rules        => {
76
                restrictedtype                   => undef,
76
                restrictedtype                   => undef,
77
                rentaldiscount                   => undef,
77
                rentaldiscount                   => undef,
Lines 107-149 elsif ($op eq 'delete-branch-cat') { Link Here
107
    my $categorycode  = $input->param('categorycode');
107
    my $categorycode  = $input->param('categorycode');
108
    if ($branch eq "*") {
108
    if ($branch eq "*") {
109
        if ($categorycode eq "*") {
109
        if ($categorycode eq "*") {
110
             Koha::CirculationRules->set_rules(
110
            Koha::CirculationRules->set_rules(
111
                 {
111
                {
112
                     categorycode => undef,
112
                    branchcode   => undef,
113
                     branchcode   => undef,
113
                    categorycode => undef,
114
                     itemtype     => undef,
114
                    rules        => {
115
                     rules        => {
115
                        patron_maxissueqty             => undef,
116
                         patron_maxissueqty             => undef,
116
                        patron_maxonsiteissueqty       => undef,
117
                         patron_maxonsiteissueqty       => undef,
117
                    }
118
                         holdallowed             => undef,
118
                }
119
                         hold_fulfillment_policy => undef,
119
            );
120
                         returnbranch            => undef,
120
            Koha::CirculationRules->set_rules(
121
                     }
121
                {
122
                 }
122
                    branchcode   => undef,
123
             );
123
                    itemtype     => undef,
124
         } else {
124
                    rules        => {
125
             Koha::CirculationRules->set_rules(
125
                        holdallowed             => undef,
126
                 {
126
                        hold_fulfillment_policy => undef,
127
                     categorycode => $categorycode,
127
                        returnbranch            => undef,
128
                     branchcode   => undef,
128
                    }
129
                     itemtype     => undef,
129
                }
130
                     rules        => {
130
            );
131
                         max_holds         => undef,
131
        } else {
132
                         patron_maxissueqty       => undef,
132
            Koha::CirculationRules->set_rules(
133
                         patron_maxonsiteissueqty => undef,
133
                {
134
                     }
134
                    categorycode => $categorycode,
135
                 }
135
                    branchcode   => undef,
136
             );
136
                    rules        => {
137
                        max_holds         => undef,
138
                        patron_maxissueqty       => undef,
139
                        patron_maxonsiteissueqty => undef,
140
                    }
141
                }
142
            );
137
        }
143
        }
138
    } elsif ($categorycode eq "*") {
144
    } elsif ($categorycode eq "*") {
139
        Koha::CirculationRules->set_rules(
145
        Koha::CirculationRules->set_rules(
140
            {
146
            {
147
                branchcode   => $branch,
141
                categorycode => undef,
148
                categorycode => undef,
149
                rules        => {
150
                    patron_maxissueqty       => undef,
151
                    patron_maxonsiteissueqty => undef,
152
                }
153
            }
154
        );
155
        Koha::CirculationRules->set_rules(
156
            {
142
                branchcode   => $branch,
157
                branchcode   => $branch,
143
                itemtype     => undef,
144
                rules        => {
158
                rules        => {
145
                    patron_maxissueqty             => undef,
146
                    patron_maxonsiteissueqty       => undef,
147
                    holdallowed             => undef,
159
                    holdallowed             => undef,
148
                    hold_fulfillment_policy => undef,
160
                    hold_fulfillment_policy => undef,
149
                    returnbranch            => undef,
161
                    returnbranch            => undef,
Lines 155-161 elsif ($op eq 'delete-branch-cat') { Link Here
155
            {
167
            {
156
                categorycode => $categorycode,
168
                categorycode => $categorycode,
157
                branchcode   => $branch,
169
                branchcode   => $branch,
158
                itemtype     => undef,
159
                rules        => {
170
                rules        => {
160
                    max_holds         => undef,
171
                    max_holds         => undef,
161
                    patron_maxissueqty       => undef,
172
                    patron_maxissueqty       => undef,
Lines 171-182 elsif ($op eq 'delete-branch-item') { Link Here
171
        if ($itemtype eq "*") {
182
        if ($itemtype eq "*") {
172
            Koha::CirculationRules->set_rules(
183
            Koha::CirculationRules->set_rules(
173
                {
184
                {
174
                    categorycode => undef,
175
                    branchcode   => undef,
185
                    branchcode   => undef,
176
                    itemtype     => undef,
186
                    itemtype     => undef,
177
                    rules        => {
187
                    rules        => {
178
                        patron_maxissueqty             => undef,
179
                        patron_maxonsiteissueqty       => undef,
180
                        holdallowed             => undef,
188
                        holdallowed             => undef,
181
                        hold_fulfillment_policy => undef,
189
                        hold_fulfillment_policy => undef,
182
                        returnbranch            => undef,
190
                        returnbranch            => undef,
Lines 186-192 elsif ($op eq 'delete-branch-item') { Link Here
186
        } else {
194
        } else {
187
            Koha::CirculationRules->set_rules(
195
            Koha::CirculationRules->set_rules(
188
                {
196
                {
189
                    categorycode => undef,
190
                    branchcode   => undef,
197
                    branchcode   => undef,
191
                    itemtype     => $itemtype,
198
                    itemtype     => $itemtype,
192
                    rules        => {
199
                    rules        => {
Lines 200-211 elsif ($op eq 'delete-branch-item') { Link Here
200
    } elsif ($itemtype eq "*") {
207
    } elsif ($itemtype eq "*") {
201
        Koha::CirculationRules->set_rules(
208
        Koha::CirculationRules->set_rules(
202
            {
209
            {
203
                categorycode => undef,
204
                branchcode   => $branch,
210
                branchcode   => $branch,
205
                itemtype     => undef,
211
                itemtype     => undef,
206
                rules        => {
212
                rules        => {
207
                    maxissueqty             => undef,
208
                    maxonsiteissueqty       => undef,
209
                    holdallowed             => undef,
213
                    holdallowed             => undef,
210
                    hold_fulfillment_policy => undef,
214
                    hold_fulfillment_policy => undef,
211
                    returnbranch            => undef,
215
                    returnbranch            => undef,
Lines 215-221 elsif ($op eq 'delete-branch-item') { Link Here
215
    } else {
219
    } else {
216
        Koha::CirculationRules->set_rules(
220
        Koha::CirculationRules->set_rules(
217
            {
221
            {
218
                categorycode => undef,
219
                branchcode   => $branch,
222
                branchcode   => $branch,
220
                itemtype     => $itemtype,
223
                itemtype     => $itemtype,
221
                rules        => {
224
                rules        => {
Lines 270-281 elsif ($op eq 'add') { Link Here
270
    my $article_requests = $input->param('article_requests') || 'no';
273
    my $article_requests = $input->param('article_requests') || 'no';
271
    my $overduefinescap = $input->param('overduefinescap') || undef;
274
    my $overduefinescap = $input->param('overduefinescap') || undef;
272
    my $cap_fine_to_replacement_price = $input->param('cap_fine_to_replacement_price') eq 'on';
275
    my $cap_fine_to_replacement_price = $input->param('cap_fine_to_replacement_price') eq 'on';
273
    $debug and warn "Adding $br, $bor, $itemtype, $fine, $maxissueqty, $maxonsiteissueqty, $cap_fine_to_replacement_price";
276
    warn "Adding $br, $bor, $itemtype, $fine, $maxissueqty, $maxonsiteissueqty, $cap_fine_to_replacement_price";
274
277
275
    my $params = {
278
    my $params = {
276
        branchcode                    => $br,
277
        categorycode                  => $bor,
278
        itemtype                      => $itemtype,
279
        fine                          => $fine,
279
        fine                          => $fine,
280
        finedays                      => $finedays,
280
        finedays                      => $finedays,
281
        maxsuspensiondays             => $maxsuspensiondays,
281
        maxsuspensiondays             => $maxsuspensiondays,
Lines 304-312 elsif ($op eq 'add') { Link Here
304
304
305
    Koha::CirculationRules->set_rules(
305
    Koha::CirculationRules->set_rules(
306
        {
306
        {
307
            categorycode => $bor,
307
            categorycode => $bor eq '*' ? undef : $bor,
308
            itemtype     => $itemtype,
308
            itemtype     => $itemtype eq '*' ? undef : $itemtype,
309
            branchcode   => $br,
309
            branchcode   => $br eq '*' ? undef : $br,
310
            rules        => {
310
            rules        => {
311
                maxissueqty       => $maxissueqty,
311
                maxissueqty       => $maxissueqty,
312
                maxonsiteissueqty => $maxonsiteissueqty,
312
                maxonsiteissueqty => $maxonsiteissueqty,
Lines 336-365 elsif ($op eq "set-branch-defaults") { Link Here
336
    if ($branch eq "*") {
336
    if ($branch eq "*") {
337
        Koha::CirculationRules->set_rules(
337
        Koha::CirculationRules->set_rules(
338
            {
338
            {
339
                categorycode => undef,
340
                itemtype     => undef,
339
                itemtype     => undef,
341
                branchcode   => undef,
340
                branchcode   => undef,
342
                rules        => {
341
                rules        => {
343
                    patron_maxissueqty       => $patron_maxissueqty,
342
                    holdallowed             => $holdallowed,
344
                    patron_maxonsiteissueqty => $patron_maxonsiteissueqty,
343
                    hold_fulfillment_policy => $hold_fulfillment_policy,
345
                    holdallowed              => $holdallowed,
344
                    returnbranch            => $returnbranch,
346
                    hold_fulfillment_policy  => $hold_fulfillment_policy,
347
                    returnbranch             => $returnbranch,
348
                }
345
                }
349
            }
346
            }
350
        );
347
        );
351
    } else {
352
        Koha::CirculationRules->set_rules(
348
        Koha::CirculationRules->set_rules(
353
            {
349
            {
354
                categorycode => undef,
350
                categorycode => undef,
351
                branchcode   => undef,
352
                rules        => {
353
                    patron_maxissueqty             => $patron_maxissueqty,
354
                    patron_maxonsiteissueqty       => $patron_maxonsiteissueqty,
355
                }
356
            }
357
        );
358
    } else {
359
        Koha::CirculationRules->set_rules(
360
            {
355
                itemtype     => undef,
361
                itemtype     => undef,
356
                branchcode   => $branch,
362
                branchcode   => $branch,
357
                rules        => {
363
                rules        => {
358
                    patron_maxissueqty       => $patron_maxissueqty,
364
                    holdallowed             => $holdallowed,
359
                    patron_maxonsiteissueqty => $patron_maxonsiteissueqty,
365
                    hold_fulfillment_policy => $hold_fulfillment_policy,
360
                    holdallowed              => $holdallowed,
366
                    returnbranch            => $returnbranch,
361
                    hold_fulfillment_policy  => $hold_fulfillment_policy,
367
                }
362
                    returnbranch             => $returnbranch,
368
            }
369
        );
370
        Koha::CirculationRules->set_rules(
371
            {
372
                categorycode => undef,
373
                branchcode   => $branch,
374
                rules        => {
375
                    patron_maxissueqty             => $patron_maxissueqty,
376
                    patron_maxonsiteissueqty       => $patron_maxonsiteissueqty,
363
                }
377
                }
364
            }
378
            }
365
        );
379
        );
Lines 391-397 elsif ($op eq "add-branch-cat") { Link Here
391
            Koha::CirculationRules->set_rules(
405
            Koha::CirculationRules->set_rules(
392
                {
406
                {
393
                    categorycode => undef,
407
                    categorycode => undef,
394
                    itemtype     => undef,
395
                    branchcode   => undef,
408
                    branchcode   => undef,
396
                    rules        => {
409
                    rules        => {
397
                        max_holds         => $max_holds,
410
                        max_holds         => $max_holds,
Lines 403-411 elsif ($op eq "add-branch-cat") { Link Here
403
        } else {
416
        } else {
404
            Koha::CirculationRules->set_rules(
417
            Koha::CirculationRules->set_rules(
405
                {
418
                {
406
                    branchcode   => '*',
407
                    categorycode => $categorycode,
419
                    categorycode => $categorycode,
408
                    itemtype     => undef,
420
                    branchcode   => undef,
409
                    rules        => {
421
                    rules        => {
410
                        max_holds         => $max_holds,
422
                        max_holds         => $max_holds,
411
                        patron_maxissueqty       => $patron_maxissueqty,
423
                        patron_maxissueqty       => $patron_maxissueqty,
Lines 418-424 elsif ($op eq "add-branch-cat") { Link Here
418
        Koha::CirculationRules->set_rules(
430
        Koha::CirculationRules->set_rules(
419
            {
431
            {
420
                categorycode => undef,
432
                categorycode => undef,
421
                itemtype     => undef,
422
                branchcode   => $branch,
433
                branchcode   => $branch,
423
                rules        => {
434
                rules        => {
424
                    max_holds         => $max_holds,
435
                    max_holds         => $max_holds,
Lines 431-437 elsif ($op eq "add-branch-cat") { Link Here
431
        Koha::CirculationRules->set_rules(
442
        Koha::CirculationRules->set_rules(
432
            {
443
            {
433
                categorycode => $categorycode,
444
                categorycode => $categorycode,
434
                itemtype     => undef,
435
                branchcode   => $branch,
445
                branchcode   => $branch,
436
                rules        => {
446
                rules        => {
437
                    max_holds         => $max_holds,
447
                    max_holds         => $max_holds,
Lines 455-461 elsif ($op eq "add-branch-item") { Link Here
455
        if ($itemtype eq "*") {
465
        if ($itemtype eq "*") {
456
            Koha::CirculationRules->set_rules(
466
            Koha::CirculationRules->set_rules(
457
                {
467
                {
458
                    categorycode => undef,
459
                    itemtype     => undef,
468
                    itemtype     => undef,
460
                    branchcode   => undef,
469
                    branchcode   => undef,
461
                    rules        => {
470
                    rules        => {
Lines 468-474 elsif ($op eq "add-branch-item") { Link Here
468
        } else {
477
        } else {
469
            Koha::CirculationRules->set_rules(
478
            Koha::CirculationRules->set_rules(
470
                {
479
                {
471
                    categorycode => undef,
472
                    itemtype     => $itemtype,
480
                    itemtype     => $itemtype,
473
                    branchcode   => undef,
481
                    branchcode   => undef,
474
                    rules        => {
482
                    rules        => {
Lines 482-488 elsif ($op eq "add-branch-item") { Link Here
482
    } elsif ($itemtype eq "*") {
490
    } elsif ($itemtype eq "*") {
483
            Koha::CirculationRules->set_rules(
491
            Koha::CirculationRules->set_rules(
484
                {
492
                {
485
                    categorycode => undef,
486
                    itemtype     => undef,
493
                    itemtype     => undef,
487
                    branchcode   => $branch,
494
                    branchcode   => $branch,
488
                    rules        => {
495
                    rules        => {
Lines 495-501 elsif ($op eq "add-branch-item") { Link Here
495
    } else {
502
    } else {
496
        Koha::CirculationRules->set_rules(
503
        Koha::CirculationRules->set_rules(
497
            {
504
            {
498
                categorycode => undef,
499
                itemtype     => $itemtype,
505
                itemtype     => $itemtype,
500
                branchcode   => $branch,
506
                branchcode   => $branch,
501
                rules        => {
507
                rules        => {
Lines 516-523 elsif ( $op eq 'mod-refund-lost-item-fee-rule' ) { Link Here
516
            # only do something for $refund eq '*' if branch-specific
522
            # only do something for $refund eq '*' if branch-specific
517
            Koha::CirculationRules->set_rules(
523
            Koha::CirculationRules->set_rules(
518
                {
524
                {
519
                    categorycode => undef,
520
                    itemtype     => undef,
521
                    branchcode   => $branch,
525
                    branchcode   => $branch,
522
                    rules        => {
526
                    rules        => {
523
                        refund => undef
527
                        refund => undef
Lines 528-536 elsif ( $op eq 'mod-refund-lost-item-fee-rule' ) { Link Here
528
    } else {
532
    } else {
529
        Koha::CirculationRules->set_rules(
533
        Koha::CirculationRules->set_rules(
530
            {
534
            {
531
                categorycode => undef,
535
                branchcode   => undef,
532
                itemtype     => undef,
533
                branchcode   => $branch,
534
                rules        => {
536
                rules        => {
535
                    refund => $refund
537
                    refund => $refund
536
                }
538
                }
Lines 539-545 elsif ( $op eq 'mod-refund-lost-item-fee-rule' ) { Link Here
539
    }
541
    }
540
}
542
}
541
543
542
my $refundLostItemFeeRule = Koha::RefundLostItemFeeRules->find({ branchcode => $branch });
544
my $refundLostItemFeeRule = Koha::RefundLostItemFeeRules->find({ branchcode => $branch eq '*' ? undef : $branch });
543
$template->param(
545
$template->param(
544
    refundLostItemFeeRule => $refundLostItemFeeRule,
546
    refundLostItemFeeRule => $refundLostItemFeeRule,
545
    defaultRefundRule     => Koha::RefundLostItemFeeRules->_default_rule
547
    defaultRefundRule     => Koha::RefundLostItemFeeRules->_default_rule
Lines 554-560 $template->param(show_branch_cat_rule_form => 1); Link Here
554
$template->param(
556
$template->param(
555
    patron_categories => $patron_categories,
557
    patron_categories => $patron_categories,
556
    itemtypeloop      => $itemtypes,
558
    itemtypeloop      => $itemtypes,
557
    humanbranch       => ( $branch ne '*' ? $branch : '' ),
559
    humanbranch       => ( $branch ne '*' ? $branch : undef ),
558
    current_branch    => $branch,
560
    current_branch    => $branch,
559
);
561
);
560
output_html_with_http_headers $input, $cookie, $template->output;
562
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 4135-4141 CREATE TABLE `circulation_rules` ( Link Here
4135
  KEY `branchcode` (`branchcode`),
4135
  KEY `branchcode` (`branchcode`),
4136
  KEY `categorycode` (`categorycode`),
4136
  KEY `categorycode` (`categorycode`),
4137
  KEY `itemtype` (`itemtype`),
4137
  KEY `itemtype` (`itemtype`),
4138
  UNIQUE (`branchcode`,`categorycode`,`itemtype`)
4138
  UNIQUE (`branchcode`,`categorycode`,`itemtype`,`rule_name`),
4139
  FOREIGN KEY (branchcode) REFERENCES branches (branchcode) ON DELETE CASCADE ON UPDATE CASCADE,
4140
  FOREIGN KEY (categorycode) REFERENCES categories (categorycode) ON DELETE CASCADE ON UPDATE CASCADE,
4141
  FOREIGN KEY (itemtype) REFERENCES itemtypes (itemtype) ON DELETE CASCADE ON UPDATE CASCADE
4139
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
4142
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
4140
4143
4141
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
4144
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt (-7 / +12 lines)
Lines 5-23 Link Here
5
[% USE CirculationRules %]
5
[% USE CirculationRules %]
6
[% SET footerjs = 1 %]
6
[% SET footerjs = 1 %]
7
7
8
[% SET branchcode = humanbranch || '*' %]
8
[% SET branchcode = humanbranch || undef %]
9
9
10
[% SET categorycodes = [] %]
10
[% SET categorycodes = [] %]
11
[% FOREACH pc IN patron_categories %]
11
[% FOREACH pc IN patron_categories %]
12
    [% categorycodes.push( pc.id ) %]
12
    [% categorycodes.push( pc.id ) %]
13
[% END %]
13
[% END %]
14
[% categorycodes.push('*') %]
14
[% categorycodes.push(undef) %]
15
15
16
[% SET itemtypes = [] %]
16
[% SET itemtypes = [] %]
17
[% FOREACH i IN itemtypeloop %]
17
[% FOREACH i IN itemtypeloop %]
18
    [% itemtypes.push( i.itemtype ) %]
18
    [% itemtypes.push( i.itemtype ) %]
19
[% END %]
19
[% END %]
20
[% itemtypes.push('*') %]
20
[% itemtypes.push(undef) %]
21
21
22
[% INCLUDE 'doc-head-open.inc' %]
22
[% INCLUDE 'doc-head-open.inc' %]
23
<title>Koha &rsaquo; Administration &rsaquo; Circulation and fine rules</title>
23
<title>Koha &rsaquo; Administration &rsaquo; Circulation and fine rules</title>
Lines 151-169 Link Here
151
                            [% SET row_count = row_count + 1 %]
151
                            [% SET row_count = row_count + 1 %]
152
                            <tr row_countd="row_[% row_count %]">
152
                            <tr row_countd="row_[% row_count %]">
153
                                    <td>
153
                                    <td>
154
                                        [% IF c == '*' %]
154
                                        [% IF c == undef %]
155
                                            <em>All</em>
155
                                            <em>All</em>
156
                                        [% ELSE %]
156
                                        [% ELSE %]
157
                                            [% Categories.GetName(c) %]
157
                                            [% Categories.GetName(c) %]
158
                                        [% END %]
158
                                        [% END %]
159
                                    </td>
159
                                    </td>
160
                                    <td>
160
                                    <td>
161
                                        [% IF i == '*' %]
161
                                        [% IF i == undef %]
162
                                            <em>All</em>
162
                                            <em>All</em>
163
                                        [% ELSE %]
163
                                        [% ELSE %]
164
                                            [% ItemTypes.GetDescription(i) %]
164
                                            [% ItemTypes.GetDescription(i) %]
165
                                        [% END %]
165
                                        [% END %]
166
                                    </td>
166
                                    </td>
167
                                    <td class="actions">
168
                                      <a href="#" class="editrule btn btn-default btn-xs"><i class="fa fa-pencil"></i> Edit</a>
169
                                      <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>
170
                                    </td>
167
                                    <td>
171
                                    <td>
168
                                        [% IF maxissueqty  %]
172
                                        [% IF maxissueqty  %]
169
                                            [% maxissueqty %]
173
                                            [% maxissueqty %]
Lines 250-256 Link Here
250
                                    <td>[% rentaldiscount %]</td>
254
                                    <td>[% rentaldiscount %]</td>
251
                                    <td class="actions">
255
                                    <td class="actions">
252
                                      <a href="#" class="editrule btn btn-default btn-xs"><i class="fa fa-pencil"></i> Edit</a>
256
                                      <a href="#" class="editrule btn btn-default btn-xs"><i class="fa fa-pencil"></i> Edit</a>
253
                                      <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>
257
                                      <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>
254
                                    </td>
258
                                    </td>
255
                            </tr>
259
                            </tr>
256
                        [% END %]
260
                        [% END %]
Lines 552-557 Link Here
552
                    <th>&nbsp;</th>
556
                    <th>&nbsp;</th>
553
                </tr>
557
                </tr>
554
                [% FOREACH c IN categorycodes %]
558
                [% FOREACH c IN categorycodes %]
559
                    [% NEXT UNLESS c %]
555
                    [% SET patron_maxissueqty = CirculationRules.Get( branchcode, c, undef, 'patron_maxissueqty' ) %]
560
                    [% SET patron_maxissueqty = CirculationRules.Get( branchcode, c, undef, 'patron_maxissueqty' ) %]
556
                    [% SET patron_maxonsiteissueqty = CirculationRules.Get( branchcode, c, undef, 'patron_maxonsiteissueqty' ) %]
561
                    [% SET patron_maxonsiteissueqty = CirculationRules.Get( branchcode, c, undef, 'patron_maxonsiteissueqty' ) %]
557
                    [% SET max_holds = CirculationRules.Get( branchcode, c, undef, 'max_holds' ) %]
562
                    [% SET max_holds = CirculationRules.Get( branchcode, c, undef, 'max_holds' ) %]
Lines 559-565 Link Here
559
                    [% IF patron_maxissueqty || patron_maxonsiteissueqty || max_holds %]
564
                    [% IF patron_maxissueqty || patron_maxonsiteissueqty || max_holds %]
560
                    <tr>
565
                    <tr>
561
                        <td>
566
                        <td>
562
                            [% IF c == '*'%]
567
                            [% IF c == undef %]
563
                                <em>Default</em>
568
                                <em>Default</em>
564
                            [% ELSE %]
569
                            [% ELSE %]
565
                                [% Categories.GetName(c) %]
570
                                [% Categories.GetName(c) %]
(-)a/t/db_dependent/ArticleRequests.t (-12 / +12 lines)
Lines 175-183 is( $biblio->article_requests_finished()->count(), 1, 'Canceled request not retu Link Here
175
175
176
my $rule = Koha::CirculationRules->set_rule(
176
my $rule = Koha::CirculationRules->set_rule(
177
    {
177
    {
178
        categorycode => '*',
178
        categorycode => undef,
179
        itemtype     => '*',
179
        itemtype     => undef,
180
        branchcode   => '*',
180
        branchcode   => undef,
181
        rule_name    => 'article_requests',
181
        rule_name    => 'article_requests',
182
        rule_value   => 'yes',
182
        rule_value   => 'yes',
183
    }
183
    }
Lines 190-198 $rule->delete(); Link Here
190
190
191
$rule = Koha::CirculationRules->set_rule(
191
$rule = Koha::CirculationRules->set_rule(
192
    {
192
    {
193
        categorycode => '*',
193
        categorycode => undef,
194
        itemtype     => '*',
194
        itemtype     => undef,
195
        branchcode   => '*',
195
        branchcode   => undef,
196
        rule_name    => 'article_requests',
196
        rule_name    => 'article_requests',
197
        rule_value   => 'bib_only',
197
        rule_value   => 'bib_only',
198
    }
198
    }
Lines 205-213 $rule->delete(); Link Here
205
205
206
$rule = Koha::CirculationRules->set_rule(
206
$rule = Koha::CirculationRules->set_rule(
207
    {
207
    {
208
        categorycode => '*',
208
        categorycode => undef,
209
        itemtype     => '*',
209
        itemtype     => undef,
210
        branchcode   => '*',
210
        branchcode   => undef,
211
        rule_name    => 'article_requests',
211
        rule_name    => 'article_requests',
212
        rule_value   => 'item_only',
212
        rule_value   => 'item_only',
213
    }
213
    }
Lines 220-228 $rule->delete(); Link Here
220
220
221
$rule = Koha::CirculationRules->set_rule(
221
$rule = Koha::CirculationRules->set_rule(
222
    {
222
    {
223
        categorycode => '*',
223
        categorycode => undef,
224
        itemtype     => '*',
224
        itemtype     => undef,
225
        branchcode   => '*',
225
        branchcode   => undef,
226
        rule_name    => 'article_requests',
226
        rule_name    => 'article_requests',
227
        rule_value   => 'no',
227
        rule_value   => 'no',
228
    }
228
    }
(-)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 => 113;
20
use Test::More tests => 113;
21
use Test::Deep qw( cmp_deeply );
21
22
22
use DateTime;
23
use DateTime;
23
24
Lines 182-190 is( Link Here
182
$dbh->do('DELETE FROM circulation_rules');
183
$dbh->do('DELETE FROM circulation_rules');
183
Koha::CirculationRules->set_rules(
184
Koha::CirculationRules->set_rules(
184
    {
185
    {
185
        categorycode => '*',
186
        categorycode => undef,
186
        branchcode   => '*',
187
        branchcode   => undef,
187
        itemtype     => '*',
188
        itemtype     => undef,
188
        rules        => {
189
        rules        => {
189
            reservesallowed => 25,
190
            reservesallowed => 25,
190
            issuelength     => 14,
191
            issuelength     => 14,
Lines 343-351 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
343
    # Testing of feature to allow the renewal of reserved items if other items on the record can fill all needed holds
344
    # Testing of feature to allow the renewal of reserved items if other items on the record can fill all needed holds
344
    Koha::CirculationRules->set_rule(
345
    Koha::CirculationRules->set_rule(
345
        {
346
        {
346
            categorycode => '*',
347
            categorycode => undef,
347
            branchcode   => '*',
348
            branchcode   => undef,
348
            itemtype     => '*',
349
            itemtype     => undef,
349
            rule_name    => 'onshelfholds',
350
            rule_name    => 'onshelfholds',
350
            rule_value   => '1',
351
            rule_value   => '1',
351
        }
352
        }
Lines 564-572 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
564
    # Test premature manual renewal
565
    # Test premature manual renewal
565
    Koha::CirculationRules->set_rule(
566
    Koha::CirculationRules->set_rule(
566
        {
567
        {
567
            categorycode => '*',
568
            categorycode => undef,
568
            branchcode   => '*',
569
            branchcode   => undef,
569
            itemtype     => '*',
570
            itemtype     => undef,
570
            rule_name    => 'norenewalbefore',
571
            rule_name    => 'norenewalbefore',
571
            rule_value   => '7',
572
            rule_value   => '7',
572
        }
573
        }
Lines 641-649 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
641
642
642
        Koha::CirculationRules->set_rules(
643
        Koha::CirculationRules->set_rules(
643
            {
644
            {
644
                categorycode => '*',
645
                categorycode => undef,
645
                branchcode   => '*',
646
                branchcode   => undef,
646
                itemtype     => '*',
647
                itemtype     => undef,
647
                rules        => {
648
                rules        => {
648
                    norenewalbefore       => '7',
649
                    norenewalbefore       => '7',
649
                    no_auto_renewal_after => '9',
650
                    no_auto_renewal_after => '9',
Lines 657-665 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
657
658
658
        Koha::CirculationRules->set_rules(
659
        Koha::CirculationRules->set_rules(
659
            {
660
            {
660
                categorycode => '*',
661
                categorycode => undef,
661
                branchcode   => '*',
662
                branchcode   => undef,
662
                itemtype     => '*',
663
                itemtype     => undef,
663
                rules        => {
664
                rules        => {
664
                    norenewalbefore       => '7',
665
                    norenewalbefore       => '7',
665
                    no_auto_renewal_after => '10',
666
                    no_auto_renewal_after => '10',
Lines 673-681 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
673
674
674
        Koha::CirculationRules->set_rules(
675
        Koha::CirculationRules->set_rules(
675
            {
676
            {
676
                categorycode => '*',
677
                categorycode => undef,
677
                branchcode   => '*',
678
                branchcode   => undef,
678
                itemtype     => '*',
679
                itemtype     => undef,
679
                rules        => {
680
                rules        => {
680
                    norenewalbefore       => '7',
681
                    norenewalbefore       => '7',
681
                    no_auto_renewal_after => '11',
682
                    no_auto_renewal_after => '11',
Lines 689-697 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
689
690
690
        Koha::CirculationRules->set_rules(
691
        Koha::CirculationRules->set_rules(
691
            {
692
            {
692
                categorycode => '*',
693
                categorycode => undef,
693
                branchcode   => '*',
694
                branchcode   => undef,
694
                itemtype     => '*',
695
                itemtype     => undef,
695
                rules        => {
696
                rules        => {
696
                    norenewalbefore       => '10',
697
                    norenewalbefore       => '10',
697
                    no_auto_renewal_after => '11',
698
                    no_auto_renewal_after => '11',
Lines 705-713 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
705
706
706
        Koha::CirculationRules->set_rules(
707
        Koha::CirculationRules->set_rules(
707
            {
708
            {
708
                categorycode => '*',
709
                categorycode => undef,
709
                branchcode   => '*',
710
                branchcode   => undef,
710
                itemtype     => '*',
711
                itemtype     => undef,
711
                rules        => {
712
                rules        => {
712
                    norenewalbefore       => '10',
713
                    norenewalbefore       => '10',
713
                    no_auto_renewal_after => undef,
714
                    no_auto_renewal_after => undef,
Lines 722-730 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
722
723
723
        Koha::CirculationRules->set_rules(
724
        Koha::CirculationRules->set_rules(
724
            {
725
            {
725
                categorycode => '*',
726
                categorycode => undef,
726
                branchcode   => '*',
727
                branchcode   => undef,
727
                itemtype     => '*',
728
                itemtype     => undef,
728
                rules        => {
729
                rules        => {
729
                    norenewalbefore       => '7',
730
                    norenewalbefore       => '7',
730
                    no_auto_renewal_after => '15',
731
                    no_auto_renewal_after => '15',
Lines 739-747 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
739
740
740
        Koha::CirculationRules->set_rules(
741
        Koha::CirculationRules->set_rules(
741
            {
742
            {
742
                categorycode => '*',
743
                categorycode => undef,
743
                branchcode   => '*',
744
                branchcode   => undef,
744
                itemtype     => '*',
745
                itemtype     => undef,
745
                rules        => {
746
                rules        => {
746
                    norenewalbefore       => '10',
747
                    norenewalbefore       => '10',
747
                    no_auto_renewal_after => undef,
748
                    no_auto_renewal_after => undef,
Lines 772-780 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
772
773
773
        Koha::CirculationRules->set_rules(
774
        Koha::CirculationRules->set_rules(
774
            {
775
            {
775
                categorycode => '*',
776
                categorycode => undef,
776
                branchcode   => '*',
777
                branchcode   => undef,
777
                itemtype     => '*',
778
                itemtype     => undef,
778
                rules        => {
779
                rules        => {
779
                    norenewalbefore       => '10',
780
                    norenewalbefore       => '10',
780
                    no_auto_renewal_after => '11',
781
                    no_auto_renewal_after => '11',
Lines 874-882 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
874
        AddIssue( $renewing_borrower, $item_to_auto_renew->{barcode}, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } );
875
        AddIssue( $renewing_borrower, $item_to_auto_renew->{barcode}, $ten_days_ahead, undef, $ten_days_before, undef, { auto_renew => 1 } );
875
        Koha::CirculationRules->set_rules(
876
        Koha::CirculationRules->set_rules(
876
            {
877
            {
877
                categorycode => '*',
878
                categorycode => undef,
878
                branchcode   => '*',
879
                branchcode   => undef,
879
                itemtype     => '*',
880
                itemtype     => undef,
880
                rules        => {
881
                rules        => {
881
                    norenewalbefore       => '7',
882
                    norenewalbefore       => '7',
882
                    no_auto_renewal_after => '',
883
                    no_auto_renewal_after => '',
Lines 889-897 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
889
        my $five_days_before = dt_from_string->add( days => -5 );
890
        my $five_days_before = dt_from_string->add( days => -5 );
890
        Koha::CirculationRules->set_rules(
891
        Koha::CirculationRules->set_rules(
891
            {
892
            {
892
                categorycode => '*',
893
                categorycode => undef,
893
                branchcode   => '*',
894
                branchcode   => undef,
894
                itemtype     => '*',
895
                itemtype     => undef,
895
                rules        => {
896
                rules        => {
896
                    norenewalbefore       => '10',
897
                    norenewalbefore       => '10',
897
                    no_auto_renewal_after => '5',
898
                    no_auto_renewal_after => '5',
Lines 910-918 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
910
        $dbh->do(q{UPDATE circulation_rules SET rule_value = NULL WHERE rule_name = 'no_auto_renewal_after_hard_limit'});
911
        $dbh->do(q{UPDATE circulation_rules SET rule_value = NULL WHERE rule_name = 'no_auto_renewal_after_hard_limit'});
911
        Koha::CirculationRules->set_rules(
912
        Koha::CirculationRules->set_rules(
912
            {
913
            {
913
                categorycode => '*',
914
                categorycode => undef,
914
                branchcode   => '*',
915
                branchcode   => undef,
915
                itemtype     => '*',
916
                itemtype     => undef,
916
                rules        => {
917
                rules        => {
917
                    norenewalbefore       => '10',
918
                    norenewalbefore       => '10',
918
                    no_auto_renewal_after => '15',
919
                    no_auto_renewal_after => '15',
Lines 928-936 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
928
        my $two_days_ahead = dt_from_string->add( days => 2 );
929
        my $two_days_ahead = dt_from_string->add( days => 2 );
929
        Koha::CirculationRules->set_rules(
930
        Koha::CirculationRules->set_rules(
930
            {
931
            {
931
                categorycode => '*',
932
                categorycode => undef,
932
                branchcode   => '*',
933
                branchcode   => undef,
933
                itemtype     => '*',
934
                itemtype     => undef,
934
                rules        => {
935
                rules        => {
935
                    norenewalbefore       => '10',
936
                    norenewalbefore       => '10',
936
                    no_auto_renewal_after => '',
937
                    no_auto_renewal_after => '',
Lines 945-953 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
945
        );
946
        );
946
        Koha::CirculationRules->set_rules(
947
        Koha::CirculationRules->set_rules(
947
            {
948
            {
948
                categorycode => '*',
949
                categorycode => undef,
949
                branchcode   => '*',
950
                branchcode   => undef,
950
                itemtype     => '*',
951
                itemtype     => undef,
951
                rules        => {
952
                rules        => {
952
                    norenewalbefore       => '10',
953
                    norenewalbefore       => '10',
953
                    no_auto_renewal_after => '15',
954
                    no_auto_renewal_after => '15',
Lines 967-975 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
967
    # set policy to forbid renewals
968
    # set policy to forbid renewals
968
    Koha::CirculationRules->set_rules(
969
    Koha::CirculationRules->set_rules(
969
        {
970
        {
970
            categorycode => '*',
971
            categorycode => undef,
971
            branchcode   => '*',
972
            branchcode   => undef,
972
            itemtype     => '*',
973
            itemtype     => undef,
973
            rules        => {
974
            rules        => {
974
                norenewalbefore => undef,
975
                norenewalbefore => undef,
975
                renewalsallowed => 0,
976
                renewalsallowed => 0,
Lines 1196-1204 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
1196
    $dbh->do('DELETE FROM circulation_rules');
1197
    $dbh->do('DELETE FROM circulation_rules');
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
                reservesallowed => 25,
1204
                reservesallowed => 25,
1204
                issuelength     => 14,
1205
                issuelength     => 14,
Lines 1265-1273 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
1265
1266
1266
    Koha::CirculationRules->set_rules(
1267
    Koha::CirculationRules->set_rules(
1267
        {
1268
        {
1268
            categorycode => '*',
1269
            categorycode => undef,
1269
            itemtype     => '*',
1270
            itemtype     => undef,
1270
            branchcode   => '*',
1271
            branchcode   => undef,
1271
            rules        => {
1272
            rules        => {
1272
                onshelfholds => 0,
1273
                onshelfholds => 0,
1273
            }
1274
            }
Lines 1279-1287 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
1279
1280
1280
    Koha::CirculationRules->set_rules(
1281
    Koha::CirculationRules->set_rules(
1281
        {
1282
        {
1282
            categorycode => '*',
1283
            categorycode => undef,
1283
            itemtype     => '*',
1284
            itemtype     => undef,
1284
            branchcode   => '*',
1285
            branchcode   => undef,
1285
            rules        => {
1286
            rules        => {
1286
                onshelfholds => 0,
1287
                onshelfholds => 0,
1287
            }
1288
            }
Lines 1293-1301 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
1293
1294
1294
    Koha::CirculationRules->set_rules(
1295
    Koha::CirculationRules->set_rules(
1295
        {
1296
        {
1296
            categorycode => '*',
1297
            categorycode => undef,
1297
            itemtype     => '*',
1298
            itemtype     => undef,
1298
            branchcode   => '*',
1299
            branchcode   => undef,
1299
            rules        => {
1300
            rules        => {
1300
                onshelfholds => 1,
1301
                onshelfholds => 1,
1301
            }
1302
            }
Lines 1307-1315 C4::Context->dbh->do("DELETE FROM accountlines"); Link Here
1307
1308
1308
    Koha::CirculationRules->set_rules(
1309
    Koha::CirculationRules->set_rules(
1309
        {
1310
        {
1310
            categorycode => '*',
1311
            categorycode => undef,
1311
            itemtype     => '*',
1312
            itemtype     => undef,
1312
            branchcode   => '*',
1313
            branchcode   => undef,
1313
            rules        => {
1314
            rules        => {
1314
                onshelfholds => 1,
1315
                onshelfholds => 1,
1315
            }
1316
            }
Lines 1811-1833 subtest 'CanBookBeIssued + AllowMultipleIssuesOnABiblio' => sub { Link Here
1811
1812
1812
    t::lib::Mocks::mock_preference('AllowMultipleIssuesOnABiblio', 0);
1813
    t::lib::Mocks::mock_preference('AllowMultipleIssuesOnABiblio', 0);
1813
    ( $error, $question, $alerts ) = CanBookBeIssued( $patron, $item_2->{barcode} );
1814
    ( $error, $question, $alerts ) = CanBookBeIssued( $patron, $item_2->{barcode} );
1814
    is( keys(%$error) + keys(%$alerts),  0, 'No error or alert should be raised' . str($error, $question, $alerts) );
1815
    cmp_deeply(
1815
    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) );
1816
        { error => $error, alerts => $alerts },
1817
        { error => {}, alerts => {} },
1818
        'No error or alert should be raised'
1819
    );
1820
    is( $question->{BIBLIO_ALREADY_ISSUED}, 1, 'BIBLIO_ALREADY_ISSUED question flag should be set if AllowMultipleIssuesOnABiblio=0 and issue already exists' );
1816
1821
1817
    t::lib::Mocks::mock_preference('AllowMultipleIssuesOnABiblio', 1);
1822
    t::lib::Mocks::mock_preference('AllowMultipleIssuesOnABiblio', 1);
1818
    ( $error, $question, $alerts ) = CanBookBeIssued( $patron, $item_2->{barcode} );
1823
    ( $error, $question, $alerts ) = CanBookBeIssued( $patron, $item_2->{barcode} );
1819
    is( keys(%$error) + keys(%$question) + keys(%$alerts),  0, 'No BIBLIO_ALREADY_ISSUED flag should be set if AllowMultipleIssuesOnABiblio=1' . str($error, $question, $alerts) );
1824
    cmp_deeply(
1825
        { error => $error, question => $question, alerts => $alerts },
1826
        { error => {}, question => {}, alerts => {} },
1827
        'No BIBLIO_ALREADY_ISSUED flag should be set if AllowMultipleIssuesOnABiblio=1'
1828
    );
1820
1829
1821
    # Add a subscription
1830
    # Add a subscription
1822
    Koha::Subscription->new({ biblionumber => $biblionumber })->store;
1831
    Koha::Subscription->new({ biblionumber => $biblionumber })->store;
1823
1832
1824
    t::lib::Mocks::mock_preference('AllowMultipleIssuesOnABiblio', 0);
1833
    t::lib::Mocks::mock_preference('AllowMultipleIssuesOnABiblio', 0);
1825
    ( $error, $question, $alerts ) = CanBookBeIssued( $patron, $item_2->{barcode} );
1834
    ( $error, $question, $alerts ) = CanBookBeIssued( $patron, $item_2->{barcode} );
1826
    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) );
1835
    cmp_deeply(
1836
        { error => $error, question => $question, alerts => $alerts },
1837
        { error => {}, question => {}, alerts => {} },
1838
        'No BIBLIO_ALREADY_ISSUED flag should be set if it is a subscription'
1839
    );
1827
1840
1828
    t::lib::Mocks::mock_preference('AllowMultipleIssuesOnABiblio', 1);
1841
    t::lib::Mocks::mock_preference('AllowMultipleIssuesOnABiblio', 1);
1829
    ( $error, $question, $alerts ) = CanBookBeIssued( $patron, $item_2->{barcode} );
1842
    ( $error, $question, $alerts ) = CanBookBeIssued( $patron, $item_2->{barcode} );
1830
    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) );
1843
    cmp_deeply(
1844
        { error => $error, question => $question, alerts => $alerts },
1845
        { error => {}, question => {}, alerts => {} },
1846
        'No BIBLIO_ALREADY_ISSUED flag should be set if it is a subscription'
1847
    );
1831
};
1848
};
1832
1849
1833
subtest 'AddReturn + CumulativeRestrictionPeriods' => sub {
1850
subtest 'AddReturn + CumulativeRestrictionPeriods' => sub {
Lines 1870-1878 subtest 'AddReturn + CumulativeRestrictionPeriods' => sub { Link Here
1870
    Koha::CirculationRules->search->delete;
1887
    Koha::CirculationRules->search->delete;
1871
    Koha::CirculationRules->set_rules(
1888
    Koha::CirculationRules->set_rules(
1872
        {
1889
        {
1873
            categorycode => '*',
1890
            categorycode => undef,
1874
            itemtype     => '*',
1891
            itemtype     => undef,
1875
            branchcode   => '*',
1892
            branchcode   => undef,
1876
            rules        => {
1893
            rules        => {
1877
                issuelength => 1,
1894
                issuelength => 1,
1878
                firstremind => 1,        # 1 day of grace
1895
                firstremind => 1,        # 1 day of grace
Lines 1985-1993 subtest 'AddReturn | is_overdue' => sub { Link Here
1985
    Koha::CirculationRules->search->delete;
2002
    Koha::CirculationRules->search->delete;
1986
    my $rule = Koha::CirculationRules->set_rules(
2003
    my $rule = Koha::CirculationRules->set_rules(
1987
        {
2004
        {
1988
            categorycode => '*',
2005
            categorycode => undef,
1989
            itemtype     => '*',
2006
            itemtype     => undef,
1990
            branchcode   => '*',
2007
            branchcode   => undef,
1991
            rules        => {
2008
            rules        => {
1992
                maxissueqty  => 99,
2009
                maxissueqty  => 99,
1993
                issuelength  => 6,
2010
                issuelength  => 6,
(-)a/t/db_dependent/Circulation/Branch.t (-10 / +21 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-176 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,
172
            holdallowed              => 1,
171
        }
173
            returnbranch             => 'holdingbranch',
172
    }
173
);
174
Koha::CirculationRules->set_rules(
175
    {
176
        branchcode   => $samplebranch2->{branchcode},
177
        itemtype     => undef,
178
        rules        => {
179
            holdallowed       => 1,
180
            returnbranch      => 'holdingbranch',
174
        }
181
        }
175
    }
182
    }
176
);
183
);
Lines 185-196 Koha::CirculationRules->set_rules( Link Here
185
    {
192
    {
186
        branchcode   => undef,
193
        branchcode   => undef,
187
        categorycode => undef,
194
        categorycode => undef,
188
        itemtype     => undef,
189
        rules        => {
195
        rules        => {
190
            patron_maxissueqty       => 4,
196
            patron_maxissueqty       => 4,
191
            patron_maxonsiteissueqty => 5,
197
            patron_maxonsiteissueqty => 5,
192
            holdallowed              => 3,
198
        }
193
            returnbranch             => 'homebranch',
199
    }
200
);
201
Koha::CirculationRules->set_rules(
202
    {
203
        branchcode   => undef,
204
        itemtype     => undef,
205
        rules        => {
206
            holdallowed       => 3,
207
            returnbranch      => 'homebranch',
194
        }
208
        }
195
    }
209
    }
196
);
210
);
Lines 198-204 Koha::CirculationRules->set_rules( Link Here
198
Koha::CirculationRules->set_rules(
212
Koha::CirculationRules->set_rules(
199
    {
213
    {
200
        branchcode   => $samplebranch1->{branchcode},
214
        branchcode   => $samplebranch1->{branchcode},
201
        categorycode => undef,
202
        itemtype     => $sampleitemtype1->{itemtype},
215
        itemtype     => $sampleitemtype1->{itemtype},
203
        rules        => {
216
        rules        => {
204
            holdallowed       => 5,
217
            holdallowed       => 5,
Lines 209-215 Koha::CirculationRules->set_rules( Link Here
209
Koha::CirculationRules->set_rules(
222
Koha::CirculationRules->set_rules(
210
    {
223
    {
211
        branchcode   => $samplebranch2->{branchcode},
224
        branchcode   => $samplebranch2->{branchcode},
212
        categorycode => undef,
213
        itemtype     => $sampleitemtype1->{itemtype},
225
        itemtype     => $sampleitemtype1->{itemtype},
214
        rules        => {
226
        rules        => {
215
            holdallowed       => 5,
227
            holdallowed       => 5,
Lines 220-226 Koha::CirculationRules->set_rules( Link Here
220
Koha::CirculationRules->set_rules(
232
Koha::CirculationRules->set_rules(
221
    {
233
    {
222
        branchcode   => $samplebranch2->{branchcode},
234
        branchcode   => $samplebranch2->{branchcode},
223
        categorycode => undef,
224
        itemtype     => $sampleitemtype2->{itemtype},
235
        itemtype     => $sampleitemtype2->{itemtype},
225
        rules        => {
236
        rules        => {
226
            holdallowed       => 5,
237
            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 79-92 Koha::CirculationRules->search()->delete(); Link Here
79
Koha::CirculationRules->set_rules(
79
Koha::CirculationRules->set_rules(
80
    {
80
    {
81
        branchcode   => $branch->{branchcode},
81
        branchcode   => $branch->{branchcode},
82
        categorycode => '*',
82
        categorycode => undef,
83
        itemtype     => '*',
83
        itemtype     => undef,
84
        rules        => {
84
        rules        => {
85
            maxissueqty       => 2,
85
            maxissueqty       => 2,
86
            maxonsiteissueqty => 1,
86
            maxonsiteissueqty => 1,
87
            branchcode        => $branch->{branchcode},
88
            categorycode      => '*',
89
            itemtype          => '*',
90
            lengthunit        => 'days',
87
            lengthunit        => 'days',
91
            issuelength       => 5,
88
            issuelength       => 5,
92
        }
89
        }
Lines 153-160 Koha::CirculationRules->search()->delete(); Link Here
153
Koha::CirculationRules->set_rules(
150
Koha::CirculationRules->set_rules(
154
    {
151
    {
155
        branchcode   => $branch->{branchcode},
152
        branchcode   => $branch->{branchcode},
156
        categorycode => '*',
153
        categorycode => undef,
157
        itemtype     => '*',
154
        itemtype     => undef,
158
        rules        => {
155
        rules        => {
159
            maxissueqty       => 2,
156
            maxissueqty       => 2,
160
            maxonsiteissueqty => 1,
157
            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 215-221 subtest '1 Issuingrule exist 1 1: issue is allowed' => sub { Link Here
215
        {
215
        {
216
            branchcode   => $branch->{branchcode},
216
            branchcode   => $branch->{branchcode},
217
            categorycode => $category->{categorycode},
217
            categorycode => $category->{categorycode},
218
            itemtype     => '*',
218
            itemtype     => undef,
219
            rules        => {
219
            rules        => {
220
                maxissueqty       => 1,
220
                maxissueqty       => 1,
221
                maxonsiteissueqty => 1,
221
                maxonsiteissueqty => 1,
Lines 255-261 subtest '1 Issuingrule exist: 1 CO allowed, 1 OSCO allowed. Do a CO' => sub { Link Here
255
        {
255
        {
256
            branchcode   => $branch->{branchcode},
256
            branchcode   => $branch->{branchcode},
257
            categorycode => $category->{categorycode},
257
            categorycode => $category->{categorycode},
258
            itemtype     => '*',
258
            itemtype     => undef,
259
            rules        => {
259
            rules        => {
260
                maxissueqty       => 1,
260
                maxissueqty       => 1,
261
                maxonsiteissueqty => 1,
261
                maxonsiteissueqty => 1,
Lines 311-317 subtest '1 Issuingrule exist: 1 CO allowed, 1 OSCO allowed, Do a OSCO' => sub { Link Here
311
        {
311
        {
312
            branchcode   => $branch->{branchcode},
312
            branchcode   => $branch->{branchcode},
313
            categorycode => $category->{categorycode},
313
            categorycode => $category->{categorycode},
314
            itemtype     => '*',
314
            itemtype     => undef,
315
            rules        => {
315
            rules        => {
316
                maxissueqty       => 1,
316
                maxissueqty       => 1,
317
                maxonsiteissueqty => 1,
317
                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 96-108 for my $i ( 0 .. 5 ) { Link Here
96
96
97
Koha::CirculationRules->set_rules(
97
Koha::CirculationRules->set_rules(
98
    {
98
    {
99
        branchcode   => '*',
99
        branchcode   => undef,
100
        categorycode => '*',
100
        categorycode => undef,
101
        itemtype     => '*',
101
        itemtype     => undef,
102
        rules        => {
102
        rules        => {
103
            issuelength     => '14',
103
            issuelength     => '14',
104
            lengthunit      => 'days',
104
            lengthunit      => 'days',
105
            reservesallowed => '99',
105
            reservesallowed => '99',
106
            holds_per_record => '99',
106
        }
107
        }
107
    }
108
    }
108
);
109
);
(-)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 245-253 my ($foreign_item_bibnum, $foreign_item_bibitemnum, $foreign_itemnumber) Link Here
245
$dbh->do('DELETE FROM circulation_rules');
245
$dbh->do('DELETE FROM circulation_rules');
246
Koha::CirculationRules->set_rules(
246
Koha::CirculationRules->set_rules(
247
    {
247
    {
248
        categorycode => '*',
248
        categorycode => undef,
249
        branchcode   => '*',
249
        branchcode   => undef,
250
        itemtype     => '*',
250
        itemtype     => undef,
251
        rules        => {
251
        rules        => {
252
            reservesallowed  => 25,
252
            reservesallowed  => 25,
253
            holds_per_record => 99,
253
            holds_per_record => 99,
Lines 256-263 Koha::CirculationRules->set_rules( Link Here
256
);
256
);
257
Koha::CirculationRules->set_rules(
257
Koha::CirculationRules->set_rules(
258
    {
258
    {
259
        categorycode => '*',
259
        categorycode => undef,
260
        branchcode   => '*',
260
        branchcode   => undef,
261
        itemtype     => 'CANNOT',
261
        itemtype     => 'CANNOT',
262
        rules        => {
262
        rules        => {
263
            reservesallowed  => 0,
263
            reservesallowed  => 0,
Lines 363-371 ok( Link Here
363
$dbh->do('DELETE FROM circulation_rules');
363
$dbh->do('DELETE FROM circulation_rules');
364
Koha::CirculationRules->set_rules(
364
Koha::CirculationRules->set_rules(
365
    {
365
    {
366
        categorycode => '*',
366
        categorycode => undef,
367
        branchcode   => '*',
367
        branchcode   => undef,
368
        itemtype     => '*',
368
        itemtype     => undef,
369
        rules        => {
369
        rules        => {
370
            reservesallowed  => 25,
370
            reservesallowed  => 25,
371
            holds_per_record => 99,
371
            holds_per_record => 99,
Lines 376-382 Koha::CirculationRules->set_rules( Link Here
376
    {
376
    {
377
        branchcode => $branch_1,
377
        branchcode => $branch_1,
378
        itemtype   => 'CANNOT',
378
        itemtype   => 'CANNOT',
379
        categorycode => undef,
380
        rules => {
379
        rules => {
381
            holdallowed => 0,
380
            holdallowed => 0,
382
            returnbranch => 'homebranch',
381
            returnbranch => 'homebranch',
Lines 387-393 Koha::CirculationRules->set_rules( Link Here
387
    {
386
    {
388
        branchcode => $branch_1,
387
        branchcode => $branch_1,
389
        itemtype   => 'CAN',
388
        itemtype   => 'CAN',
390
        categorycode => undef,
391
        rules => {
389
        rules => {
392
            holdallowed => 1,
390
            holdallowed => 1,
393
            returnbranch => 'homebranch',
391
            returnbranch => 'homebranch',
Lines 426-433 $dbh->do('DELETE FROM biblio'); Link Here
426
424
427
Koha::CirculationRules->set_rules(
425
Koha::CirculationRules->set_rules(
428
    {
426
    {
429
        categorycode => '*',
427
        categorycode => undef,
430
        branchcode   => '*',
428
        branchcode   => undef,
431
        itemtype     => 'ONLY1',
429
        itemtype     => 'ONLY1',
432
        rules        => {
430
        rules        => {
433
            reservesallowed  => 1,
431
            reservesallowed  => 1,
Lines 449-463 subtest 'Test max_holds per library/patron category' => sub { Link Here
449
    $dbh->do('DELETE FROM reserves');
447
    $dbh->do('DELETE FROM reserves');
450
    $dbh->do('DELETE FROM circulation_rules');
448
    $dbh->do('DELETE FROM circulation_rules');
451
449
452
    ( $bibnum, $title, $bibitemnum ) = create_helper_biblio('TEST');
450
    my $testitemtype = $builder->build({ source => 'Itemtype' })->{itemtype};
451
    ( $bibnum, $title, $bibitemnum ) = create_helper_biblio($testitemtype);
453
    ( $item_bibnum, $item_bibitemnum, $itemnumber ) =
452
    ( $item_bibnum, $item_bibitemnum, $itemnumber ) =
454
      AddItem( { homebranch => $branch_1, holdingbranch => $branch_1 },
453
      AddItem( { homebranch => $branch_1, holdingbranch => $branch_1 },
455
        $bibnum );
454
        $bibnum );
456
    Koha::CirculationRules->set_rules(
455
    Koha::CirculationRules->set_rules(
457
        {
456
        {
458
            categorycode => '*',
457
            categorycode => undef,
459
            branchcode   => '*',
458
            branchcode   => undef,
460
            itemtype     => 'TEST',
459
            itemtype     => $testitemtype,
461
            rules        => {
460
            rules        => {
462
                reservesallowed  => 99,
461
                reservesallowed  => 99,
463
                holds_per_record => 99,
462
                holds_per_record => 99,
Lines 479-485 subtest 'Test max_holds per library/patron category' => sub { Link Here
479
        {
478
        {
480
            categorycode => $category->{categorycode},
479
            categorycode => $category->{categorycode},
481
            branchcode   => undef,
480
            branchcode   => undef,
482
            itemtype     => undef,
483
            rule_name    => 'max_holds',
481
            rule_name    => 'max_holds',
484
            rule_value   => 3,
482
            rule_value   => 3,
485
        }
483
        }
Lines 489-495 subtest 'Test max_holds per library/patron category' => sub { Link Here
489
        {
487
        {
490
            branchcode   => $branch_1,
488
            branchcode   => $branch_1,
491
            categorycode => $category->{categorycode},
489
            categorycode => $category->{categorycode},
492
            itemtype     => undef,
493
            rule_name    => 'max_holds',
490
            rule_name    => 'max_holds',
494
            rule_value   => 5,
491
            rule_value   => 5,
495
        }
492
        }
(-)a/t/db_dependent/Holds/DisallowHoldIfItemsAvailable.t (-3 / +3 lines)
Lines 95-103 my $item2 = GetItem( $itemnumber2 ); Link Here
95
$dbh->do("DELETE FROM circulation_rules");
95
$dbh->do("DELETE FROM circulation_rules");
96
Koha::CirculationRules->set_rules(
96
Koha::CirculationRules->set_rules(
97
    {
97
    {
98
        categorycode => '*',
98
        categorycode => undef,
99
        itemtype     => '*',
99
        itemtype     => undef,
100
        branchcode   => '*',
100
        branchcode   => undef,
101
        rules        => {
101
        rules        => {
102
            issuelength     => 7,
102
            issuelength     => 7,
103
            lengthunit      => 8,
103
            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 (-116 / +247 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 3;
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 36-50 my $builder = t::lib::TestBuilder->new; Link Here
36
subtest 'get_effective_issuing_rule' => sub {
38
subtest 'get_effective_issuing_rule' => sub {
37
    plan tests => 3;
39
    plan tests => 3;
38
40
39
    my $patron       = $builder->build({ source => 'Borrower' });
41
    my $categorycode = $builder->build({ source => 'Category' })->{'categorycode'};
40
    my $item     = $builder->build({ source => 'Item' });
42
    my $itemtype     = $builder->build({ source => 'Itemtype' })->{'itemtype'};
41
43
    my $branchcode   = $builder->build({ source => 'Branch' })->{'branchcode'};
42
    my $categorycode = $patron->{'categorycode'};
43
    my $itemtype     = $item->{'itype'};
44
    my $branchcode   = $item->{'homebranch'};
45
44
46
    subtest 'Call with undefined values' => sub {
45
    subtest 'Call with undefined values' => sub {
47
        plan tests => 4;
46
        plan tests => 5;
48
47
49
        my $rule;
48
        my $rule;
50
        Koha::CirculationRules->delete;
49
        Koha::CirculationRules->delete;
Lines 59-83 subtest 'get_effective_issuing_rule' => sub { Link Here
59
        is($rule, undef, 'When I attempt to get effective issuing rule by'
58
        is($rule, undef, 'When I attempt to get effective issuing rule by'
60
           .' providing undefined values, then undef is returned.');
59
           .' providing undefined values, then undef is returned.');
61
        ok(Koha::CirculationRule->new({
60
        ok(Koha::CirculationRule->new({
62
            branchcode => '*',
61
            branchcode => undef,
63
            categorycode => '*',
62
            categorycode => undef,
64
            itemtype => '*',
63
            itemtype => undef,
65
            rule_name => 'fine',
64
            rule_name => 'fine',
66
        })->store, 'Given I added an issuing rule branchcode => *,'
65
        })->store, 'Given I added an issuing rule branchcode => undef,'
67
           .' categorycode => *, itemtype => *,');
66
           .' categorycode => undef, itemtype => undef,');
68
        $rule = Koha::CirculationRules->get_effective_rule({
67
        $rule = Koha::CirculationRules->get_effective_rule({
69
            branchcode   => '*',
68
            branchcode   => undef,
70
            categorycode => '*',
69
            categorycode => undef,
71
            itemtype     => '*',
70
            itemtype     => undef,
72
            rule_name    => 'fine',
71
            rule_name    => 'fine',
73
        });
72
        });
74
        ok(_row_match($rule, '*', '*', '*'), 'When I attempt to get effective'
73
        _is_row_match(
74
            $rule,
75
            {
76
                branchcode => undef,
77
                categorycode => undef,
78
                itemtype => undef
79
            },
80
            'When I attempt to get effective'
75
           .' issuing rule by providing undefined values, then the above one is'
81
           .' issuing rule by providing undefined values, then the above one is'
76
           .' returned.');
82
           .' returned.'
83
        );
77
    };
84
    };
78
85
79
    subtest 'Get effective issuing rule in correct order' => sub {
86
    subtest 'Get effective issuing rule in correct order' => sub {
80
        plan tests => 18;
87
        plan tests => 26;
81
88
82
        my $rule;
89
        my $rule;
83
        Koha::CirculationRules->delete;
90
        Koha::CirculationRules->delete;
Lines 92-200 subtest 'get_effective_issuing_rule' => sub { Link Here
92
                        .' is returned.');
99
                        .' is returned.');
93
100
94
        ok(Koha::CirculationRule->new({
101
        ok(Koha::CirculationRule->new({
95
            branchcode => '*',
102
            branchcode => undef,
96
            categorycode => '*',
103
            categorycode => undef,
97
            itemtype => '*',
104
            itemtype => undef,
98
            rule_name => 'fine',
105
            rule_name => 'fine',
99
        })->store, 'Given I added an issuing rule branchcode => *, categorycode => *, itemtype => *,');
106
        })->store, 'Given I added an issuing rule branchcode => undef, categorycode => undef, itemtype => undef,');
100
        $rule = Koha::CirculationRules->get_effective_rule({
107
        $rule = Koha::CirculationRules->get_effective_rule({
101
            branchcode   => $branchcode,
108
            branchcode   => $branchcode,
102
            categorycode => $categorycode,
109
            categorycode => $categorycode,
103
            itemtype     => $itemtype,
110
            itemtype     => $itemtype,
104
            rule_name    => 'fine',
111
            rule_name    => 'fine',
105
        });
112
        });
106
        ok(_row_match($rule, '*', '*', '*'), 'When I attempt to get effective issuing rule,'
113
        _is_row_match(
107
           .' then the above one is returned.');
114
            $rule,
115
            {
116
                branchcode => undef,
117
                categorycode => undef,
118
                itemtype => undef
119
            },
120
            'When I attempt to get effective issuing rule,'
121
           .' then the above one is returned.'
122
        );
108
123
109
        ok(Koha::CirculationRule->new({
124
        ok(Koha::CirculationRule->new({
110
            branchcode => '*',
125
            branchcode => undef,
111
            categorycode => '*',
126
            categorycode => undef,
112
            itemtype => $itemtype,
127
            itemtype => $itemtype,
113
            rule_name => 'fine',
128
            rule_name => 'fine',
114
        })->store, "Given I added an issuing rule branchcode => *, categorycode => *, itemtype => $itemtype,");
129
        })->store, "Given I added an issuing rule branchcode => undef, categorycode => undef, itemtype => $itemtype,");
115
        $rule = Koha::CirculationRules->get_effective_rule({
130
        $rule = Koha::CirculationRules->get_effective_rule({
116
            branchcode   => $branchcode,
131
            branchcode   => $branchcode,
117
            categorycode => $categorycode,
132
            categorycode => $categorycode,
118
            itemtype     => $itemtype,
133
            itemtype     => $itemtype,
119
            rule_name    => 'fine',
134
            rule_name    => 'fine',
120
        });
135
        });
121
        ok(_row_match($rule, '*', '*', $itemtype), 'When I attempt to get effective issuing rule,'
136
        _is_row_match(
122
           .' then the above one is returned.');
137
            $rule,
138
            {
139
                branchcode => undef,
140
                categorycode => undef,
141
                itemtype => $itemtype
142
            },
143
            'When I attempt to get effective issuing rule,'
144
           .' then the above one is returned.'
145
        );
123
146
124
        ok(Koha::CirculationRule->new({
147
        ok(Koha::CirculationRule->new({
125
            branchcode => '*',
148
            branchcode => undef,
126
            categorycode => $categorycode,
149
            categorycode => $categorycode,
127
            itemtype => '*',
150
            itemtype => undef,
128
            rule_name => 'fine',
151
            rule_name => 'fine',
129
        })->store, "Given I added an issuing rule branchcode => *, categorycode => $categorycode, itemtype => *,");
152
        })->store, "Given I added an issuing rule branchcode => undef, categorycode => $categorycode, itemtype => undef,");
130
        $rule = Koha::CirculationRules->get_effective_rule({
153
        $rule = Koha::CirculationRules->get_effective_rule({
131
            branchcode   => $branchcode,
154
            branchcode   => $branchcode,
132
            categorycode => $categorycode,
155
            categorycode => $categorycode,
133
            itemtype     => $itemtype,
156
            itemtype     => $itemtype,
134
            rule_name    => 'fine',
157
            rule_name    => 'fine',
135
        });
158
        });
136
        ok(_row_match($rule, '*', $categorycode, '*'), 'When I attempt to get effective issuing rule,'
159
        _is_row_match(
137
           .' then the above one is returned.');
160
            $rule,
161
            {
162
                branchcode => undef,
163
                categorycode => $categorycode,
164
                itemtype => undef
165
            },
166
            'When I attempt to get effective issuing rule,'
167
           .' then the above one is returned.'
168
        );
138
169
139
        ok(Koha::CirculationRule->new({
170
        ok(Koha::CirculationRule->new({
140
            branchcode => '*',
171
            branchcode => undef,
141
            categorycode => $categorycode,
172
            categorycode => $categorycode,
142
            itemtype => $itemtype,
173
            itemtype => $itemtype,
143
            rule_name => 'fine',
174
            rule_name => 'fine',
144
        })->store, "Given I added an issuing rule branchcode => *, categorycode => $categorycode, itemtype => $itemtype,");
175
        })->store, "Given I added an issuing rule branchcode => undef, categorycode => $categorycode, itemtype => $itemtype,");
145
        $rule = Koha::CirculationRules->get_effective_rule({
176
        $rule = Koha::CirculationRules->get_effective_rule({
146
            branchcode   => $branchcode,
177
            branchcode   => $branchcode,
147
            categorycode => $categorycode,
178
            categorycode => $categorycode,
148
            itemtype     => $itemtype,
179
            itemtype     => $itemtype,
149
            rule_name    => 'fine',
180
            rule_name    => 'fine',
150
        });
181
        });
151
        ok(_row_match($rule, '*', $categorycode, $itemtype), 'When I attempt to get effective issuing rule,'
182
        _is_row_match(
152
           .' then the above one is returned.');
183
            $rule,
184
            {
185
                branchcode => undef,
186
                categorycode => $categorycode,
187
                itemtype => $itemtype
188
            },
189
            'When I attempt to get effective issuing rule,'
190
           .' then the above one is returned.'
191
        );
153
192
154
        ok(Koha::CirculationRule->new({
193
        ok(Koha::CirculationRule->new({
155
            branchcode => $branchcode,
194
            branchcode => $branchcode,
156
            categorycode => '*',
195
            categorycode => undef,
157
            itemtype => '*',
196
            itemtype => undef,
158
            rule_name => 'fine',
197
            rule_name => 'fine',
159
        })->store, "Given I added an issuing rule branchcode => $branchcode, categorycode => '*', itemtype => '*',");
198
        })->store, "Given I added an issuing rule branchcode => $branchcode, categorycode => undef, itemtype => undef,");
160
        $rule = Koha::CirculationRules->get_effective_rule({
199
        $rule = Koha::CirculationRules->get_effective_rule({
161
            branchcode   => $branchcode,
200
            branchcode   => $branchcode,
162
            categorycode => $categorycode,
201
            categorycode => $categorycode,
163
            itemtype     => $itemtype,
202
            itemtype     => $itemtype,
164
            rule_name    => 'fine',
203
            rule_name    => 'fine',
165
        });
204
        });
166
        ok(_row_match($rule, $branchcode, '*', '*'), 'When I attempt to get effective issuing rule,'
205
        _is_row_match(
167
           .' then the above one is returned.');
206
            $rule,
207
            {
208
                branchcode => $branchcode,
209
                categorycode => undef,
210
                itemtype => undef
211
            },
212
            'When I attempt to get effective issuing rule,'
213
           .' then the above one is returned.'
214
        );
168
215
169
        ok(Koha::CirculationRule->new({
216
        ok(Koha::CirculationRule->new({
170
            branchcode => $branchcode,
217
            branchcode => $branchcode,
171
            categorycode => '*',
218
            categorycode => undef,
172
            itemtype => $itemtype,
219
            itemtype => $itemtype,
173
            rule_name => 'fine',
220
            rule_name => 'fine',
174
        })->store, "Given I added an issuing rule branchcode => $branchcode, categorycode => '*', itemtype => $itemtype,");
221
        })->store, "Given I added an issuing rule branchcode => $branchcode, categorycode => undef, itemtype => $itemtype,");
175
        $rule = Koha::CirculationRules->get_effective_rule({
222
        $rule = Koha::CirculationRules->get_effective_rule({
176
            branchcode   => $branchcode,
223
            branchcode   => $branchcode,
177
            categorycode => $categorycode,
224
            categorycode => $categorycode,
178
            itemtype     => $itemtype,
225
            itemtype     => $itemtype,
179
            rule_name    => 'fine',
226
            rule_name    => 'fine',
180
        });
227
        });
181
        ok(_row_match($rule, $branchcode, '*', $itemtype), 'When I attempt to get effective issuing rule,'
228
        _is_row_match(
182
           .' then the above one is returned.');
229
            $rule,
230
            {
231
                branchcode => $branchcode,
232
                categorycode => undef,
233
                itemtype => $itemtype
234
            },
235
            'When I attempt to get effective issuing rule,'
236
           .' then the above one is returned.'
237
        );
183
238
184
        ok(Koha::CirculationRule->new({
239
        ok(Koha::CirculationRule->new({
185
            branchcode => $branchcode,
240
            branchcode => $branchcode,
186
            categorycode => $categorycode,
241
            categorycode => $categorycode,
187
            itemtype => '*',
242
            itemtype => undef,
188
            rule_name => 'fine',
243
            rule_name => 'fine',
189
        })->store, "Given I added an issuing rule branchcode => $branchcode, categorycode => $categorycode, itemtype => '*',");
244
        })->store, "Given I added an issuing rule branchcode => $branchcode, categorycode => $categorycode, itemtype => undef,");
190
        $rule = Koha::CirculationRules->get_effective_rule({
245
        $rule = Koha::CirculationRules->get_effective_rule({
191
            branchcode   => $branchcode,
246
            branchcode   => $branchcode,
192
            categorycode => $categorycode,
247
            categorycode => $categorycode,
193
            itemtype     => $itemtype,
248
            itemtype     => $itemtype,
194
            rule_name    => 'fine',
249
            rule_name    => 'fine',
195
        });
250
        });
196
        ok(_row_match($rule, $branchcode, $categorycode, '*'), 'When I attempt to get effective issuing rule,'
251
        _is_row_match(
197
           .' then the above one is returned.');
252
            $rule,
253
            {
254
                branchcode => $branchcode,
255
                categorycode => $categorycode,
256
                itemtype => undef
257
            },
258
            'When I attempt to get effective issuing rule,'
259
           .' then the above one is returned.'
260
        );
198
261
199
        ok(Koha::CirculationRule->new({
262
        ok(Koha::CirculationRule->new({
200
            branchcode => $branchcode,
263
            branchcode => $branchcode,
Lines 208-215 subtest 'get_effective_issuing_rule' => sub { Link Here
208
            itemtype     => $itemtype,
271
            itemtype     => $itemtype,
209
            rule_name    => 'fine',
272
            rule_name    => 'fine',
210
        });
273
        });
211
        ok(_row_match($rule, $branchcode, $categorycode, $itemtype), 'When I attempt to get effective issuing rule,'
274
        _is_row_match(
212
           .' then the above one is returned.');
275
            $rule,
276
            {
277
                branchcode => $branchcode,
278
                categorycode => $categorycode,
279
                itemtype => $itemtype
280
            },
281
            'When I attempt to get effective issuing rule,'
282
           .' then the above one is returned.'
283
        );
213
    };
284
    };
214
285
215
    subtest 'Performance' => sub {
286
    subtest 'Performance' => sub {
Lines 266-340 subtest 'get_effective_issuing_rule' => sub { Link Here
266
    };
337
    };
267
};
338
};
268
339
269
subtest 'get_opacitemholds_policy' => sub {
340
subtest 'set_rule' => sub {
270
    plan tests => 4;
271
    my $itype = $builder->build_object({ class => 'Koha::ItemTypes' });
272
    my $itemtype = $builder->build_object({ class => 'Koha::ItemTypes' });
273
    my $library = $builder->build_object({ class => 'Koha::Libraries' });
274
    my $patron = $builder->build_object({ class => 'Koha::Patrons' });
275
    my $biblio = $builder->build_object({ class => 'Koha::Biblios' });
276
    my $biblioitem = $builder->build_object( { class => 'Koha::Biblioitems', value => { itemtype => $itemtype->itemtype, biblionumber => $biblio->biblionumber } } );
277
    my $item = $builder->build_object(
278
        {   class  => 'Koha::Items',
279
            value  => {
280
                homebranch    => $library->branchcode,
281
                holdingbranch => $library->branchcode,
282
                notforloan    => 0,
283
                itemlost      => 0,
284
                withdrawn     => 0,
285
                biblionumber  => $biblio->biblionumber,
286
                biblioitemnumber => $biblioitem->biblioitemnumber,
287
                itype         => $itype->itemtype,
288
            }
289
        }
290
    );
291
292
    Koha::IssuingRules->delete;
293
    Koha::IssuingRule->new({categorycode => '*', itemtype => '*',                 branchcode => '*', opacitemholds => "N"})->store;
294
    Koha::IssuingRule->new({categorycode => '*', itemtype => $itype->itemtype,    branchcode => '*', opacitemholds => "Y"})->store;
295
    Koha::IssuingRule->new({categorycode => '*', itemtype => $itemtype->itemtype, branchcode => '*', opacitemholds => "N"})->store;
296
    t::lib::Mocks::mock_preference('item-level_itypes', 1);
297
    my $opacitemholds = Koha::IssuingRules->get_opacitemholds_policy( { item => $item, patron => $patron } );
298
    is ( $opacitemholds, 'Y', 'Patrons can place a hold on this itype');
299
    t::lib::Mocks::mock_preference('item-level_itypes', 0);
300
    $opacitemholds = Koha::IssuingRules->get_opacitemholds_policy( { item => $item, patron => $patron } );
301
    is ( $opacitemholds, 'N', 'Patrons cannot place a hold on this itemtype');
302
303
    Koha::IssuingRules->delete;
304
    Koha::IssuingRule->new({categorycode => '*', itemtype => '*',                 branchcode => '*', opacitemholds => "N"})->store;
305
    Koha::IssuingRule->new({categorycode => '*', itemtype => $itype->itemtype,    branchcode => '*', opacitemholds => "N"})->store;
306
    Koha::IssuingRule->new({categorycode => '*', itemtype => $itemtype->itemtype, branchcode => '*', opacitemholds => "Y"})->store;
307
    t::lib::Mocks::mock_preference('item-level_itypes', 1);
308
    $opacitemholds = Koha::IssuingRules->get_opacitemholds_policy( { item => $item, patron => $patron } );
309
    is ( $opacitemholds, 'N', 'Patrons cannot place a hold on this itype');
310
    t::lib::Mocks::mock_preference('item-level_itypes', 0);
311
    $opacitemholds = Koha::IssuingRules->get_opacitemholds_policy( { item => $item, patron => $patron } );
312
    is ( $opacitemholds, 'Y', 'Patrons can place a hold on this itemtype');
313
314
    $patron->delete;
315
};
316
317
subtest 'get_onshelfholds_policy' => sub {
318
    plan tests => 3;
341
    plan tests => 3;
319
342
320
    t::lib::Mocks::mock_preference('item-level_itypes', 1);
343
    my $branchcode   = $builder->build({ source => 'Branch' })->{'branchcode'};
321
    Koha::IssuingRules->delete;
344
    my $categorycode = $builder->build({ source => 'Category' })->{'categorycode'};
345
    my $itemtype     = $builder->build({ source => 'Itemtype' })->{'itemtype'};
322
346
323
    my $patron = $builder->build_object({ class => 'Koha::Patrons' });
347
    subtest 'Correct call' => sub {
324
    my $item = $builder->build_object({ class => 'Koha::Items' });
348
        plan tests => 4;
325
349
326
    is( Koha::IssuingRules->get_onshelfholds_policy({ item => $item, patron => $patron }), undef, 'Should return undef when no rules can be found' );
350
        Koha::CirculationRules->delete;
327
    Koha::IssuingRule->new({ categorycode => $patron->categorycode, itemtype => $item->itype, branchcode => '*', onshelfholds => "0" })->store;
351
328
    is( Koha::IssuingRules->get_onshelfholds_policy({ item => $item, patron => $patron }), 0, 'Should be zero' );
352
        lives_ok( sub {
329
    Koha::IssuingRule->new({ categorycode => $patron->categorycode, itemtype => $item->itype, branchcode => $item->holdingbranch, onshelfholds => "2" })->store;
353
            Koha::CirculationRules->set_rule( {
330
    is( Koha::IssuingRules->get_onshelfholds_policy({ item => $item, patron => $patron }), 2, 'Should be two now' );
354
                branchcode => $branchcode,
355
                rule_name => 'refund',
356
                rule_value => '',
357
            } );
358
        }, 'setting refund with branch' );
359
360
        lives_ok( sub {
361
            Koha::CirculationRules->set_rule( {
362
                branchcode => $branchcode,
363
                categorycode => $categorycode,
364
                rule_name => 'patron_maxissueqty',
365
                rule_value => '',
366
            } );
367
        }, 'setting patron_maxissueqty with branch/category succeeds' );
368
369
        lives_ok( sub {
370
            Koha::CirculationRules->set_rule( {
371
                branchcode => $branchcode,
372
                itemtype => $itemtype,
373
                rule_name => 'holdallowed',
374
                rule_value => '',
375
            } );
376
        }, 'setting holdallowed with branch/itemtype succeeds' );
377
378
        lives_ok( sub {
379
            Koha::CirculationRules->set_rule( {
380
                branchcode => $branchcode,
381
                categorycode => $categorycode,
382
                itemtype => $itemtype,
383
                rule_name => 'fine',
384
                rule_value => '',
385
            } );
386
        }, 'setting fine with branch/category/itemtype succeeds' );
387
    };
388
389
    subtest 'Call with missing params' => sub {
390
        plan tests => 4;
391
392
        Koha::CirculationRules->delete;
393
394
        throws_ok( sub {
395
            Koha::CirculationRules->set_rule( {
396
                rule_name => 'refund',
397
                rule_value => '',
398
            } );
399
        }, qr/branchcode/, 'setting refund without branch fails' );
400
401
        throws_ok( sub {
402
            Koha::CirculationRules->set_rule( {
403
                branchcode => $branchcode,
404
                rule_name => 'patron_maxissueqty',
405
                rule_value => '',
406
            } );
407
        }, qr/categorycode/, 'setting patron_maxissueqty without categorycode fails' );
408
409
        throws_ok( sub {
410
            Koha::CirculationRules->set_rule( {
411
                branchcode => $branchcode,
412
                rule_name => 'holdallowed',
413
                rule_value => '',
414
            } );
415
        }, qr/itemtype/, 'setting holdallowed without itemtype fails' );
416
417
        throws_ok( sub {
418
            Koha::CirculationRules->set_rule( {
419
                branchcode => $branchcode,
420
                categorycode => $categorycode,
421
                rule_name => 'fine',
422
                rule_value => '',
423
            } );
424
        }, qr/itemtype/, 'setting fine without itemtype fails' );
425
    };
426
427
    subtest 'Call with extra params' => sub {
428
        plan tests => 3;
429
430
        Koha::CirculationRules->delete;
431
432
        throws_ok( sub {
433
            Koha::CirculationRules->set_rule( {
434
                branchcode => $branchcode,
435
                categorycode => $categorycode,
436
                rule_name => 'refund',
437
                rule_value => '',
438
            } );
439
        }, qr/categorycode/, 'setting refund with categorycode fails' );
440
441
        throws_ok( sub {
442
            Koha::CirculationRules->set_rule( {
443
                branchcode => $branchcode,
444
                categorycode => $categorycode,
445
                itemtype => $itemtype,
446
                rule_name => 'patron_maxissueqty',
447
                rule_value => '',
448
            } );
449
        }, qr/itemtype/, 'setting patron_maxissueqty with itemtype fails' );
450
451
        throws_ok( sub {
452
            Koha::CirculationRules->set_rule( {
453
                branchcode => $branchcode,
454
                rule_name => 'holdallowed',
455
                categorycode => $categorycode,
456
                itemtype => $itemtype,
457
                rule_value => '',
458
            } );
459
        }, qr/categorycode/, 'setting holdallowed with categorycode fails' );
460
    };
331
};
461
};
332
462
333
sub _row_match {
463
sub _is_row_match {
334
    my ($rule, $branchcode, $categorycode, $itemtype) = @_;
464
    my ( $rule, $expected, $message ) = @_;
335
465
336
    return $rule->branchcode eq $branchcode && $rule->categorycode eq $categorycode
466
    ok( $rule, $message ) ?
337
            && $rule->itemtype eq $itemtype;
467
        cmp_methods( $rule, [ %$expected ], $message ) :
468
        fail( $message );
338
}
469
}
339
470
340
$schema->storage->txn_rollback;
471
$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 355-366 subtest 'build_object() tests' => sub { Link Here
355
355
356
    $builder = t::lib::TestBuilder->new();
356
    $builder = t::lib::TestBuilder->new();
357
357
358
    my $branchcode = $builder->build( { source => 'Branch' } )->{branchcode};
358
    my $categorycode = $builder->build( { source => 'Category' } )->{categorycode};
359
    my $categorycode = $builder->build( { source => 'Category' } )->{categorycode};
359
    my $itemtype = $builder->build( { source => 'Itemtype' } )->{itemtype};
360
    my $itemtype = $builder->build( { source => 'Itemtype' } )->{itemtype};
360
361
361
    my $issuing_rule = $builder->build_object(
362
    my $issuing_rule = $builder->build_object(
362
        {   class => 'Koha::CirculationRules',
363
        {   class => 'Koha::CirculationRules',
363
            value => {
364
            value => {
365
                branchcode   => $branchcode,
364
                categorycode => $categorycode,
366
                categorycode => $categorycode,
365
                itemtype     => $itemtype
367
                itemtype     => $itemtype
366
            }
368
            }
(-)a/t/db_dependent/api/v1/holds.t (-4 / +3 lines)
Lines 140-148 $dbh->do('DELETE FROM reserves'); Link Here
140
Koha::CirculationRules->search()->delete();
140
Koha::CirculationRules->search()->delete();
141
Koha::CirculationRules->set_rules(
141
Koha::CirculationRules->set_rules(
142
    {
142
    {
143
        categorycode => '*',
143
        categorycode => undef,
144
        branchcode   => '*',
144
        branchcode   => undef,
145
        itemtype     => '*',
145
        itemtype     => undef,
146
        rules        => {
146
        rules        => {
147
            reservesallowed => 1,
147
            reservesallowed => 1,
148
            holds_per_record => 99
148
            holds_per_record => 99
149
- 

Return to bug 18936