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

(-)a/Koha/CirculationRule.pm (+10 lines)
Lines 71-76 sub item_type { Link Here
71
    return $self->{item_type};
71
    return $self->{item_type};
72
}
72
}
73
73
74
=head3 priority
75
76
=cut
77
78
sub priority {
79
    my ($self) = @_;
80
81
    return $self->has_priority;
82
}
83
74
=head3 clone
84
=head3 clone
75
85
76
Clone a circulation rule to another branch
86
Clone a circulation rule to another branch
(-)a/Koha/CirculationRules.pm (-9 / +21 lines)
Lines 59-67 our $RULE_KINDS = { Link Here
59
    max_holds => {
59
    max_holds => {
60
        scope => [ 'branchcode', 'categorycode' ],
60
        scope => [ 'branchcode', 'categorycode' ],
61
    },
61
    },
62
    has_priority => {
63
	scope => [ 'branchcode', 'categorycode' ],
64
    },
65
    holdallowed => {
62
    holdallowed => {
66
        scope => [ 'branchcode', 'itemtype' ],
63
        scope => [ 'branchcode', 'itemtype' ],
67
        can_be_blank => 0,
64
        can_be_blank => 0,
Lines 208-222 sub get_effective_rule { Link Here
208
    }
205
    }
209
206
210
    my $order_by = $params->{order_by}
207
    my $order_by = $params->{order_by}
211
      // { -desc => [ 'branchcode', 'categorycode', 'itemtype' ] };
208
      // { -desc => [ 'has_priority', 'branchcode', 'categorycode', 'itemtype' ] };
212
209
213
    my $search_params;
210
    my $search_params;
214
    $search_params->{rule_name} = $rule_name;
211
    $search_params->{rule_name} = $rule_name;
215
216
    $search_params->{categorycode} = defined $categorycode ? [ $categorycode, undef ] : undef;
212
    $search_params->{categorycode} = defined $categorycode ? [ $categorycode, undef ] : undef;
217
    $search_params->{itemtype}     = defined $itemtype     ? [ $itemtype, undef ] : undef;
213
    $search_params->{has_priority} = 1;
218
    $search_params->{branchcode}   = defined $branchcode   ? [ $branchcode,   undef ] : undef;
219
    $search_params->{has_priority} = defined $has_priority ? [ $has_priority, undef ] : undef;
220
214
221
    my $rule = $self->search(
215
    my $rule = $self->search(
222
        $search_params,
216
        $search_params,
Lines 226-231 sub get_effective_rule { Link Here
226
        }
220
        }
227
    )->single;
221
    )->single;
228
222
223
    return $rule if defined $rule;
224
225
    $search_params->{itemtype}     = defined $itemtype     ? [ $itemtype,     undef ] : undef;
226
    $search_params->{has_priority} = defined $has_priority ? [ $has_priority, undef ] : undef;
227
    $search_params->{branchcode}   = defined $branchcode   ? [ $branchcode,   undef ] : undef;
228
229
    $rule = $self->search(
230
        $search_params,
231
        {
232
            order_by => $order_by,
233
            rows => 1,
234
        }
235
    )->single;
236
229
    return $rule;
237
    return $rule;
230
}
238
}
231
239
Lines 290-295 sub set_rule { Link Here
290
    my $branchcode   = $params->{branchcode};
298
    my $branchcode   = $params->{branchcode};
291
    my $categorycode = $params->{categorycode};
299
    my $categorycode = $params->{categorycode};
292
    my $itemtype     = $params->{itemtype};
300
    my $itemtype     = $params->{itemtype};
301
    my $has_priority = $params->{has_priority};
293
    my $rule_name    = $params->{rule_name};
302
    my $rule_name    = $params->{rule_name};
294
    my $rule_value   = $params->{rule_value};
303
    my $rule_value   = $params->{rule_value};
295
    my $can_be_blank = defined $kind_info->{can_be_blank} ? $kind_info->{can_be_blank} : 1;
304
    my $can_be_blank = defined $kind_info->{can_be_blank} ? $kind_info->{can_be_blank} : 1;
Lines 304-309 sub set_rule { Link Here
304
            branchcode   => $branchcode,
313
            branchcode   => $branchcode,
305
            categorycode => $categorycode,
314
            categorycode => $categorycode,
306
            itemtype     => $itemtype,
315
            itemtype     => $itemtype,
316
            has_priority => $has_priority,
307
        }
317
        }
308
    )->next();
318
    )->next();
309
319
Lines 323-328 sub set_rule { Link Here
323
                    branchcode   => $branchcode,
333
                    branchcode   => $branchcode,
324
                    categorycode => $categorycode,
334
                    categorycode => $categorycode,
325
                    itemtype     => $itemtype,
335
                    itemtype     => $itemtype,
336
                    has_priority => $has_priority,
326
                    rule_name    => $rule_name,
337
                    rule_name    => $rule_name,
327
                    rule_value   => $rule_value,
338
                    rule_value   => $rule_value,
328
                }
339
                }
Lines 345-351 sub set_rules { Link Here
345
    $set_params{branchcode} = $params->{branchcode} if exists $params->{branchcode};
356
    $set_params{branchcode} = $params->{branchcode} if exists $params->{branchcode};
346
    $set_params{categorycode} = $params->{categorycode} if exists $params->{categorycode};
357
    $set_params{categorycode} = $params->{categorycode} if exists $params->{categorycode};
347
    $set_params{itemtype} = $params->{itemtype} if exists $params->{itemtype};
358
    $set_params{itemtype} = $params->{itemtype} if exists $params->{itemtype};
348
    my $rules        = $params->{rules};
359
    $set_params{has_priority} = $params->{has_priority} if exists $params->{has_priority};
360
    my $rules = $params->{rules};
349
361
350
    my $rule_objects = [];
362
    my $rule_objects = [];
351
    while ( my ( $rule_name, $rule_value ) = each %$rules ) {
363
    while ( my ( $rule_name, $rule_value ) = each %$rules ) {
(-)a/Koha/Schema/Result/CirculationRule.pm (-2 / +9 lines)
Lines 50-55 __PACKAGE__->table("circulation_rules"); Link Here
50
  is_nullable: 1
50
  is_nullable: 1
51
  size: 10
51
  size: 10
52
52
53
=head2 has_priority
54
55
  data_type: 'integer'
56
  is_nullable: 1
57
53
=head2 rule_name
58
=head2 rule_name
54
59
55
  data_type: 'varchar'
60
  data_type: 'varchar'
Lines 73-78 __PACKAGE__->add_columns( Link Here
73
  { data_type => "varchar", is_foreign_key => 1, is_nullable => 1, size => 10 },
78
  { data_type => "varchar", is_foreign_key => 1, is_nullable => 1, size => 10 },
74
  "itemtype",
79
  "itemtype",
75
  { data_type => "varchar", is_foreign_key => 1, is_nullable => 1, size => 10 },
80
  { data_type => "varchar", is_foreign_key => 1, is_nullable => 1, size => 10 },
81
  "has_priority",
82
  { data_type => "integer", is_nullable => 1, is_boolean => 1 },
76
  "rule_name",
83
  "rule_name",
77
  { data_type => "varchar", is_nullable => 0, size => 32 },
84
  { data_type => "varchar", is_nullable => 0, size => 32 },
78
  "rule_value",
85
  "rule_value",
Lines 177-184 __PACKAGE__->belongs_to( Link Here
177
);
184
);
178
185
179
186
180
# Created by DBIx::Class::Schema::Loader v0.07042 @ 2018-10-05 14:29:17
187
# Created by DBIx::Class::Schema::Loader v0.07046 @ 2020-07-22 13:19:28
181
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:QHMqvrtX0ohJe70PHUYZ0Q
188
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:1mg3weVQdfPTJ+jX6X5K+Q
182
189
183
sub koha_objects_class {
190
sub koha_objects_class {
184
    'Koha::CirculationRules';
191
    'Koha::CirculationRules';
(-)a/admin/smart-rules.pl (-8 / +21 lines)
Lines 73-78 $cache->clear_from_cache( Koha::CirculationRules::GUESSED_ITEMTYPES_KEY ); Link Here
73
if ($op eq 'delete') {
73
if ($op eq 'delete') {
74
    my $itemtype     = $input->param('itemtype');
74
    my $itemtype     = $input->param('itemtype');
75
    my $categorycode = $input->param('categorycode');
75
    my $categorycode = $input->param('categorycode');
76
    my $has_priority = $input->param('has_priority') ? 1 : undef;
76
    $debug and warn "deleting $1 $2 $branch";
77
    $debug and warn "deleting $1 $2 $branch";
77
78
78
    Koha::CirculationRules->set_rules(
79
    Koha::CirculationRules->set_rules(
Lines 80-85 if ($op eq 'delete') { Link Here
80
            categorycode => $categorycode eq '*' ? undef : $categorycode,
81
            categorycode => $categorycode eq '*' ? undef : $categorycode,
81
            branchcode   => $branch eq '*' ? undef : $branch,
82
            branchcode   => $branch eq '*' ? undef : $branch,
82
            itemtype     => $itemtype eq '*' ? undef : $itemtype,
83
            itemtype     => $itemtype eq '*' ? undef : $itemtype,
84
            has_priority => $has_priority,
83
            rules        => {
85
            rules        => {
84
                maxissueqty                      => undef,
86
                maxissueqty                      => undef,
85
                maxonsiteissueqty                => undef,
87
                maxonsiteissueqty                => undef,
Lines 118-129 if ($op eq 'delete') { Link Here
118
}
120
}
119
elsif ($op eq 'delete-branch-cat') {
121
elsif ($op eq 'delete-branch-cat') {
120
    my $categorycode  = $input->param('categorycode');
122
    my $categorycode  = $input->param('categorycode');
123
    my $has_priority  = $input->param('has_priority') ? 1 : undef;
121
    if ($branch eq "*") {
124
    if ($branch eq "*") {
122
        if ($categorycode eq "*") {
125
        if ($categorycode eq "*") {
123
            Koha::CirculationRules->set_rules(
126
            Koha::CirculationRules->set_rules(
124
                {
127
                {
125
                    branchcode   => undef,
128
                    branchcode   => undef,
126
                    categorycode => undef,
129
                    categorycode => undef,
130
                    has_priority => $has_priority,
127
                    rules        => {
131
                    rules        => {
128
                        max_holds                      => undef,
132
                        max_holds                      => undef,
129
                        patron_maxissueqty             => undef,
133
                        patron_maxissueqty             => undef,
Lines 147-152 elsif ($op eq 'delete-branch-cat') { Link Here
147
                {
151
                {
148
                    categorycode => $categorycode,
152
                    categorycode => $categorycode,
149
                    branchcode   => undef,
153
                    branchcode   => undef,
154
                    has_priority => $has_priority,
150
                    rules        => {
155
                    rules        => {
151
                        max_holds                => undef,
156
                        max_holds                => undef,
152
                        patron_maxissueqty       => undef,
157
                        patron_maxissueqty       => undef,
Lines 160-165 elsif ($op eq 'delete-branch-cat') { Link Here
160
            {
165
            {
161
                branchcode   => $branch,
166
                branchcode   => $branch,
162
                categorycode => undef,
167
                categorycode => undef,
168
                has_priority => $has_priority,
163
                rules        => {
169
                rules        => {
164
                    max_holds                => undef,
170
                    max_holds                => undef,
165
                    patron_maxissueqty       => undef,
171
                    patron_maxissueqty       => undef,
Lines 183-188 elsif ($op eq 'delete-branch-cat') { Link Here
183
            {
189
            {
184
                categorycode => $categorycode,
190
                categorycode => $categorycode,
185
                branchcode   => $branch,
191
                branchcode   => $branch,
192
                has_priority => $has_priority,
186
                rules        => {
193
                rules        => {
187
                    max_holds         => undef,
194
                    max_holds         => undef,
188
                    patron_maxissueqty       => undef,
195
                    patron_maxissueqty       => undef,
Lines 251-257 elsif ($op eq 'add') { Link Here
251
    my $br = $branch; # branch
258
    my $br = $branch; # branch
252
    my $bor  = $input->param('categorycode'); # borrower category
259
    my $bor  = $input->param('categorycode'); # borrower category
253
    my $itemtype  = $input->param('itemtype');     # item type
260
    my $itemtype  = $input->param('itemtype');     # item type
254
    my $has_priority = $input->param('has_priority') ? 1 : 0;
261
    my $has_priority = $input->param('has_priority') ? 1 : undef;
255
    my $fine = $input->param('fine');
262
    my $fine = $input->param('fine');
256
    my $finedays     = $input->param('finedays');
263
    my $finedays     = $input->param('finedays');
257
    my $maxsuspensiondays = $input->param('maxsuspensiondays') || '';
264
    my $maxsuspensiondays = $input->param('maxsuspensiondays') || '';
Lines 298-304 elsif ($op eq 'add') { Link Here
298
        maxissueqty                   => $maxissueqty,
305
        maxissueqty                   => $maxissueqty,
299
        maxonsiteissueqty             => $maxonsiteissueqty,
306
        maxonsiteissueqty             => $maxonsiteissueqty,
300
        rentaldiscount                => $rentaldiscount,
307
        rentaldiscount                => $rentaldiscount,
301
        has_priority                  => $has_priority,
302
        fine                          => $fine,
308
        fine                          => $fine,
303
        finedays                      => $finedays,
309
        finedays                      => $finedays,
304
        maxsuspensiondays             => $maxsuspensiondays,
310
        maxsuspensiondays             => $maxsuspensiondays,
Lines 335-341 elsif ($op eq 'add') { Link Here
335
            categorycode => $bor eq '*' ? undef : $bor,
341
            categorycode => $bor eq '*' ? undef : $bor,
336
            itemtype     => $itemtype eq '*' ? undef : $itemtype,
342
            itemtype     => $itemtype eq '*' ? undef : $itemtype,
337
            branchcode   => $br eq '*' ? undef : $br,
343
            branchcode   => $br eq '*' ? undef : $br,
338
	    has_priority => $has_priority,
344
            has_priority => $has_priority,
339
            rules        => $rules,
345
            rules        => $rules,
340
        }
346
        }
341
    );
347
    );
Lines 350-361 elsif ($op eq "set-branch-defaults") { Link Here
350
    my $hold_fulfillment_policy = $input->param('hold_fulfillment_policy');
356
    my $hold_fulfillment_policy = $input->param('hold_fulfillment_policy');
351
    my $returnbranch  = $input->param('returnbranch');
357
    my $returnbranch  = $input->param('returnbranch');
352
    my $max_holds = strip_non_numeric( scalar $input->param('max_holds') );
358
    my $max_holds = strip_non_numeric( scalar $input->param('max_holds') );
359
    my $has_priority = $input->param('has_priority') ? 1 : undef;
353
360
354
    if ($branch eq "*") {
361
    if ($branch eq "*") {
355
        Koha::CirculationRules->set_rules(
362
        Koha::CirculationRules->set_rules(
356
            {
363
            {
357
                itemtype     => undef,
364
                itemtype     => undef,
358
                branchcode   => undef,
365
                branchcode   => undef,
366
                has_priority => $has_priority,
359
                rules        => {
367
                rules        => {
360
                    holdallowed             => $holdallowed,
368
                    holdallowed             => $holdallowed,
361
                    hold_fulfillment_policy => $hold_fulfillment_policy,
369
                    hold_fulfillment_policy => $hold_fulfillment_policy,
Lines 367-375 elsif ($op eq "set-branch-defaults") { Link Here
367
            {
375
            {
368
                categorycode => undef,
376
                categorycode => undef,
369
                branchcode   => undef,
377
                branchcode   => undef,
378
                has_priority => $has_priority,
370
                rules        => {
379
                rules        => {
371
                    patron_maxissueqty             => $patron_maxissueqty,
380
                    patron_maxissueqty             => $patron_maxissueqty,
372
                    patron_maxonsiteissueqty       => $patron_maxonsiteissueqty,
381
                    patron_maxonsiteissueqty       => $patron_maxonsiteissueqty,
382
                    patron_has_priority      => $has_priority,
373
                }
383
                }
374
            }
384
            }
375
        );
385
        );
Lines 378-383 elsif ($op eq "set-branch-defaults") { Link Here
378
            {
388
            {
379
                itemtype     => undef,
389
                itemtype     => undef,
380
                branchcode   => $branch,
390
                branchcode   => $branch,
391
                has_priority => $has_priority,
381
                rules        => {
392
                rules        => {
382
                    holdallowed             => $holdallowed,
393
                    holdallowed             => $holdallowed,
383
                    hold_fulfillment_policy => $hold_fulfillment_policy,
394
                    hold_fulfillment_policy => $hold_fulfillment_policy,
Lines 389-394 elsif ($op eq "set-branch-defaults") { Link Here
389
            {
400
            {
390
                categorycode => undef,
401
                categorycode => undef,
391
                branchcode   => $branch,
402
                branchcode   => $branch,
403
                has_priority => $has_priority,
392
                rules        => {
404
                rules        => {
393
                    patron_maxissueqty             => $patron_maxissueqty,
405
                    patron_maxissueqty             => $patron_maxissueqty,
394
                    patron_maxonsiteissueqty       => $patron_maxonsiteissueqty,
406
                    patron_maxonsiteissueqty       => $patron_maxonsiteissueqty,
Lines 413-420 elsif ($op eq "add-branch-cat") { Link Here
413
    my $max_holds = $input->param('max_holds');
425
    my $max_holds = $input->param('max_holds');
414
    $max_holds =~ s/\s//g;
426
    $max_holds =~ s/\s//g;
415
    $max_holds = undef if $max_holds !~ /^\d+/;
427
    $max_holds = undef if $max_holds !~ /^\d+/;
416
    my $has_priority = $input->param('has_priority');
428
    my $has_priority = $input->param('has_priority') ? 1 : undef;
417
    $has_priority = $has_priority ? 1 : 0;
418
429
419
    if ($branch eq "*") {
430
    if ($branch eq "*") {
420
        if ($categorycode eq "*") {
431
        if ($categorycode eq "*") {
Lines 422-427 elsif ($op eq "add-branch-cat") { Link Here
422
                {
433
                {
423
                    categorycode => undef,
434
                    categorycode => undef,
424
                    branchcode   => undef,
435
                    branchcode   => undef,
436
                    has_priority => $has_priority,
425
                    rules        => {
437
                    rules        => {
426
                        max_holds         => $max_holds,
438
                        max_holds         => $max_holds,
427
                        patron_maxissueqty       => $patron_maxissueqty,
439
                        patron_maxissueqty       => $patron_maxissueqty,
Lines 435-445 elsif ($op eq "add-branch-cat") { Link Here
435
                {
447
                {
436
                    categorycode => $categorycode,
448
                    categorycode => $categorycode,
437
                    branchcode   => undef,
449
                    branchcode   => undef,
450
                    has_priority => $has_priority,
438
                    rules        => {
451
                    rules        => {
439
                        max_holds         => $max_holds,
452
                        max_holds         => $max_holds,
440
                        patron_maxissueqty       => $patron_maxissueqty,
453
                        patron_maxissueqty       => $patron_maxissueqty,
441
                        patron_maxonsiteissueqty => $patron_maxonsiteissueqty,
454
                        patron_maxonsiteissueqty => $patron_maxonsiteissueqty,
442
                        has_priority      => $has_priority,
443
                    }
455
                    }
444
                }
456
                }
445
            );
457
            );
Lines 449-459 elsif ($op eq "add-branch-cat") { Link Here
449
            {
461
            {
450
                categorycode => undef,
462
                categorycode => undef,
451
                branchcode   => $branch,
463
                branchcode   => $branch,
464
                has_priority => $has_priority,
452
                rules        => {
465
                rules        => {
453
                    max_holds         => $max_holds,
466
                    max_holds         => $max_holds,
454
                    patron_maxissueqty       => $patron_maxissueqty,
467
                    patron_maxissueqty       => $patron_maxissueqty,
455
                    patron_maxonsiteissueqty => $patron_maxonsiteissueqty,
468
                    patron_maxonsiteissueqty => $patron_maxonsiteissueqty,
456
                    has_priority      => $has_priority,
457
                }
469
                }
458
            }
470
            }
459
        );
471
        );
Lines 462-472 elsif ($op eq "add-branch-cat") { Link Here
462
            {
474
            {
463
                categorycode => $categorycode,
475
                categorycode => $categorycode,
464
                branchcode   => $branch,
476
                branchcode   => $branch,
477
                has_priority => $has_priority,
465
                rules        => {
478
                rules        => {
466
                    max_holds         => $max_holds,
479
                    max_holds         => $max_holds,
467
                    patron_maxissueqty       => $patron_maxissueqty,
480
                    patron_maxissueqty       => $patron_maxissueqty,
468
                    patron_maxonsiteissueqty => $patron_maxonsiteissueqty,
481
                    patron_maxonsiteissueqty => $patron_maxonsiteissueqty,
469
                    has_priority      => $has_priority,
470
                }
482
                }
471
            }
483
            }
472
        );
484
        );
Lines 578-583 my $rules = {}; Link Here
578
while ( my $r = $all_rules->next ) {
590
while ( my $r = $all_rules->next ) {
579
    $r = $r->unblessed;
591
    $r = $r->unblessed;
580
    $rules->{ $r->{categorycode} // '' }->{ $r->{itemtype} // '' }->{ $r->{rule_name} } = $r->{rule_value};
592
    $rules->{ $r->{categorycode} // '' }->{ $r->{itemtype} // '' }->{ $r->{rule_name} } = $r->{rule_value};
593
    $rules->{ $r->{categorycode} // '' }->{ $r->{itemtype} // '' }->{ 'has_priority' } = $r->{has_priority};
581
}
594
}
582
595
583
$template->param(show_branch_cat_rule_form => 1);
596
$template->param(show_branch_cat_rule_form => 1);
(-)a/installer/data/mysql/atomicupdate/Bug_8137-add-column-has_priority.sql (-5 / +2 lines)
Lines 1-5 Link Here
1
ALTER TABLE default_borrower_circ_rules ADD has_priority INT(1) DEFAULT 0;
1
ALTER TABLE circulation_rules ADD has_priority INT(1) DEFAULT NULL AFTER itemtype;
2
ALTER TABLE default_borrower_circ_rules DROP foreign key borrower_borrower_circ_rules_ibfk_1;
2
ALTER TABLE circulation_rules ADD KEY (branchcode , categorycode, itemtype, has_priority);
3
ALTER TABLE default_borrower_circ_rules DROP primary key;
4
ALTER TABLE default_borrower_circ_rules ADD primary key(categorycode, has_priority);
5
ALTER TABLE default_borrower_circ_rules ADD CONSTRAINT borrower_borrower_circ_rules_ibfk_1 FOREIGN KEY (categorycode) REFERENCES categories (categorycode) ON DELETE CASCADE ON UPDATE CASCADE;
(-)a/installer/data/mysql/kohastructure.sql (+1 lines)
Lines 1663-1668 CREATE TABLE `circulation_rules` ( Link Here
1663
  `branchcode` varchar(10) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
1663
  `branchcode` varchar(10) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
1664
  `categorycode` varchar(10) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
1664
  `categorycode` varchar(10) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
1665
  `itemtype` varchar(10) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
1665
  `itemtype` varchar(10) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
1666
  `has_priority` tinyint(1) NULL default NULL,
1666
  `rule_name` varchar(32) COLLATE utf8mb4_unicode_ci NOT NULL,
1667
  `rule_name` varchar(32) COLLATE utf8mb4_unicode_ci NOT NULL,
1667
  `rule_value` varchar(32) COLLATE utf8mb4_unicode_ci NOT NULL,
1668
  `rule_value` varchar(32) COLLATE utf8mb4_unicode_ci NOT NULL,
1668
  PRIMARY KEY (`id`),
1669
  PRIMARY KEY (`id`),
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt (-7 / +9 lines)
Lines 139-144 Link Here
139
                    [% FOREACH i IN itemtypes %]
139
                    [% FOREACH i IN itemtypes %]
140
                        [% SET i = '' UNLESS i.defined %]
140
                        [% SET i = '' UNLESS i.defined %]
141
                        [% SET note = all_rules.$c.$i.note %]
141
                        [% SET note = all_rules.$c.$i.note %]
142
                        [% SET has_priority = all_rules.$c.$i.has_priority %]
142
                        [% SET maxissueqty = all_rules.$c.$i.maxissueqty %]
143
                        [% SET maxissueqty = all_rules.$c.$i.maxissueqty %]
143
                        [% SET maxonsiteissueqty = all_rules.$c.$i.maxonsiteissueqty %]
144
                        [% SET maxonsiteissueqty = all_rules.$c.$i.maxonsiteissueqty %]
144
                        [% SET issuelength = all_rules.$c.$i.issuelength %]
145
                        [% SET issuelength = all_rules.$c.$i.issuelength %]
Lines 202-208 Link Here
202
                                    </td>
203
                                    </td>
203
                                    [% UNLESS humanbranch %]
204
                                    [% UNLESS humanbranch %]
204
                                    <td>
205
                                    <td>
205
                                        [% IF rule.has_priority %]
206
                                        [% IF has_priority.defined && has_priority %]
206
                                            <input type="checkbox" checked="checked" disabled="disabled"/>
207
                                            <input type="checkbox" checked="checked" disabled="disabled"/>
207
                                        [% ELSE %]
208
                                        [% ELSE %]
208
                                            <input type="checkbox" disabled="disabled"/>
209
                                            <input type="checkbox" disabled="disabled"/>
Lines 708-714 Link Here
708
        </p>
709
        </p>
709
        <p>
710
        <p>
710
            <b>Has priority: </b>If checked, the rule will override those for all branches. Else
711
            <b>Has priority: </b>If checked, the rule will override those for all branches. Else
711
            it behaves like a default one: used if no rule existe for the coresponding branch.
712
            it behaves like a default one: used if no rule exists for the coresponding branch.
712
        </p>
713
        </p>
713
        <form method="post" action="/cgi-bin/koha/admin/smart-rules.pl">
714
        <form method="post" action="/cgi-bin/koha/admin/smart-rules.pl">
714
            <input type="hidden" name="op" value="add-branch-cat" />
715
            <input type="hidden" name="op" value="add-branch-cat" />
Lines 722-733 Link Here
722
                    [% UNLESS humanbranch %]<th>Has priority</th>[% END %]
723
                    [% UNLESS humanbranch %]<th>Has priority</th>[% END %]
723
                    <th>&nbsp;</th>
724
                    <th>&nbsp;</th>
724
                </tr>
725
                </tr>
726
                [% SET i = '' %]
725
                [% FOREACH c IN categorycodes %]
727
                [% FOREACH c IN categorycodes %]
726
                    [% NEXT UNLESS c %]
728
                    [% NEXT UNLESS c %]
727
                    [% SET patron_maxissueqty = CirculationRules.Search( branchcode, c, undef, 'patron_maxissueqty' ) %]
729
                    [% SET patron_maxissueqty = all_rules.$c.$i.patron_maxissueqty %]
728
                    [% SET patron_maxonsiteissueqty = CirculationRules.Search( branchcode, c, undef, 'patron_maxonsiteissueqty' ) %]
730
                    [% SET patron_maxonsiteissueqty = all_rules.$c.$i.patron_maxonsiteissueqty %]
729
                    [% SET max_holds = CirculationRules.Search( branchcode, c, undef, 'max_holds' ) %]
731
                    [% SET max_holds = all_rules.$c.$i.max_holds %]
730
732
                    [% SET has_priority = all_rules.$c.$i.has_priority %]
731
                    [% IF  ( patron_maxissueqty.defined && patron_maxissueqty != '' ) || ( patron_maxonsiteissueqty.defined && patron_maxonsiteissueqty != '' ) || ( max_holds.defined && max_holds != '' ) %]
733
                    [% IF  ( patron_maxissueqty.defined && patron_maxissueqty != '' ) || ( patron_maxonsiteissueqty.defined && patron_maxonsiteissueqty != '' ) || ( max_holds.defined && max_holds != '' ) %]
732
                    <tr>
734
                    <tr>
733
                        <td>
735
                        <td>
Lines 760-766 Link Here
760
                        </td>
762
                        </td>
761
                        [% UNLESS humanbranch %]
763
                        [% UNLESS humanbranch %]
762
                            <td>
764
                            <td>
763
                                [% IF branch_cat_rule_loo.has_priority %]
765
                                [% IF has_priority.defined && has_priority %]
764
                                    <input type="checkbox" checked="checked" disabled/>
766
                                    <input type="checkbox" checked="checked" disabled/>
765
                                [% ELSE %]
767
                                [% ELSE %]
766
                                    <input type="checkbox" disabled/>
768
                                    <input type="checkbox" disabled/>
(-)a/t/db_dependent/Circulation/Branch.t (-14 / +36 lines)
Lines 155-161 Koha::CirculationRules->set_rules( Link Here
155
            patron_maxissueqty       => 5,
155
            patron_maxissueqty       => 5,
156
            patron_maxonsiteissueqty => 6,
156
            patron_maxonsiteissueqty => 6,
157
        }
157
        }
158
    }
158
   }
159
);
159
);
160
160
161
161
Lines 232-243 Koha::CirculationRules->set_rules( Link Here
232
    }
232
    }
233
);
233
);
234
234
235
$query = q|
235
Koha::CirculationRules->set_rules(
236
    INSERT INTO default_borrower_circ_rules
236
    {
237
    (categorycode, maxissueqty, maxonsiteissueqty, has_priority)
237
        branchcode   => undef,
238
    VALUES( ?, ?, ?, ? )
238
        categorycode => $samplecat->{categorycode},
239
|;
239
        rules        => {
240
$dbh->do($query, {}, $samplecat->{categorycode}, 3, 3, 0);
240
            patron_maxonsiteissueqty  => 3,
241
            patron_maxissueqty        => 3,
242
        }
243
    }
244
);
241
245
242
#Test GetBranchBorrowerCircRule
246
#Test GetBranchBorrowerCircRule
243
#
247
#
Lines 265-286 is_deeply( Link Here
265
"GetBranchBorrower with wrong parameters returns the patron_maxissueqty and patron_maxonsiteissueqty of default_circ_rules"
269
"GetBranchBorrower with wrong parameters returns the patron_maxissueqty and patron_maxonsiteissueqty of default_circ_rules"
266
);
270
);
267
271
268
$query = q|
272
269
    INSERT INTO default_borrower_circ_rules
273
Koha::CirculationRules->set_rules(
270
    (categorycode, maxissueqty, maxonsiteissueqty, has_priority)
274
    {
271
    VALUES( ?, ?, ?, ? )
275
        branchcode   => undef,
272
|;
276
        categorycode => $samplecat->{categorycode},
273
$dbh->do($query, {}, $samplecat->{categorycode}, 3, 3, 1);
277
        has_priority => 1,
278
        rules        => {
279
            patron_maxonsiteissueqty  => 3,
280
            patron_maxissueqty        => 3,
281
        }
282
    }
283
);
274
284
275
is_deeply(
285
is_deeply(
276
    GetBranchBorrowerCircRule(
286
    GetBranchBorrowerCircRule(
277
        $samplebranch1->{branchcode},
287
        $samplebranch1->{branchcode},
278
        $samplecat->{categorycode}
288
        $samplecat->{categorycode}
279
    ),
289
    ),
280
    { maxissueqty => 3, maxonsiteissueqty => 3, has_priority => 1 },
290
    { patron_maxissueqty => 3, patron_maxonsiteissueqty => 3 },
281
    "GetBranchBorrower returns the rule having priority"
291
    "GetBranchBorrower returns the rule having priority"
282
);
292
);
283
293
294
Koha::CirculationRules->set_rules(
295
    {
296
        branchcode   => undef,
297
        categorycode => $samplecat->{categorycode},
298
        has_priority => 0,
299
        rules        => {
300
            patron_maxonsiteissueqty  => 3,
301
            patron_maxissueqty        => 3,
302
        }
303
    }
304
);
305
284
#Test GetBranchItemRule
306
#Test GetBranchItemRule
285
my @lazy_any = ( 'hold_fulfillment_policy' => 'any' );
307
my @lazy_any = ( 'hold_fulfillment_policy' => 'any' );
286
is_deeply(
308
is_deeply(
(-)a/t/db_dependent/Koha/IssuingRules.t (-9 / +15 lines)
Lines 35-40 $schema->storage->txn_begin; Link Here
35
35
36
my $builder      = t::lib::TestBuilder->new;
36
my $builder      = t::lib::TestBuilder->new;
37
37
38
38
subtest 'get_effective_issuing_rule' => sub {
39
subtest 'get_effective_issuing_rule' => sub {
39
    plan tests => 3;
40
    plan tests => 3;
40
41
Lines 43-72 subtest 'get_effective_issuing_rule' => sub { Link Here
43
    my $branchcode   = $builder->build({ source => 'Branch' })->{'branchcode'};
44
    my $branchcode   = $builder->build({ source => 'Branch' })->{'branchcode'};
44
45
45
    subtest 'Priority rule' => sub {
46
    subtest 'Priority rule' => sub {
46
        plan tests => 3;
47
        plan tests => 4;
47
48
48
        Koha::IssuingRules->delete;
49
        Koha::CirculationRules->delete;
50
        is(Koha::CirculationRules->search->count, 0, 'There are no issuing rules.');
49
51
50
        ok(Koha::IssuingRule->new({
52
        ok(Koha::CirculationRule->new({
51
            branchcode => $branchcode,
53
            branchcode => $branchcode,
52
            categorycode => $categorycode,
54
            categorycode => $categorycode,
53
            itemtype => $itemtype,
55
            itemtype => $itemtype,
56
            rule_name => 'fine',
57
            rule_value => 0,
54
        })->store, "Given I added an issuing rule branchcode => $branchcode,'
58
        })->store, "Given I added an issuing rule branchcode => $branchcode,'
55
           .' categorycode => $categorycode, itemtype => $itemtype,");
59
           .' categorycode => $categorycode, itemtype => $itemtype,");
56
60
57
        ok(Koha::IssuingRule->new({
61
        ok(Koha::CirculationRule->new({
58
            branchcode => '*',
62
            branchcode => undef,
59
            categorycode => $categorycode,
63
            categorycode => $categorycode,
60
            itemtype => $itemtype,
64
            itemtype => $itemtype,
61
            has_priority => 1,
65
            has_priority => 1,
66
            rule_name => 'fine',
67
            rule_value => 1,
62
        })->store, "Add a priority rule.");
68
        })->store, "Add a priority rule.");
63
69
64
        my $rule = Koha::IssuingRules->get_effective_issuing_rule({
70
        my $rule = Koha::CirculationRules->get_effective_rule({
65
            branchcode   => $branchcode,
71
            branchcode   => $branchcode,
66
            categorycode => $categorycode,
72
            categorycode => $categorycode,
67
            itemtype     => $itemtype,
73
            itemtype     => $itemtype,
74
            has_priority => 1,
75
            rule_name    => 'fine',
68
        });
76
        });
69
        is($rule->has_priority, 1, 'Priority rule should be returned');
77
        is($rule->priority, 1, 'Priority rule should be returned');
70
    };
78
    };
71
79
72
    subtest 'Call with undefined values' => sub {
80
    subtest 'Call with undefined values' => sub {
Lines 416-419 sub _is_row_match { Link Here
416
}
424
}
417
425
418
$schema->storage->txn_rollback;
426
$schema->storage->txn_rollback;
419
420
- 

Return to bug 8137