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 202-216 sub get_effective_rule { Link Here
202
    }
199
    }
203
200
204
    my $order_by = $params->{order_by}
201
    my $order_by = $params->{order_by}
205
      // { -desc => [ 'branchcode', 'categorycode', 'itemtype' ] };
202
      // { -desc => [ 'has_priority', 'branchcode', 'categorycode', 'itemtype' ] };
206
203
207
    my $search_params;
204
    my $search_params;
208
    $search_params->{rule_name} = $rule_name;
205
    $search_params->{rule_name} = $rule_name;
209
210
    $search_params->{categorycode} = defined $categorycode ? [ $categorycode, undef ] : undef;
206
    $search_params->{categorycode} = defined $categorycode ? [ $categorycode, undef ] : undef;
211
    $search_params->{itemtype}     = defined $itemtype     ? [ $itemtype, undef ] : undef;
207
    $search_params->{has_priority} = 1;
212
    $search_params->{branchcode}   = defined $branchcode   ? [ $branchcode,   undef ] : undef;
213
    $search_params->{has_priority} = defined $has_priority ? [ $has_priority, undef ] : undef;
214
208
215
    my $rule = $self->search(
209
    my $rule = $self->search(
216
        $search_params,
210
        $search_params,
Lines 220-225 sub get_effective_rule { Link Here
220
        }
214
        }
221
    )->single;
215
    )->single;
222
216
217
    return $rule if defined $rule;
218
219
    $search_params->{itemtype}     = defined $itemtype     ? [ $itemtype,     undef ] : undef;
220
    $search_params->{has_priority} = defined $has_priority ? [ $has_priority, undef ] : undef;
221
    $search_params->{branchcode}   = defined $branchcode   ? [ $branchcode,   undef ] : undef;
222
223
    $rule = $self->search(
224
        $search_params,
225
        {
226
            order_by => $order_by,
227
            rows => 1,
228
        }
229
    )->single;
230
223
    return $rule;
231
    return $rule;
224
}
232
}
225
233
Lines 284-289 sub set_rule { Link Here
284
    my $branchcode   = $params->{branchcode};
292
    my $branchcode   = $params->{branchcode};
285
    my $categorycode = $params->{categorycode};
293
    my $categorycode = $params->{categorycode};
286
    my $itemtype     = $params->{itemtype};
294
    my $itemtype     = $params->{itemtype};
295
    my $has_priority = $params->{has_priority};
287
    my $rule_name    = $params->{rule_name};
296
    my $rule_name    = $params->{rule_name};
288
    my $rule_value   = $params->{rule_value};
297
    my $rule_value   = $params->{rule_value};
289
    my $can_be_blank = defined $kind_info->{can_be_blank} ? $kind_info->{can_be_blank} : 1;
298
    my $can_be_blank = defined $kind_info->{can_be_blank} ? $kind_info->{can_be_blank} : 1;
Lines 298-303 sub set_rule { Link Here
298
            branchcode   => $branchcode,
307
            branchcode   => $branchcode,
299
            categorycode => $categorycode,
308
            categorycode => $categorycode,
300
            itemtype     => $itemtype,
309
            itemtype     => $itemtype,
310
            has_priority => $has_priority,
301
        }
311
        }
302
    )->next();
312
    )->next();
303
313
Lines 317-322 sub set_rule { Link Here
317
                    branchcode   => $branchcode,
327
                    branchcode   => $branchcode,
318
                    categorycode => $categorycode,
328
                    categorycode => $categorycode,
319
                    itemtype     => $itemtype,
329
                    itemtype     => $itemtype,
330
                    has_priority => $has_priority,
320
                    rule_name    => $rule_name,
331
                    rule_name    => $rule_name,
321
                    rule_value   => $rule_value,
332
                    rule_value   => $rule_value,
322
                }
333
                }
Lines 339-345 sub set_rules { Link Here
339
    $set_params{branchcode} = $params->{branchcode} if exists $params->{branchcode};
350
    $set_params{branchcode} = $params->{branchcode} if exists $params->{branchcode};
340
    $set_params{categorycode} = $params->{categorycode} if exists $params->{categorycode};
351
    $set_params{categorycode} = $params->{categorycode} if exists $params->{categorycode};
341
    $set_params{itemtype} = $params->{itemtype} if exists $params->{itemtype};
352
    $set_params{itemtype} = $params->{itemtype} if exists $params->{itemtype};
342
    my $rules        = $params->{rules};
353
    $set_params{has_priority} = $params->{has_priority} if exists $params->{has_priority};
354
    my $rules = $params->{rules};
343
355
344
    my $rule_objects = [];
356
    my $rule_objects = [];
345
    while ( my ( $rule_name, $rule_value ) = each %$rules ) {
357
    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 117-128 if ($op eq 'delete') { Link Here
117
}
119
}
118
elsif ($op eq 'delete-branch-cat') {
120
elsif ($op eq 'delete-branch-cat') {
119
    my $categorycode  = $input->param('categorycode');
121
    my $categorycode  = $input->param('categorycode');
122
    my $has_priority  = $input->param('has_priority') ? 1 : undef;
120
    if ($branch eq "*") {
123
    if ($branch eq "*") {
121
        if ($categorycode eq "*") {
124
        if ($categorycode eq "*") {
122
            Koha::CirculationRules->set_rules(
125
            Koha::CirculationRules->set_rules(
123
                {
126
                {
124
                    branchcode   => undef,
127
                    branchcode   => undef,
125
                    categorycode => undef,
128
                    categorycode => undef,
129
                    has_priority => $has_priority,
126
                    rules        => {
130
                    rules        => {
127
                        max_holds                      => undef,
131
                        max_holds                      => undef,
128
                        patron_maxissueqty             => undef,
132
                        patron_maxissueqty             => undef,
Lines 146-151 elsif ($op eq 'delete-branch-cat') { Link Here
146
                {
150
                {
147
                    categorycode => $categorycode,
151
                    categorycode => $categorycode,
148
                    branchcode   => undef,
152
                    branchcode   => undef,
153
                    has_priority => $has_priority,
149
                    rules        => {
154
                    rules        => {
150
                        max_holds                => undef,
155
                        max_holds                => undef,
151
                        patron_maxissueqty       => undef,
156
                        patron_maxissueqty       => undef,
Lines 159-164 elsif ($op eq 'delete-branch-cat') { Link Here
159
            {
164
            {
160
                branchcode   => $branch,
165
                branchcode   => $branch,
161
                categorycode => undef,
166
                categorycode => undef,
167
                has_priority => $has_priority,
162
                rules        => {
168
                rules        => {
163
                    max_holds                => undef,
169
                    max_holds                => undef,
164
                    patron_maxissueqty       => undef,
170
                    patron_maxissueqty       => undef,
Lines 182-187 elsif ($op eq 'delete-branch-cat') { Link Here
182
            {
188
            {
183
                categorycode => $categorycode,
189
                categorycode => $categorycode,
184
                branchcode   => $branch,
190
                branchcode   => $branch,
191
                has_priority => $has_priority,
185
                rules        => {
192
                rules        => {
186
                    max_holds         => undef,
193
                    max_holds         => undef,
187
                    patron_maxissueqty       => undef,
194
                    patron_maxissueqty       => undef,
Lines 250-256 elsif ($op eq 'add') { Link Here
250
    my $br = $branch; # branch
257
    my $br = $branch; # branch
251
    my $bor  = $input->param('categorycode'); # borrower category
258
    my $bor  = $input->param('categorycode'); # borrower category
252
    my $itemtype  = $input->param('itemtype');     # item type
259
    my $itemtype  = $input->param('itemtype');     # item type
253
    my $has_priority = $input->param('has_priority') ? 1 : 0;
260
    my $has_priority = $input->param('has_priority') ? 1 : undef;
254
    my $fine = $input->param('fine');
261
    my $fine = $input->param('fine');
255
    my $finedays     = $input->param('finedays');
262
    my $finedays     = $input->param('finedays');
256
    my $maxsuspensiondays = $input->param('maxsuspensiondays') || '';
263
    my $maxsuspensiondays = $input->param('maxsuspensiondays') || '';
Lines 295-301 elsif ($op eq 'add') { Link Here
295
        maxissueqty                   => $maxissueqty,
302
        maxissueqty                   => $maxissueqty,
296
        maxonsiteissueqty             => $maxonsiteissueqty,
303
        maxonsiteissueqty             => $maxonsiteissueqty,
297
        rentaldiscount                => $rentaldiscount,
304
        rentaldiscount                => $rentaldiscount,
298
        has_priority                  => $has_priority,
299
        fine                          => $fine,
305
        fine                          => $fine,
300
        finedays                      => $finedays,
306
        finedays                      => $finedays,
301
        maxsuspensiondays             => $maxsuspensiondays,
307
        maxsuspensiondays             => $maxsuspensiondays,
Lines 330-336 elsif ($op eq 'add') { Link Here
330
            categorycode => $bor eq '*' ? undef : $bor,
336
            categorycode => $bor eq '*' ? undef : $bor,
331
            itemtype     => $itemtype eq '*' ? undef : $itemtype,
337
            itemtype     => $itemtype eq '*' ? undef : $itemtype,
332
            branchcode   => $br eq '*' ? undef : $br,
338
            branchcode   => $br eq '*' ? undef : $br,
333
	    has_priority => $has_priority,
339
            has_priority => $has_priority,
334
            rules        => $rules,
340
            rules        => $rules,
335
        }
341
        }
336
    );
342
    );
Lines 345-356 elsif ($op eq "set-branch-defaults") { Link Here
345
    my $hold_fulfillment_policy = $input->param('hold_fulfillment_policy');
351
    my $hold_fulfillment_policy = $input->param('hold_fulfillment_policy');
346
    my $returnbranch  = $input->param('returnbranch');
352
    my $returnbranch  = $input->param('returnbranch');
347
    my $max_holds = strip_non_numeric( scalar $input->param('max_holds') );
353
    my $max_holds = strip_non_numeric( scalar $input->param('max_holds') );
354
    my $has_priority = $input->param('has_priority') ? 1 : undef;
348
355
349
    if ($branch eq "*") {
356
    if ($branch eq "*") {
350
        Koha::CirculationRules->set_rules(
357
        Koha::CirculationRules->set_rules(
351
            {
358
            {
352
                itemtype     => undef,
359
                itemtype     => undef,
353
                branchcode   => undef,
360
                branchcode   => undef,
361
                has_priority => $has_priority,
354
                rules        => {
362
                rules        => {
355
                    holdallowed             => $holdallowed,
363
                    holdallowed             => $holdallowed,
356
                    hold_fulfillment_policy => $hold_fulfillment_policy,
364
                    hold_fulfillment_policy => $hold_fulfillment_policy,
Lines 362-370 elsif ($op eq "set-branch-defaults") { Link Here
362
            {
370
            {
363
                categorycode => undef,
371
                categorycode => undef,
364
                branchcode   => undef,
372
                branchcode   => undef,
373
                has_priority => $has_priority,
365
                rules        => {
374
                rules        => {
366
                    patron_maxissueqty             => $patron_maxissueqty,
375
                    patron_maxissueqty             => $patron_maxissueqty,
367
                    patron_maxonsiteissueqty       => $patron_maxonsiteissueqty,
376
                    patron_maxonsiteissueqty       => $patron_maxonsiteissueqty,
377
                    patron_has_priority      => $has_priority,
368
                }
378
                }
369
            }
379
            }
370
        );
380
        );
Lines 373-378 elsif ($op eq "set-branch-defaults") { Link Here
373
            {
383
            {
374
                itemtype     => undef,
384
                itemtype     => undef,
375
                branchcode   => $branch,
385
                branchcode   => $branch,
386
                has_priority => $has_priority,
376
                rules        => {
387
                rules        => {
377
                    holdallowed             => $holdallowed,
388
                    holdallowed             => $holdallowed,
378
                    hold_fulfillment_policy => $hold_fulfillment_policy,
389
                    hold_fulfillment_policy => $hold_fulfillment_policy,
Lines 384-389 elsif ($op eq "set-branch-defaults") { Link Here
384
            {
395
            {
385
                categorycode => undef,
396
                categorycode => undef,
386
                branchcode   => $branch,
397
                branchcode   => $branch,
398
                has_priority => $has_priority,
387
                rules        => {
399
                rules        => {
388
                    patron_maxissueqty             => $patron_maxissueqty,
400
                    patron_maxissueqty             => $patron_maxissueqty,
389
                    patron_maxonsiteissueqty       => $patron_maxonsiteissueqty,
401
                    patron_maxonsiteissueqty       => $patron_maxonsiteissueqty,
Lines 408-415 elsif ($op eq "add-branch-cat") { Link Here
408
    my $max_holds = $input->param('max_holds');
420
    my $max_holds = $input->param('max_holds');
409
    $max_holds =~ s/\s//g;
421
    $max_holds =~ s/\s//g;
410
    $max_holds = undef if $max_holds !~ /^\d+/;
422
    $max_holds = undef if $max_holds !~ /^\d+/;
411
    my $has_priority = $input->param('has_priority');
423
    my $has_priority = $input->param('has_priority') ? 1 : undef;
412
    $has_priority = $has_priority ? 1 : 0;
413
424
414
    if ($branch eq "*") {
425
    if ($branch eq "*") {
415
        if ($categorycode eq "*") {
426
        if ($categorycode eq "*") {
Lines 417-422 elsif ($op eq "add-branch-cat") { Link Here
417
                {
428
                {
418
                    categorycode => undef,
429
                    categorycode => undef,
419
                    branchcode   => undef,
430
                    branchcode   => undef,
431
                    has_priority => $has_priority,
420
                    rules        => {
432
                    rules        => {
421
                        max_holds         => $max_holds,
433
                        max_holds         => $max_holds,
422
                        patron_maxissueqty       => $patron_maxissueqty,
434
                        patron_maxissueqty       => $patron_maxissueqty,
Lines 430-440 elsif ($op eq "add-branch-cat") { Link Here
430
                {
442
                {
431
                    categorycode => $categorycode,
443
                    categorycode => $categorycode,
432
                    branchcode   => undef,
444
                    branchcode   => undef,
445
                    has_priority => $has_priority,
433
                    rules        => {
446
                    rules        => {
434
                        max_holds         => $max_holds,
447
                        max_holds         => $max_holds,
435
                        patron_maxissueqty       => $patron_maxissueqty,
448
                        patron_maxissueqty       => $patron_maxissueqty,
436
                        patron_maxonsiteissueqty => $patron_maxonsiteissueqty,
449
                        patron_maxonsiteissueqty => $patron_maxonsiteissueqty,
437
                        has_priority      => $has_priority,
438
                    }
450
                    }
439
                }
451
                }
440
            );
452
            );
Lines 444-454 elsif ($op eq "add-branch-cat") { Link Here
444
            {
456
            {
445
                categorycode => undef,
457
                categorycode => undef,
446
                branchcode   => $branch,
458
                branchcode   => $branch,
459
                has_priority => $has_priority,
447
                rules        => {
460
                rules        => {
448
                    max_holds         => $max_holds,
461
                    max_holds         => $max_holds,
449
                    patron_maxissueqty       => $patron_maxissueqty,
462
                    patron_maxissueqty       => $patron_maxissueqty,
450
                    patron_maxonsiteissueqty => $patron_maxonsiteissueqty,
463
                    patron_maxonsiteissueqty => $patron_maxonsiteissueqty,
451
                    has_priority      => $has_priority,
452
                }
464
                }
453
            }
465
            }
454
        );
466
        );
Lines 457-467 elsif ($op eq "add-branch-cat") { Link Here
457
            {
469
            {
458
                categorycode => $categorycode,
470
                categorycode => $categorycode,
459
                branchcode   => $branch,
471
                branchcode   => $branch,
472
                has_priority => $has_priority,
460
                rules        => {
473
                rules        => {
461
                    max_holds         => $max_holds,
474
                    max_holds         => $max_holds,
462
                    patron_maxissueqty       => $patron_maxissueqty,
475
                    patron_maxissueqty       => $patron_maxissueqty,
463
                    patron_maxonsiteissueqty => $patron_maxonsiteissueqty,
476
                    patron_maxonsiteissueqty => $patron_maxonsiteissueqty,
464
                    has_priority      => $has_priority,
465
                }
477
                }
466
            }
478
            }
467
        );
479
        );
Lines 573-578 my $rules = {}; Link Here
573
while ( my $r = $all_rules->next ) {
585
while ( my $r = $all_rules->next ) {
574
    $r = $r->unblessed;
586
    $r = $r->unblessed;
575
    $rules->{ $r->{categorycode} // '' }->{ $r->{itemtype} // '' }->{ $r->{rule_name} } = $r->{rule_value};
587
    $rules->{ $r->{categorycode} // '' }->{ $r->{itemtype} // '' }->{ $r->{rule_name} } = $r->{rule_value};
588
    $rules->{ $r->{categorycode} // '' }->{ $r->{itemtype} // '' }->{ 'has_priority' } = $r->{has_priority};
576
}
589
}
577
590
578
$template->param(show_branch_cat_rule_form => 1);
591
$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 4432-4437 CREATE TABLE `circulation_rules` ( Link Here
4432
  `branchcode` varchar(10) NULL default NULL,
4432
  `branchcode` varchar(10) NULL default NULL,
4433
  `categorycode` varchar(10) NULL default NULL,
4433
  `categorycode` varchar(10) NULL default NULL,
4434
  `itemtype` varchar(10) NULL default NULL,
4434
  `itemtype` varchar(10) NULL default NULL,
4435
  `has_priority` tinyint(1) NULL default NULL,
4435
  `rule_name` varchar(32) NOT NULL,
4436
  `rule_name` varchar(32) NOT NULL,
4436
  `rule_value` varchar(32) NOT NULL,
4437
  `rule_value` varchar(32) NOT NULL,
4437
  PRIMARY KEY (`id`),
4438
  PRIMARY KEY (`id`),
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt (-7 / +9 lines)
Lines 135-140 Link Here
135
                    [% FOREACH i IN itemtypes %]
135
                    [% FOREACH i IN itemtypes %]
136
                        [% SET i = '' UNLESS i.defined %]
136
                        [% SET i = '' UNLESS i.defined %]
137
                        [% SET note = all_rules.$c.$i.note %]
137
                        [% SET note = all_rules.$c.$i.note %]
138
                        [% SET has_priority = all_rules.$c.$i.has_priority %]
138
                        [% SET maxissueqty = all_rules.$c.$i.maxissueqty %]
139
                        [% SET maxissueqty = all_rules.$c.$i.maxissueqty %]
139
                        [% SET maxonsiteissueqty = all_rules.$c.$i.maxonsiteissueqty %]
140
                        [% SET maxonsiteissueqty = all_rules.$c.$i.maxonsiteissueqty %]
140
                        [% SET issuelength = all_rules.$c.$i.issuelength %]
141
                        [% SET issuelength = all_rules.$c.$i.issuelength %]
Lines 196-202 Link Here
196
                                    </td>
197
                                    </td>
197
                                    [% UNLESS humanbranch %]
198
                                    [% UNLESS humanbranch %]
198
                                    <td>
199
                                    <td>
199
                                        [% IF rule.has_priority %]
200
                                        [% IF has_priority.defined && has_priority %]
200
                                            <input type="checkbox" checked="checked" disabled="disabled"/>
201
                                            <input type="checkbox" checked="checked" disabled="disabled"/>
201
                                        [% ELSE %]
202
                                        [% ELSE %]
202
                                            <input type="checkbox" disabled="disabled"/>
203
                                            <input type="checkbox" disabled="disabled"/>
Lines 690-696 Link Here
690
        </p>
691
        </p>
691
        <p>
692
        <p>
692
            <b>Has priority: </b>If checked, the rule will override those for all branches. Else
693
            <b>Has priority: </b>If checked, the rule will override those for all branches. Else
693
            it behaves like a default one: used if no rule existe for the coresponding branch.
694
            it behaves like a default one: used if no rule exists for the coresponding branch.
694
        </p>
695
        </p>
695
        <form method="post" action="/cgi-bin/koha/admin/smart-rules.pl">
696
        <form method="post" action="/cgi-bin/koha/admin/smart-rules.pl">
696
            <input type="hidden" name="op" value="add-branch-cat" />
697
            <input type="hidden" name="op" value="add-branch-cat" />
Lines 704-715 Link Here
704
                    [% UNLESS humanbranch %]<th>Has priority</th>[% END %]
705
                    [% UNLESS humanbranch %]<th>Has priority</th>[% END %]
705
                    <th>&nbsp;</th>
706
                    <th>&nbsp;</th>
706
                </tr>
707
                </tr>
708
                [% SET i = '' %]
707
                [% FOREACH c IN categorycodes %]
709
                [% FOREACH c IN categorycodes %]
708
                    [% NEXT UNLESS c %]
710
                    [% NEXT UNLESS c %]
709
                    [% SET patron_maxissueqty = CirculationRules.Search( branchcode, c, undef, 'patron_maxissueqty' ) %]
711
                    [% SET patron_maxissueqty = all_rules.$c.$i.patron_maxissueqty %]
710
                    [% SET patron_maxonsiteissueqty = CirculationRules.Search( branchcode, c, undef, 'patron_maxonsiteissueqty' ) %]
712
                    [% SET patron_maxonsiteissueqty = all_rules.$c.$i.patron_maxonsiteissueqty %]
711
                    [% SET max_holds = CirculationRules.Search( branchcode, c, undef, 'max_holds' ) %]
713
                    [% SET max_holds = all_rules.$c.$i.max_holds %]
712
714
                    [% SET has_priority = all_rules.$c.$i.has_priority %]
713
                    [% IF  ( patron_maxissueqty.defined && patron_maxissueqty != '' ) || ( patron_maxonsiteissueqty.defined && patron_maxonsiteissueqty != '' ) || ( max_holds.defined && max_holds != '' ) %]
715
                    [% IF  ( patron_maxissueqty.defined && patron_maxissueqty != '' ) || ( patron_maxonsiteissueqty.defined && patron_maxonsiteissueqty != '' ) || ( max_holds.defined && max_holds != '' ) %]
714
                    <tr>
716
                    <tr>
715
                        <td>
717
                        <td>
Lines 742-748 Link Here
742
                        </td>
744
                        </td>
743
                        [% UNLESS humanbranch %]
745
                        [% UNLESS humanbranch %]
744
                            <td>
746
                            <td>
745
                                [% IF branch_cat_rule_loo.has_priority %]
747
                                [% IF has_priority.defined && has_priority %]
746
                                    <input type="checkbox" checked="checked" disabled/>
748
                                    <input type="checkbox" checked="checked" disabled/>
747
                                [% ELSE %]
749
                                [% ELSE %]
748
                                    <input type="checkbox" disabled/>
750
                                    <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