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
    },
64
    },
Lines 199-213 sub get_effective_rule { Link Here
199
    }
196
    }
200
197
201
    my $order_by = $params->{order_by}
198
    my $order_by = $params->{order_by}
202
      // { -desc => [ 'branchcode', 'categorycode', 'itemtype' ] };
199
      // { -desc => [ 'has_priority', 'branchcode', 'categorycode', 'itemtype' ] };
203
200
204
    my $search_params;
201
    my $search_params;
205
    $search_params->{rule_name} = $rule_name;
202
    $search_params->{rule_name} = $rule_name;
206
207
    $search_params->{categorycode} = defined $categorycode ? [ $categorycode, undef ] : undef;
203
    $search_params->{categorycode} = defined $categorycode ? [ $categorycode, undef ] : undef;
208
    $search_params->{itemtype}     = defined $itemtype     ? [ $itemtype, undef ] : undef;
204
    $search_params->{has_priority} = 1;
209
    $search_params->{branchcode}   = defined $branchcode   ? [ $branchcode,   undef ] : undef;
210
    $search_params->{has_priority} = defined $has_priority ? [ $has_priority, undef ] : undef;
211
205
212
    my $rule = $self->search(
206
    my $rule = $self->search(
213
        $search_params,
207
        $search_params,
Lines 217-222 sub get_effective_rule { Link Here
217
        }
211
        }
218
    )->single;
212
    )->single;
219
213
214
    return $rule if defined $rule;
215
216
    $search_params->{itemtype}     = defined $itemtype     ? [ $itemtype,     undef ] : undef;
217
    $search_params->{has_priority} = defined $has_priority ? [ $has_priority, undef ] : undef;
218
    $search_params->{branchcode}   = defined $branchcode   ? [ $branchcode,   undef ] : undef;
219
220
    $rule = $self->search(
221
        $search_params,
222
        {
223
            order_by => $order_by,
224
            rows => 1,
225
        }
226
    )->single;
227
220
    return $rule;
228
    return $rule;
221
}
229
}
222
230
Lines 281-286 sub set_rule { Link Here
281
    my $branchcode   = $params->{branchcode};
289
    my $branchcode   = $params->{branchcode};
282
    my $categorycode = $params->{categorycode};
290
    my $categorycode = $params->{categorycode};
283
    my $itemtype     = $params->{itemtype};
291
    my $itemtype     = $params->{itemtype};
292
    my $has_priority = $params->{has_priority};
284
    my $rule_name    = $params->{rule_name};
293
    my $rule_name    = $params->{rule_name};
285
    my $rule_value   = $params->{rule_value};
294
    my $rule_value   = $params->{rule_value};
286
295
Lines 293-298 sub set_rule { Link Here
293
            branchcode   => $branchcode,
302
            branchcode   => $branchcode,
294
            categorycode => $categorycode,
303
            categorycode => $categorycode,
295
            itemtype     => $itemtype,
304
            itemtype     => $itemtype,
305
            has_priority => $has_priority,
296
        }
306
        }
297
    )->next();
307
    )->next();
298
308
Lines 312-317 sub set_rule { Link Here
312
                    branchcode   => $branchcode,
322
                    branchcode   => $branchcode,
313
                    categorycode => $categorycode,
323
                    categorycode => $categorycode,
314
                    itemtype     => $itemtype,
324
                    itemtype     => $itemtype,
325
                    has_priority => $has_priority,
315
                    rule_name    => $rule_name,
326
                    rule_name    => $rule_name,
316
                    rule_value   => $rule_value,
327
                    rule_value   => $rule_value,
317
                }
328
                }
Lines 334-340 sub set_rules { Link Here
334
    $set_params{branchcode} = $params->{branchcode} if exists $params->{branchcode};
345
    $set_params{branchcode} = $params->{branchcode} if exists $params->{branchcode};
335
    $set_params{categorycode} = $params->{categorycode} if exists $params->{categorycode};
346
    $set_params{categorycode} = $params->{categorycode} if exists $params->{categorycode};
336
    $set_params{itemtype} = $params->{itemtype} if exists $params->{itemtype};
347
    $set_params{itemtype} = $params->{itemtype} if exists $params->{itemtype};
337
    my $rules        = $params->{rules};
348
    $set_params{has_priority} = $params->{has_priority} if exists $params->{has_priority};
349
    my $rules = $params->{rules};
338
350
339
    my $rule_objects = [];
351
    my $rule_objects = [];
340
    while ( my ( $rule_name, $rule_value ) = each %$rules ) {
352
    while ( my ( $rule_name, $rule_value ) = each %$rules ) {
(-)a/Koha/Schema/Result/CirculationRule.pm (-2 / +8 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" => { is_boolean => 1 },
76
  "rule_name",
82
  "rule_name",
77
  { data_type => "varchar", is_nullable => 0, size => 32 },
83
  { data_type => "varchar", is_nullable => 0, size => 32 },
78
  "rule_value",
84
  "rule_value",
Lines 177-184 __PACKAGE__->belongs_to( Link Here
177
);
183
);
178
184
179
185
180
# Created by DBIx::Class::Schema::Loader v0.07042 @ 2018-10-05 14:29:17
186
# Created by DBIx::Class::Schema::Loader v0.07046 @ 2020-07-22 13:19:28
181
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:QHMqvrtX0ohJe70PHUYZ0Q
187
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:1mg3weVQdfPTJ+jX6X5K+Q
182
188
183
sub koha_objects_class {
189
sub koha_objects_class {
184
    'Koha::CirculationRules';
190
    'Koha::CirculationRules';
(-)a/admin/smart-rules.pl (-8 / +21 lines)
Lines 75-80 $cache->clear_from_cache( Koha::CirculationRules::GUESSED_ITEMTYPES_KEY ); Link Here
75
if ($op eq 'delete') {
75
if ($op eq 'delete') {
76
    my $itemtype     = $input->param('itemtype');
76
    my $itemtype     = $input->param('itemtype');
77
    my $categorycode = $input->param('categorycode');
77
    my $categorycode = $input->param('categorycode');
78
    my $has_priority = $input->param('has_priority') ? 1 : undef;
78
    $debug and warn "deleting $1 $2 $branch";
79
    $debug and warn "deleting $1 $2 $branch";
79
80
80
    Koha::CirculationRules->set_rules(
81
    Koha::CirculationRules->set_rules(
Lines 82-87 if ($op eq 'delete') { Link Here
82
            categorycode => $categorycode eq '*' ? undef : $categorycode,
83
            categorycode => $categorycode eq '*' ? undef : $categorycode,
83
            branchcode   => $branch eq '*' ? undef : $branch,
84
            branchcode   => $branch eq '*' ? undef : $branch,
84
            itemtype     => $itemtype eq '*' ? undef : $itemtype,
85
            itemtype     => $itemtype eq '*' ? undef : $itemtype,
86
            has_priority => $has_priority,
85
            rules        => {
87
            rules        => {
86
                maxissueqty                      => undef,
88
                maxissueqty                      => undef,
87
                maxonsiteissueqty                => undef,
89
                maxonsiteissueqty                => undef,
Lines 119-130 if ($op eq 'delete') { Link Here
119
}
121
}
120
elsif ($op eq 'delete-branch-cat') {
122
elsif ($op eq 'delete-branch-cat') {
121
    my $categorycode  = $input->param('categorycode');
123
    my $categorycode  = $input->param('categorycode');
124
    my $has_priority  = $input->param('has_priority') ? 1 : undef;
122
    if ($branch eq "*") {
125
    if ($branch eq "*") {
123
        if ($categorycode eq "*") {
126
        if ($categorycode eq "*") {
124
            Koha::CirculationRules->set_rules(
127
            Koha::CirculationRules->set_rules(
125
                {
128
                {
126
                    branchcode   => undef,
129
                    branchcode   => undef,
127
                    categorycode => undef,
130
                    categorycode => undef,
131
                    has_priority => $has_priority,
128
                    rules        => {
132
                    rules        => {
129
                        max_holds                      => undef,
133
                        max_holds                      => undef,
130
                        patron_maxissueqty             => undef,
134
                        patron_maxissueqty             => undef,
Lines 148-153 elsif ($op eq 'delete-branch-cat') { Link Here
148
                {
152
                {
149
                    categorycode => $categorycode,
153
                    categorycode => $categorycode,
150
                    branchcode   => undef,
154
                    branchcode   => undef,
155
                    has_priority => $has_priority,
151
                    rules        => {
156
                    rules        => {
152
                        max_holds                => undef,
157
                        max_holds                => undef,
153
                        patron_maxissueqty       => undef,
158
                        patron_maxissueqty       => undef,
Lines 161-166 elsif ($op eq 'delete-branch-cat') { Link Here
161
            {
166
            {
162
                branchcode   => $branch,
167
                branchcode   => $branch,
163
                categorycode => undef,
168
                categorycode => undef,
169
                has_priority => $has_priority,
164
                rules        => {
170
                rules        => {
165
                    max_holds                => undef,
171
                    max_holds                => undef,
166
                    patron_maxissueqty       => undef,
172
                    patron_maxissueqty       => undef,
Lines 184-189 elsif ($op eq 'delete-branch-cat') { Link Here
184
            {
190
            {
185
                categorycode => $categorycode,
191
                categorycode => $categorycode,
186
                branchcode   => $branch,
192
                branchcode   => $branch,
193
                has_priority => $has_priority,
187
                rules        => {
194
                rules        => {
188
                    max_holds         => undef,
195
                    max_holds         => undef,
189
                    patron_maxissueqty       => undef,
196
                    patron_maxissueqty       => undef,
Lines 252-258 elsif ($op eq 'add') { Link Here
252
    my $br = $branch; # branch
259
    my $br = $branch; # branch
253
    my $bor  = $input->param('categorycode'); # borrower category
260
    my $bor  = $input->param('categorycode'); # borrower category
254
    my $itemtype  = $input->param('itemtype');     # item type
261
    my $itemtype  = $input->param('itemtype');     # item type
255
    my $has_priority = $input->param('has_priority') ? 1 : 0;
262
    my $has_priority = $input->param('has_priority') ? 1 : undef;
256
    my $fine = $input->param('fine');
263
    my $fine = $input->param('fine');
257
    my $finedays     = $input->param('finedays');
264
    my $finedays     = $input->param('finedays');
258
    my $maxsuspensiondays = $input->param('maxsuspensiondays') || '';
265
    my $maxsuspensiondays = $input->param('maxsuspensiondays') || '';
Lines 297-303 elsif ($op eq 'add') { Link Here
297
        maxissueqty                   => $maxissueqty,
304
        maxissueqty                   => $maxissueqty,
298
        maxonsiteissueqty             => $maxonsiteissueqty,
305
        maxonsiteissueqty             => $maxonsiteissueqty,
299
        rentaldiscount                => $rentaldiscount,
306
        rentaldiscount                => $rentaldiscount,
300
        has_priority                  => $has_priority,
301
        fine                          => $fine,
307
        fine                          => $fine,
302
        finedays                      => $finedays,
308
        finedays                      => $finedays,
303
        maxsuspensiondays             => $maxsuspensiondays,
309
        maxsuspensiondays             => $maxsuspensiondays,
Lines 332-338 elsif ($op eq 'add') { Link Here
332
            categorycode => $bor eq '*' ? undef : $bor,
338
            categorycode => $bor eq '*' ? undef : $bor,
333
            itemtype     => $itemtype eq '*' ? undef : $itemtype,
339
            itemtype     => $itemtype eq '*' ? undef : $itemtype,
334
            branchcode   => $br eq '*' ? undef : $br,
340
            branchcode   => $br eq '*' ? undef : $br,
335
	    has_priority => $has_priority,
341
            has_priority => $has_priority,
336
            rules        => $rules,
342
            rules        => $rules,
337
        }
343
        }
338
    );
344
    );
Lines 347-352 elsif ($op eq "set-branch-defaults") { Link Here
347
    my $hold_fulfillment_policy = $input->param('hold_fulfillment_policy');
353
    my $hold_fulfillment_policy = $input->param('hold_fulfillment_policy');
348
    my $returnbranch  = $input->param('returnbranch');
354
    my $returnbranch  = $input->param('returnbranch');
349
    my $max_holds = strip_non_numeric( scalar $input->param('max_holds') );
355
    my $max_holds = strip_non_numeric( scalar $input->param('max_holds') );
356
    my $has_priority = $input->param('has_priority') ? 1 : undef;
350
    $holdallowed =~ s/\s//g;
357
    $holdallowed =~ s/\s//g;
351
    $holdallowed = undef if $holdallowed !~ /^\d+/;
358
    $holdallowed = undef if $holdallowed !~ /^\d+/;
352
359
Lines 355-360 elsif ($op eq "set-branch-defaults") { Link Here
355
            {
362
            {
356
                itemtype     => undef,
363
                itemtype     => undef,
357
                branchcode   => undef,
364
                branchcode   => undef,
365
                has_priority => $has_priority,
358
                rules        => {
366
                rules        => {
359
                    holdallowed             => $holdallowed,
367
                    holdallowed             => $holdallowed,
360
                    hold_fulfillment_policy => $hold_fulfillment_policy,
368
                    hold_fulfillment_policy => $hold_fulfillment_policy,
Lines 366-374 elsif ($op eq "set-branch-defaults") { Link Here
366
            {
374
            {
367
                categorycode => undef,
375
                categorycode => undef,
368
                branchcode   => undef,
376
                branchcode   => undef,
377
                has_priority => $has_priority,
369
                rules        => {
378
                rules        => {
370
                    patron_maxissueqty             => $patron_maxissueqty,
379
                    patron_maxissueqty             => $patron_maxissueqty,
371
                    patron_maxonsiteissueqty       => $patron_maxonsiteissueqty,
380
                    patron_maxonsiteissueqty       => $patron_maxonsiteissueqty,
381
                    patron_has_priority      => $has_priority,
372
                }
382
                }
373
            }
383
            }
374
        );
384
        );
Lines 377-382 elsif ($op eq "set-branch-defaults") { Link Here
377
            {
387
            {
378
                itemtype     => undef,
388
                itemtype     => undef,
379
                branchcode   => $branch,
389
                branchcode   => $branch,
390
                has_priority => $has_priority,
380
                rules        => {
391
                rules        => {
381
                    holdallowed             => $holdallowed,
392
                    holdallowed             => $holdallowed,
382
                    hold_fulfillment_policy => $hold_fulfillment_policy,
393
                    hold_fulfillment_policy => $hold_fulfillment_policy,
Lines 388-393 elsif ($op eq "set-branch-defaults") { Link Here
388
            {
399
            {
389
                categorycode => undef,
400
                categorycode => undef,
390
                branchcode   => $branch,
401
                branchcode   => $branch,
402
                has_priority => $has_priority,
391
                rules        => {
403
                rules        => {
392
                    patron_maxissueqty             => $patron_maxissueqty,
404
                    patron_maxissueqty             => $patron_maxissueqty,
393
                    patron_maxonsiteissueqty       => $patron_maxonsiteissueqty,
405
                    patron_maxonsiteissueqty       => $patron_maxonsiteissueqty,
Lines 412-419 elsif ($op eq "add-branch-cat") { Link Here
412
    my $max_holds = $input->param('max_holds');
424
    my $max_holds = $input->param('max_holds');
413
    $max_holds =~ s/\s//g;
425
    $max_holds =~ s/\s//g;
414
    $max_holds = undef if $max_holds !~ /^\d+/;
426
    $max_holds = undef if $max_holds !~ /^\d+/;
415
    my $has_priority = $input->param('has_priority');
427
    my $has_priority = $input->param('has_priority') ? 1 : undef;
416
    $has_priority = $has_priority ? 1 : 0;
417
428
418
    if ($branch eq "*") {
429
    if ($branch eq "*") {
419
        if ($categorycode eq "*") {
430
        if ($categorycode eq "*") {
Lines 421-426 elsif ($op eq "add-branch-cat") { Link Here
421
                {
432
                {
422
                    categorycode => undef,
433
                    categorycode => undef,
423
                    branchcode   => undef,
434
                    branchcode   => undef,
435
                    has_priority => $has_priority,
424
                    rules        => {
436
                    rules        => {
425
                        max_holds         => $max_holds,
437
                        max_holds         => $max_holds,
426
                        patron_maxissueqty       => $patron_maxissueqty,
438
                        patron_maxissueqty       => $patron_maxissueqty,
Lines 434-444 elsif ($op eq "add-branch-cat") { Link Here
434
                {
446
                {
435
                    categorycode => $categorycode,
447
                    categorycode => $categorycode,
436
                    branchcode   => undef,
448
                    branchcode   => undef,
449
                    has_priority => $has_priority,
437
                    rules        => {
450
                    rules        => {
438
                        max_holds         => $max_holds,
451
                        max_holds         => $max_holds,
439
                        patron_maxissueqty       => $patron_maxissueqty,
452
                        patron_maxissueqty       => $patron_maxissueqty,
440
                        patron_maxonsiteissueqty => $patron_maxonsiteissueqty,
453
                        patron_maxonsiteissueqty => $patron_maxonsiteissueqty,
441
                        has_priority      => $has_priority,
442
                    }
454
                    }
443
                }
455
                }
444
            );
456
            );
Lines 448-458 elsif ($op eq "add-branch-cat") { Link Here
448
            {
460
            {
449
                categorycode => undef,
461
                categorycode => undef,
450
                branchcode   => $branch,
462
                branchcode   => $branch,
463
                has_priority => $has_priority,
451
                rules        => {
464
                rules        => {
452
                    max_holds         => $max_holds,
465
                    max_holds         => $max_holds,
453
                    patron_maxissueqty       => $patron_maxissueqty,
466
                    patron_maxissueqty       => $patron_maxissueqty,
454
                    patron_maxonsiteissueqty => $patron_maxonsiteissueqty,
467
                    patron_maxonsiteissueqty => $patron_maxonsiteissueqty,
455
                    has_priority      => $has_priority,
456
                }
468
                }
457
            }
469
            }
458
        );
470
        );
Lines 461-471 elsif ($op eq "add-branch-cat") { Link Here
461
            {
473
            {
462
                categorycode => $categorycode,
474
                categorycode => $categorycode,
463
                branchcode   => $branch,
475
                branchcode   => $branch,
476
                has_priority => $has_priority,
464
                rules        => {
477
                rules        => {
465
                    max_holds         => $max_holds,
478
                    max_holds         => $max_holds,
466
                    patron_maxissueqty       => $patron_maxissueqty,
479
                    patron_maxissueqty       => $patron_maxissueqty,
467
                    patron_maxonsiteissueqty => $patron_maxonsiteissueqty,
480
                    patron_maxonsiteissueqty => $patron_maxonsiteissueqty,
468
                    has_priority      => $has_priority,
469
                }
481
                }
470
            }
482
            }
471
        );
483
        );
Lines 579-584 my $rules = {}; Link Here
579
while ( my $r = $all_rules->next ) {
591
while ( my $r = $all_rules->next ) {
580
    $r = $r->unblessed;
592
    $r = $r->unblessed;
581
    $rules->{ $r->{categorycode} // '' }->{ $r->{itemtype} // '' }->{ $r->{rule_name} } = $r->{rule_value};
593
    $rules->{ $r->{categorycode} // '' }->{ $r->{itemtype} // '' }->{ $r->{rule_name} } = $r->{rule_value};
594
    $rules->{ $r->{categorycode} // '' }->{ $r->{itemtype} // '' }->{ 'has_priority' } = $r->{has_priority};
582
}
595
}
583
596
584
$template->param(show_branch_cat_rule_form => 1);
597
$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 4359-4364 CREATE TABLE `circulation_rules` ( Link Here
4359
  `branchcode` varchar(10) NULL default NULL,
4359
  `branchcode` varchar(10) NULL default NULL,
4360
  `categorycode` varchar(10) NULL default NULL,
4360
  `categorycode` varchar(10) NULL default NULL,
4361
  `itemtype` varchar(10) NULL default NULL,
4361
  `itemtype` varchar(10) NULL default NULL,
4362
  `has_priority` tinyint(1) NULL default NULL,
4362
  `rule_name` varchar(32) NOT NULL,
4363
  `rule_name` varchar(32) NOT NULL,
4363
  `rule_value` varchar(32) NOT NULL,
4364
  `rule_value` varchar(32) NOT NULL,
4364
  PRIMARY KEY (`id`),
4365
  PRIMARY KEY (`id`),
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt (-7 / +9 lines)
Lines 129-134 Link Here
129
                    [% FOREACH i IN itemtypes %]
129
                    [% FOREACH i IN itemtypes %]
130
                        [% SET i = '' UNLESS i.defined %]
130
                        [% SET i = '' UNLESS i.defined %]
131
                        [% SET note = all_rules.$c.$i.note %]
131
                        [% SET note = all_rules.$c.$i.note %]
132
                        [% SET has_priority = all_rules.$c.$i.has_priority %]
132
                        [% SET maxissueqty = all_rules.$c.$i.maxissueqty %]
133
                        [% SET maxissueqty = all_rules.$c.$i.maxissueqty %]
133
                        [% SET maxonsiteissueqty = all_rules.$c.$i.maxonsiteissueqty %]
134
                        [% SET maxonsiteissueqty = all_rules.$c.$i.maxonsiteissueqty %]
134
                        [% SET issuelength = all_rules.$c.$i.issuelength %]
135
                        [% SET issuelength = all_rules.$c.$i.issuelength %]
Lines 188-194 Link Here
188
                                    </td>
189
                                    </td>
189
                                    [% UNLESS humanbranch %]
190
                                    [% UNLESS humanbranch %]
190
                                    <td>
191
                                    <td>
191
                                        [% IF rule.has_priority %]
192
                                        [% IF has_priority.defined && has_priority %]
192
                                            <input type="checkbox" checked="checked" disabled="disabled"/>
193
                                            <input type="checkbox" checked="checked" disabled="disabled"/>
193
                                        [% ELSE %]
194
                                        [% ELSE %]
194
                                            <input type="checkbox" disabled="disabled"/>
195
                                            <input type="checkbox" disabled="disabled"/>
Lines 666-672 Link Here
666
        </p>
667
        </p>
667
        <p>
668
        <p>
668
            <b>Has priority: </b>If checked, the rule will override those for all branches. Else
669
            <b>Has priority: </b>If checked, the rule will override those for all branches. Else
669
            it behaves like a default one: used if no rule existe for the coresponding branch.
670
            it behaves like a default one: used if no rule exists for the coresponding branch.
670
        </p>
671
        </p>
671
        <form method="post" action="/cgi-bin/koha/admin/smart-rules.pl">
672
        <form method="post" action="/cgi-bin/koha/admin/smart-rules.pl">
672
            <input type="hidden" name="op" value="add-branch-cat" />
673
            <input type="hidden" name="op" value="add-branch-cat" />
Lines 680-691 Link Here
680
                    [% UNLESS humanbranch %]<th>Has priority</th>[% END %]
681
                    [% UNLESS humanbranch %]<th>Has priority</th>[% END %]
681
                    <th>&nbsp;</th>
682
                    <th>&nbsp;</th>
682
                </tr>
683
                </tr>
684
                [% SET i = '' %]
683
                [% FOREACH c IN categorycodes %]
685
                [% FOREACH c IN categorycodes %]
684
                    [% NEXT UNLESS c %]
686
                    [% NEXT UNLESS c %]
685
                    [% SET patron_maxissueqty = CirculationRules.Search( branchcode, c, undef, 'patron_maxissueqty' ) %]
687
                    [% SET patron_maxissueqty = all_rules.$c.$i.patron_maxissueqty %]
686
                    [% SET patron_maxonsiteissueqty = CirculationRules.Search( branchcode, c, undef, 'patron_maxonsiteissueqty' ) %]
688
                    [% SET patron_maxonsiteissueqty = all_rules.$c.$i.patron_maxonsiteissueqty %]
687
                    [% SET max_holds = CirculationRules.Search( branchcode, c, undef, 'max_holds' ) %]
689
                    [% SET max_holds = all_rules.$c.$i.max_holds %]
688
690
                    [% SET has_priority = all_rules.$c.$i.has_priority %]
689
                    [% IF  ( patron_maxissueqty.defined && patron_maxissueqty != '' ) || ( patron_maxonsiteissueqty.defined && patron_maxonsiteissueqty != '' ) || ( max_holds.defined && max_holds != '' ) %]
691
                    [% IF  ( patron_maxissueqty.defined && patron_maxissueqty != '' ) || ( patron_maxonsiteissueqty.defined && patron_maxonsiteissueqty != '' ) || ( max_holds.defined && max_holds != '' ) %]
690
                    <tr>
692
                    <tr>
691
                        <td>
693
                        <td>
Lines 718-724 Link Here
718
                        </td>
720
                        </td>
719
                        [% UNLESS humanbranch %]
721
                        [% UNLESS humanbranch %]
720
                            <td>
722
                            <td>
721
                                [% IF branch_cat_rule_loo.has_priority %]
723
                                [% IF has_priority.defined && has_priority %]
722
                                    <input type="checkbox" checked="checked" disabled/>
724
                                    <input type="checkbox" checked="checked" disabled/>
723
                                [% ELSE %]
725
                                [% ELSE %]
724
                                    <input type="checkbox" disabled/>
726
                                    <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 (-11 / +16 lines)
Lines 35-41 $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
subtest 'get_effective_issuing_rule' => sub {
38
subtest 'get_effective_rule' => sub {
39
    plan tests => 4;
39
    plan tests => 4;
40
40
41
    my $categorycode = $builder->build({ source => 'Category' })->{'categorycode'};
41
    my $categorycode = $builder->build({ source => 'Category' })->{'categorycode'};
Lines 43-72 subtest 'get_effective_issuing_rule' => sub { Link Here
43
    my $branchcode   = $builder->build({ source => 'Branch' })->{'branchcode'};
43
    my $branchcode   = $builder->build({ source => 'Branch' })->{'branchcode'};
44
44
45
    subtest 'Priority rule' => sub {
45
    subtest 'Priority rule' => sub {
46
        plan tests => 3;
46
        plan tests => 4;
47
47
48
        Koha::IssuingRules->delete;
48
        Koha::CirculationRules->delete;
49
        is(Koha::CirculationRules->search->count, 0, 'There are no issuing rules.');
49
50
50
        ok(Koha::IssuingRule->new({
51
        ok(Koha::CirculationRule->new({
51
            branchcode => $branchcode,
52
            branchcode => $branchcode,
52
            categorycode => $categorycode,
53
            categorycode => $categorycode,
53
            itemtype => $itemtype,
54
            itemtype => $itemtype,
55
            rule_name => 'fine',
56
            rule_value => 0,
54
        })->store, "Given I added an issuing rule branchcode => $branchcode,'
57
        })->store, "Given I added an issuing rule branchcode => $branchcode,'
55
           .' categorycode => $categorycode, itemtype => $itemtype,");
58
           .' categorycode => $categorycode, itemtype => $itemtype,");
56
59
57
        ok(Koha::IssuingRule->new({
60
        ok(Koha::CirculationRule->new({
58
            branchcode => '*',
61
            branchcode => undef,
59
            categorycode => $categorycode,
62
            categorycode => $categorycode,
60
            itemtype => $itemtype,
63
            itemtype => $itemtype,
61
            has_priority => 1,
64
            has_priority => 1,
65
            rule_name => 'fine',
66
            rule_value => 1,
62
        })->store, "Add a priority rule.");
67
        })->store, "Add a priority rule.");
63
68
64
        my $rule = Koha::IssuingRules->get_effective_issuing_rule({
69
        my $rule = Koha::CirculationRules->get_effective_rule({
65
            branchcode   => $branchcode,
70
            branchcode   => $branchcode,
66
            categorycode => $categorycode,
71
            categorycode => $categorycode,
67
            itemtype     => $itemtype,
72
            itemtype     => $itemtype,
73
            has_priority => 1,
74
            rule_name    => 'fine',
68
        });
75
        });
69
        is($rule->has_priority, 1, 'Priority rule should be returned');
76
        is($rule->priority, 1, 'Priority rule should be returned');
70
    };
77
    };
71
78
72
    subtest 'Call with undefined values' => sub {
79
    subtest 'Call with undefined values' => sub {
Lines 76-82 subtest 'get_effective_issuing_rule' => sub { Link Here
76
        Koha::CirculationRules->delete;
83
        Koha::CirculationRules->delete;
77
84
78
        is(Koha::CirculationRules->search->count, 0, 'There are no issuing rules.');
85
        is(Koha::CirculationRules->search->count, 0, 'There are no issuing rules.');
79
        # undef, undef, undef => 1
86
        # undef, undef, undef => 1w
80
        $rule = Koha::CirculationRules->get_effective_rule({
87
        $rule = Koha::CirculationRules->get_effective_rule({
81
            branchcode   => undef,
88
            branchcode   => undef,
82
            categorycode => undef,
89
            categorycode => undef,
Lines 711-714 sub _is_row_match { Link Here
711
}
718
}
712
719
713
$schema->storage->txn_rollback;
720
$schema->storage->txn_rollback;
714
715
- 

Return to bug 8137