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

(-)a/C4/Reserves.pm (-1 / +1 lines)
Lines 1180-1186 sub IsAvailableForItemLevelRequest { Link Here
1180
        $item->withdrawn        ||
1180
        $item->withdrawn        ||
1181
        ($item->damaged && !C4::Context->preference('AllowHoldsOnDamagedItems'));
1181
        ($item->damaged && !C4::Context->preference('AllowHoldsOnDamagedItems'));
1182
1182
1183
    my $on_shelf_holds = Koha::IssuingRules->get_onshelfholds_policy( { item => $item, patron => $patron } );
1183
    my $on_shelf_holds = Koha::CirculationRules->get_onshelfholds_policy( { item => $item, patron => $patron } );
1184
1184
1185
    if ($pickup_branchcode) {
1185
    if ($pickup_branchcode) {
1186
        my $destination = Koha::Libraries->find($pickup_branchcode);
1186
        my $destination = Koha::Libraries->find($pickup_branchcode);
(-)a/Koha/Charges/Fees.pm (-4 / +4 lines)
Lines 22-28 use Modern::Perl; Link Here
22
use Carp qw( confess );
22
use Carp qw( confess );
23
23
24
use Koha::Calendar;
24
use Koha::Calendar;
25
use Koha::IssuingRules;
26
use Koha::DateUtils qw( dt_from_string );
25
use Koha::DateUtils qw( dt_from_string );
27
use Koha::Exceptions;
26
use Koha::Exceptions;
28
27
Lines 91-104 sub accumulate_rentalcharge { Link Here
91
    my ( $self ) = @_;
90
    my ( $self ) = @_;
92
91
93
    my $itemtype = Koha::ItemTypes->find( $self->item->effective_itemtype );
92
    my $itemtype = Koha::ItemTypes->find( $self->item->effective_itemtype );
94
    my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule(
93
    my $lengthunit_rule = Koha::CirculationRules->get_effective_rule(
95
        {
94
        {
96
            categorycode => $self->patron->categorycode,
95
            categorycode => $self->patron->categorycode,
97
            itemtype     => $itemtype->id,
96
            itemtype     => $itemtype->id,
98
            branchcode   => $self->library->id
97
            branchcode   => $self->library->id,
98
            rule_name    => 'lengthunit',
99
        }
99
        }
100
    );
100
    );
101
    my $units = $issuing_rule->lengthunit;
101
    my $units = $lengthunit_rule->rule_value;
102
    my $rentalcharge_increment = ( $units eq 'days' ) ? $itemtype->rentalcharge_daily : $itemtype->rentalcharge_hourly;
102
    my $rentalcharge_increment = ( $units eq 'days' ) ? $itemtype->rentalcharge_daily : $itemtype->rentalcharge_hourly;
103
103
104
    return 0 unless $rentalcharge_increment && $rentalcharge_increment > 0;
104
    return 0 unless $rentalcharge_increment && $rentalcharge_increment > 0;
(-)a/Koha/CirculationRules.pm (-2 / +6 lines)
Lines 154-159 our $RULE_KINDS = { Link Here
154
    suspension_chargeperiod => {
154
    suspension_chargeperiod => {
155
        scope => [ 'branchcode', 'categorycode', 'itemtype' ],
155
        scope => [ 'branchcode', 'categorycode', 'itemtype' ],
156
    },
156
    },
157
    note => { # This is not really a rule. Maybe we will want to separate this later.
158
        scope => [ 'branchcode', 'categorycode', 'itemtype' ],
159
    },
157
    # Not included (deprecated?):
160
    # Not included (deprecated?):
158
    #   * accountsent
161
    #   * accountsent
159
    #   * reservecharge
162
    #   * reservecharge
Lines 180-187 sub get_effective_rule { Link Here
180
    my $itemtype     = $params->{itemtype};
183
    my $itemtype     = $params->{itemtype};
181
    my $branchcode   = $params->{branchcode};
184
    my $branchcode   = $params->{branchcode};
182
185
186
    my @c = caller;
183
    Koha::Exceptions::MissingParameter->throw(
187
    Koha::Exceptions::MissingParameter->throw(
184
        "Required parameter 'rule_name' missing")
188
        "Required parameter 'rule_name' missing" . "@c")
185
      unless $rule_name;
189
      unless $rule_name;
186
190
187
    for my $v ( $branchcode, $categorycode, $itemtype ) {
191
    for my $v ( $branchcode, $categorycode, $itemtype ) {
Lines 372-378 sub get_opacitemholds_policy { Link Here
372
376
373
    return unless $item or $patron;
377
    return unless $item or $patron;
374
378
375
    my $rule = Koha::CirculationRules->get_effective_issuing_rule(
379
    my $rule = Koha::CirculationRules->get_effective_rule(
376
        {
380
        {
377
            categorycode => $patron->categorycode,
381
            categorycode => $patron->categorycode,
378
            itemtype     => $item->effective_itemtype,
382
            itemtype     => $item->effective_itemtype,
(-)a/Koha/REST/V1/Checkouts.pm (-2 / +1 lines)
Lines 24-30 use C4::Auth qw( haspermission ); Link Here
24
use C4::Context;
24
use C4::Context;
25
use C4::Circulation;
25
use C4::Circulation;
26
use Koha::Checkouts;
26
use Koha::Checkouts;
27
use Koha::IssuingRules;
28
27
29
use Try::Tiny;
28
use Try::Tiny;
30
29
Lines 154-160 sub allows_renewal { Link Here
154
    my $renewable = Mojo::JSON->false;
153
    my $renewable = Mojo::JSON->false;
155
    $renewable = Mojo::JSON->true if $can_renew;
154
    $renewable = Mojo::JSON->true if $can_renew;
156
155
157
    my $rule = Koha::IssuingRules->get_effective_issuing_rule(
156
    my $rule = Koha::CirculationRules->get_effective_rule(
158
        {
157
        {
159
            categorycode => $checkout->patron->categorycode,
158
            categorycode => $checkout->patron->categorycode,
160
            itemtype     => $checkout->item->effective_itemtype,
159
            itemtype     => $checkout->item->effective_itemtype,
(-)a/Koha/Template/Plugin/CirculationRules.pm (-6 / +8 lines)
Lines 26-34 use Koha::CirculationRules; Link Here
26
sub Get {
26
sub Get {
27
    my ( $self, $branchcode, $categorycode, $itemtype, $rule_name ) = @_;
27
    my ( $self, $branchcode, $categorycode, $itemtype, $rule_name ) = @_;
28
28
29
    $branchcode   = undef if $branchcode eq q{}   or $branchcode eq q{*};
29
    for my $var ( $branchcode, $categorycode, $itemtype ) {
30
    $categorycode = undef if $categorycode eq q{} or $branchcode eq q{*};
30
        next unless defined $var;
31
    $itemtype     = undef if $itemtype eq q{}     or $branchcode eq q{*};
31
        $var = undef if $var eq q{} or $var eq q{*};
32
    }
32
33
33
    my $rule = Koha::CirculationRules->search(
34
    my $rule = Koha::CirculationRules->search(
34
        {
35
        {
Lines 45-53 sub Get { Link Here
45
sub Search {
46
sub Search {
46
    my ( $self, $branchcode, $categorycode, $itemtype, $rule_name ) = @_;
47
    my ( $self, $branchcode, $categorycode, $itemtype, $rule_name ) = @_;
47
48
48
    $branchcode   = undef if $branchcode eq q{}   or $branchcode eq q{*};
49
    for my $var ( $branchcode, $categorycode, $itemtype ) {
49
    $categorycode = undef if $categorycode eq q{} or $branchcode eq q{*};
50
        next unless defined $var;
50
    $itemtype     = undef if $itemtype eq q{}     or $branchcode eq q{*};
51
        $var = undef if $var eq q{} or $var eq q{*};
52
    }
51
53
52
    my $rule = Koha::CirculationRules->search(
54
    my $rule = Koha::CirculationRules->search(
53
        {
55
        {
(-)a/admin/smart-rules.pl (-10 / +12 lines)
Lines 85-99 if ($op eq 'delete') { Link Here
85
            branchcode   => $branch eq '*' ? undef : $branch,
85
            branchcode   => $branch eq '*' ? undef : $branch,
86
            itemtype     => $itemtype eq '*' ? undef : $itemtype,
86
            itemtype     => $itemtype eq '*' ? undef : $itemtype,
87
            rules        => {
87
            rules        => {
88
                restrictedtype                   => undef,
88
                maxissueqty                      => undef,
89
                maxonsiteissueqty                => undef,
89
                rentaldiscount                   => undef,
90
                rentaldiscount                   => undef,
90
                fine                             => undef,
91
                fine                             => undef,
91
                finedays                         => undef,
92
                finedays                         => undef,
92
                maxsuspensiondays                => undef,
93
                maxsuspensiondays                => undef,
94
                suspension_chargeperiod          => undef,
93
                firstremind                      => undef,
95
                firstremind                      => undef,
94
                chargeperiod                     => undef,
96
                chargeperiod                     => undef,
95
                chargeperiod_charge_at           => undef,
97
                chargeperiod_charge_at           => undef,
96
                accountsent                      => undef,
97
                issuelength                      => undef,
98
                issuelength                      => undef,
98
                lengthunit                       => undef,
99
                lengthunit                       => undef,
99
                hardduedate                      => undef,
100
                hardduedate                      => undef,
Lines 106-116 if ($op eq 'delete') { Link Here
106
                no_auto_renewal_after_hard_limit => undef,
107
                no_auto_renewal_after_hard_limit => undef,
107
                reservesallowed                  => undef,
108
                reservesallowed                  => undef,
108
                holds_per_record                 => undef,
109
                holds_per_record                 => undef,
109
                overduefinescap                  => undef,
110
                holds_per_day                    => undef,
110
                cap_fine_to_replacement_price    => undef,
111
                onshelfholds                     => undef,
111
                onshelfholds                     => undef,
112
                opacitemholds                    => undef,
112
                opacitemholds                    => undef,
113
                overduefinescap                  => undef,
114
                cap_fine_to_replacement_price    => undef,
113
                article_requests                 => undef,
115
                article_requests                 => undef,
116
                note                             => undef,
114
            }
117
            }
115
        }
118
        }
116
    );
119
    );
Lines 298-303 elsif ($op eq 'add') { Link Here
298
    my $rules = {
301
    my $rules = {
299
        maxissueqty                   => $maxissueqty,
302
        maxissueqty                   => $maxissueqty,
300
        maxonsiteissueqty             => $maxonsiteissueqty,
303
        maxonsiteissueqty             => $maxonsiteissueqty,
304
        rentaldiscount                => $rentaldiscount,
301
        fine                          => $fine,
305
        fine                          => $fine,
302
        finedays                      => $finedays,
306
        finedays                      => $finedays,
303
        maxsuspensiondays             => $maxsuspensiondays,
307
        maxsuspensiondays             => $maxsuspensiondays,
Lines 305-310 elsif ($op eq 'add') { Link Here
305
        firstremind                   => $firstremind,
309
        firstremind                   => $firstremind,
306
        chargeperiod                  => $chargeperiod,
310
        chargeperiod                  => $chargeperiod,
307
        chargeperiod_charge_at        => $chargeperiod_charge_at,
311
        chargeperiod_charge_at        => $chargeperiod_charge_at,
312
        issuelength                   => $issuelength,
313
        lengthunit                    => $lengthunit,
314
        hardduedate                   => $hardduedate,
315
        hardduedatecompare            => $hardduedatecompare,
308
        renewalsallowed               => $renewalsallowed,
316
        renewalsallowed               => $renewalsallowed,
309
        renewalperiod                 => $renewalperiod,
317
        renewalperiod                 => $renewalperiod,
310
        norenewalbefore               => $norenewalbefore,
318
        norenewalbefore               => $norenewalbefore,
Lines 314-324 elsif ($op eq 'add') { Link Here
314
        reservesallowed               => $reservesallowed,
322
        reservesallowed               => $reservesallowed,
315
        holds_per_record              => $holds_per_record,
323
        holds_per_record              => $holds_per_record,
316
        holds_per_day                 => $holds_per_day,
324
        holds_per_day                 => $holds_per_day,
317
        issuelength                   => $issuelength,
318
        lengthunit                    => $lengthunit,
319
        hardduedate                   => $hardduedate,
320
        hardduedatecompare            => $hardduedatecompare,
321
        rentaldiscount                => $rentaldiscount,
322
        onshelfholds                  => $onshelfholds,
325
        onshelfholds                  => $onshelfholds,
323
        opacitemholds                 => $opacitemholds,
326
        opacitemholds                 => $opacitemholds,
324
        overduefinescap               => $overduefinescap,
327
        overduefinescap               => $overduefinescap,
Lines 403-409 elsif ($op eq "set-branch-defaults") { Link Here
403
        {
406
        {
404
            branchcode   => $branch,
407
            branchcode   => $branch,
405
            categorycode => undef,
408
            categorycode => undef,
406
            itemtype     => undef,
407
            rule_name    => 'max_holds',
409
            rule_name    => 'max_holds',
408
            rule_value   => $max_holds,
410
            rule_value   => $max_holds,
409
        }
411
        }
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt (-6 / +3 lines)
Lines 154-163 Link Here
154
                        [% SET article_requests = CirculationRules.Get( branchcode, c, i, 'article_requests' ) %]
154
                        [% SET article_requests = CirculationRules.Get( branchcode, c, i, 'article_requests' ) %]
155
                        [% SET rentaldiscount = CirculationRules.Get( branchcode, c, i, 'rentaldiscount' ) %]
155
                        [% SET rentaldiscount = CirculationRules.Get( branchcode, c, i, 'rentaldiscount' ) %]
156
156
157
                        [% SET show_rule = maxissueqty || maxonsiteissueqty || issuelength || lengthunit || hardduedate || hardduedatebefore || hardduedateexact || fine || chargeperiod
157
                        [% SET show_rule = maxissueqty || maxonsiteissueqty || issuelength || lengthunit || hardduedate || hardduedatebefore || hardduedateexact || fine || chargeperiod || chargeperiod_charge_at || firstremind || overduefinescap || cap_fine_to_replacement_price || finedays || maxsuspensiondays || suspension_chargeperiod || renewalsallowed || renewalsallowed || norenewalbefore || auto_renew || no_auto_renewal_after || no_auto_renewal_after_hard_limit || reservesallowed || holds_per_day || holds_per_record || onshelfholds || opacitemholds || article_requests || article_requests %]
158
                                        || chargeperiod_charge_at || firstremind || overduefinescap || cap_fine_to_replacement_price || finedays || maxsuspensiondays || suspension_chargeperiod || renewalsallowed
159
                                        || renewalsallowed || norenewalbefore || auto_renew || no_auto_renewal_after || no_auto_renewal_after_hard_limit || reservesallowed
160
                                        || holds_per_day || holds_per_record || onshelfholds || opacitemholds || article_requests || article_requests %]
161
                        [% IF show_rule %]
158
                        [% IF show_rule %]
162
                            [% SET row_count = row_count + 1 %]
159
                            [% SET row_count = row_count + 1 %]
163
                            <tr row_countd="row_[% row_count %]">
160
                            <tr row_countd="row_[% row_count %]">
Lines 180-187 Link Here
180
                                      <a class="btn btn-default btn-xs delete" href="/cgi-bin/koha/admin/smart-rules.pl?op=delete&amp;itemtype=[% rule.itemtype || '*' %]&amp;categorycode=[% rule.categorycode || '*' %]&amp;branch=[% current_branch %]"><i class="fa fa-trash"></i> Delete</a>
177
                                      <a class="btn btn-default btn-xs delete" href="/cgi-bin/koha/admin/smart-rules.pl?op=delete&amp;itemtype=[% rule.itemtype || '*' %]&amp;categorycode=[% rule.categorycode || '*' %]&amp;branch=[% current_branch %]"><i class="fa fa-trash"></i> Delete</a>
181
                                    </td>
178
                                    </td>
182
                                    <td>
179
                                    <td>
183
                                        [% IF rule.note %]
180
                                        [% IF note.defined %]
184
                                            <a name="viewnote" data-toggle="popover" title="Note" data-content="[% rule.note | html %]" data-placement="top" data-trigger="hover">View note</a>
181
                                            <a name="viewnote" data-toggle="popover" title="Note" data-content="[% note | html %]" data-placement="top" data-trigger="hover">View note</a>
185
                                        [% ELSE %]<span>&nbsp;</span>[% END %]
182
                                        [% ELSE %]<span>&nbsp;</span>[% END %]
186
                                    </td>
183
                                    </td>
187
                                    <td>
184
                                    <td>
(-)a/t/db_dependent/Circulation/CalcFine.t (-7 / +6 lines)
Lines 165-177 subtest 'Test cap_fine_to_replacement_pricew with overduefinescap' => sub { Link Here
165
    plan tests => 2;
165
    plan tests => 2;
166
166
167
    t::lib::Mocks::mock_preference('useDefaultReplacementCost', '1');
167
    t::lib::Mocks::mock_preference('useDefaultReplacementCost', '1');
168
    my $issuingrule = $builder->build_object(
168
    Koha::CirculationRules->set_rules(
169
        {
169
        {
170
            class => 'Koha::IssuingRules',
170
            branchcode   => undef,
171
            value  => {
171
            categorycode => undef,
172
                branchcode                    => '*',
172
            itemtype     => undef,
173
                categorycode                  => '*',
173
            rules        => {
174
                itemtype                      => '*',
175
                fine                          => '1.00',
174
                fine                          => '1.00',
176
                lengthunit                    => 'days',
175
                lengthunit                    => 'days',
177
                finedays                      => 0,
176
                finedays                      => 0,
Lines 198-204 subtest 'Test cap_fine_to_replacement_pricew with overduefinescap' => sub { Link Here
198
    my ($amount) = CalcFine( $item, $patron->{categorycode}, $branch->{branchcode}, $start_dt, $end_dt );
197
    my ($amount) = CalcFine( $item, $patron->{categorycode}, $branch->{branchcode}, $start_dt, $end_dt );
199
    is( int($amount), 3, 'Got the lesser of overduefinescap and replacement price where overduefinescap < replacement price' );
198
    is( int($amount), 3, 'Got the lesser of overduefinescap and replacement price where overduefinescap < replacement price' );
200
199
201
    $issuingrule->overduefinescap(6)->store();
200
    Koha::CirculationRules->set_rule({ rule_name => 'overduefinescap', rule_value => 6, branchcode => undef, categorycode => undef, itemtype => undef });
202
    ($amount) = CalcFine( $item, $patron->{categorycode}, $branch->{branchcode}, $start_dt, $end_dt );
201
    ($amount) = CalcFine( $item, $patron->{categorycode}, $branch->{branchcode}, $start_dt, $end_dt );
203
    is( int($amount), 5, 'Get the lesser of overduefinescap and replacement price where overduefinescap > replacement price' );
202
    is( int($amount), 5, 'Get the lesser of overduefinescap and replacement price where overduefinescap > replacement price' );
204
203
(-)a/t/db_dependent/Circulation/TooMany.t (-8 / +9 lines)
Lines 499-516 subtest 'General vs specific rules limit quantity correctly' => sub { Link Here
499
    });
499
    });
500
500
501
    # Set up an issuing rule
501
    # Set up an issuing rule
502
    my $rule = $builder->build({
502
    Koha::CirculationRules->set_rules(
503
        source => 'Issuingrule',
503
        {
504
        value => {
505
            categorycode => '*',
504
            categorycode => '*',
506
            itemtype     => $itemtype->{itemtype},
505
            itemtype     => $itemtype->{itemtype},
507
            branchcode   => '*',
506
            branchcode   => '*',
508
            issuelength  => 1,
507
            rules        => {
509
            firstremind  => 1,        # 1 day of grace
508
                issuelength => 1,
510
            finedays     => 2,        # 2 days of fine per day of overdue
509
                firstremind => 1,        # 1 day of grace
511
            lengthunit   => 'days',
510
                finedays    => 2,        # 2 days of fine per day of overdue
511
                lengthunit  => 'days',
512
            }
512
        }
513
        }
513
    });
514
    );
514
515
515
    # Set an All->All for an itemtype
516
    # Set an All->All for an itemtype
516
    Koha::CirculationRules->set_rules(
517
    Koha::CirculationRules->set_rules(
(-)a/t/db_dependent/Circulation/issue.t (-9 / +8 lines)
Lines 87-102 my $categorycode = $builder->build({ Link Here
87
    })->{categorycode};
87
    })->{categorycode};
88
88
89
# A default issuingrule should always be present
89
# A default issuingrule should always be present
90
my $issuingrule = $builder->build(
90
Koha::CirculationRules->set_rules(
91
    {
91
    {
92
        source => 'Issuingrule',
92
        itemtype     => '*',
93
        value  => {
93
        categorycode => '*',
94
            itemtype      => '*',
94
        branchcode   => '*',
95
            categorycode  => '*',
95
        rules        => {
96
            branchcode    => '*',
96
            lengthunit      => 'days',
97
            lengthunit    => 'days',
97
            issuelength     => 0,
98
            issuelength   => 0,
98
            renewalperiod   => 0,
99
            renewalperiod => 0,
100
            renewalsallowed => 0
99
            renewalsallowed => 0
101
        }
100
        }
102
    }
101
    }
(-)a/t/db_dependent/Holds.t (-10 / +45 lines)
Lines 458-464 subtest 'Test max_holds per library/patron category' => sub { Link Here
458
    $dbh->do('DELETE FROM reserves');
458
    $dbh->do('DELETE FROM reserves');
459
    $dbh->do('DELETE FROM circulation_rules');
459
    $dbh->do('DELETE FROM circulation_rules');
460
460
461
    $biblio = $builder->build_sample_biblio({ itemtype => 'TEST' });
461
    $biblio = $builder->build_sample_biblio;
462
    ( $item_bibnum, $item_bibitemnum, $itemnumber ) =
462
    ( $item_bibnum, $item_bibitemnum, $itemnumber ) =
463
      AddItem( { homebranch => $branch_1, holdingbranch => $branch_1 },
463
      AddItem( { homebranch => $branch_1, holdingbranch => $branch_1 },
464
        $biblio->biblionumber );
464
        $biblio->biblionumber );
Lines 466-472 subtest 'Test max_holds per library/patron category' => sub { Link Here
466
        {
466
        {
467
            categorycode => undef,
467
            categorycode => undef,
468
            branchcode   => undef,
468
            branchcode   => undef,
469
            itemtype     => $testitemtype,
469
            itemtype     => $biblio->itemtype,
470
            rules        => {
470
            rules        => {
471
                reservesallowed  => 99,
471
                reservesallowed  => 99,
472
                holds_per_record => 99,
472
                holds_per_record => 99,
Lines 533-543 subtest 'Pickup location availability tests' => sub { Link Here
533
    my ( $item_bibnum, $item_bibitemnum, $itemnumber )
533
    my ( $item_bibnum, $item_bibitemnum, $itemnumber )
534
    = AddItem( { homebranch => $branch_1, holdingbranch => $branch_1 }, $biblio->biblionumber );
534
    = AddItem( { homebranch => $branch_1, holdingbranch => $branch_1 }, $biblio->biblionumber );
535
    #Add a default rule to allow some holds
535
    #Add a default rule to allow some holds
536
    $dbh->do(
536
537
        q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed, holds_per_record)
537
    Koha::CirculationRules->set_rules(
538
          VALUES (?, ?, ?, ?, ?)},
538
        {
539
        {},
539
            branchcode   => undef,
540
        '*', '*', '*', 25, 99
540
            categorycode => undef,
541
            itemtype     => undef,
542
            rules        => {
543
                reservesallowed  => 25,
544
                holds_per_record => 99,
545
            }
546
        }
541
    );
547
    );
542
    my $item = Koha::Items->find($itemnumber);
548
    my $item = Koha::Items->find($itemnumber);
543
    my $branch_to = $builder->build({ source => 'Branch' })->{ branchcode };
549
    my $branch_to = $builder->build({ source => 'Branch' })->{ branchcode };
Lines 637-643 subtest 'CanItemBeReserved / holds_per_day tests' => sub { Link Here
637
    );
643
    );
638
644
639
    # Raise reservesallowed to avoid tooManyReserves from it
645
    # Raise reservesallowed to avoid tooManyReserves from it
640
    $issuingrule->set( { reservesallowed => 3 } )->store;
646
    Koha::CirculationRules->set_rule(
647
        {
648
649
            categorycode => '*',
650
            branchcode   => '*',
651
            itemtype     => $itemtype->itemtype,
652
            rule_name  => 'reservesallowed',
653
            rule_value => 3,
654
        }
655
    );
641
656
642
    is_deeply(
657
    is_deeply(
643
        CanItemBeReserved( $patron->borrowernumber, $itemnumber_2 ),
658
        CanItemBeReserved( $patron->borrowernumber, $itemnumber_2 ),
Lines 665-671 subtest 'CanItemBeReserved / holds_per_day tests' => sub { Link Here
665
    );
680
    );
666
681
667
    # Set holds_per_day to 0
682
    # Set holds_per_day to 0
668
    $issuingrule->set( { holds_per_day => 0 } )->store;
683
    Koha::CirculationRules->set_rule(
684
        {
685
686
            categorycode => '*',
687
            branchcode   => '*',
688
            itemtype     => $itemtype->itemtype,
689
            rule_name  => 'holds_per_day',
690
            rule_value => 0,
691
        }
692
    );
693
669
694
670
    # Delete existing holds
695
    # Delete existing holds
671
    Koha::Holds->search->delete;
696
    Koha::Holds->search->delete;
Lines 675-681 subtest 'CanItemBeReserved / holds_per_day tests' => sub { Link Here
675
        'Patron cannot reserve if holds_per_day is 0 (i.e. 0 is 0)'
700
        'Patron cannot reserve if holds_per_day is 0 (i.e. 0 is 0)'
676
    );
701
    );
677
702
678
    $issuingrule->set( { holds_per_day => undef } )->store;
703
    Koha::CirculationRules->set_rule(
704
        {
705
706
            categorycode => '*',
707
            branchcode   => '*',
708
            itemtype     => $itemtype->itemtype,
709
            rule_name  => 'holds_per_day',
710
            rule_value => undef,
711
        }
712
    );
713
679
    Koha::Holds->search->delete;
714
    Koha::Holds->search->delete;
680
    is_deeply(
715
    is_deeply(
681
        CanItemBeReserved( $patron->borrowernumber, $itemnumber_2 ),
716
        CanItemBeReserved( $patron->borrowernumber, $itemnumber_2 ),
(-)a/t/db_dependent/ILSDI_Services.t (-24 / +27 lines)
Lines 379-398 subtest 'Holds test' => sub { Link Here
379
        source => 'Item',
379
        source => 'Item',
380
        value => {
380
        value => {
381
            biblionumber => $biblio2->{biblionumber},
381
            biblionumber => $biblio2->{biblionumber},
382
            damaged => 0
382
            damaged => 0,
383
            itype => $builder->build_object({ class => 'Koha::ItemTypes' })->itemtype,
383
        }
384
        }
384
    });
385
    });
385
386
386
    t::lib::Mocks::mock_preference( 'ReservesControlBranch', 'PatronLibrary' );
387
    t::lib::Mocks::mock_preference( 'ReservesControlBranch', 'PatronLibrary' );
387
    my $issuingrule = $builder->build({
388
    Koha::CirculationRules->set_rule(
388
        source => 'Issuingrule',
389
        {
389
        value => {
390
            categorycode => $patron->{categorycode},
390
            categorycode => $patron->{categorycode},
391
            itemtype => $item2->{itype},
391
            itemtype     => $item2->{itype},
392
            branchcode => $patron->{branchcode},
392
            branchcode   => $patron->{branchcode},
393
            reservesallowed => 0,
393
            rule_name    => 'reservesallowed',
394
            rule_value   => 0,
394
        }
395
        }
395
    });
396
    );
396
397
397
    $query = new CGI;
398
    $query = new CGI;
398
    $query->param( 'patron_id', $patron->{borrowernumber});
399
    $query->param( 'patron_id', $patron->{borrowernumber});
Lines 419-424 subtest 'Holds test' => sub { Link Here
419
        value => {
420
        value => {
420
            biblionumber => $biblio3->{biblionumber},
421
            biblionumber => $biblio3->{biblionumber},
421
            damaged => 0,
422
            damaged => 0,
423
            itype => $builder->build_object({ class => 'Koha::ItemTypes' })->itemtype,
422
        }
424
        }
423
    });
425
    });
424
426
Lines 427-444 subtest 'Holds test' => sub { Link Here
427
        value => {
429
        value => {
428
            biblionumber => $biblio3->{biblionumber},
430
            biblionumber => $biblio3->{biblionumber},
429
            damaged => 1,
431
            damaged => 1,
432
            itype => $builder->build_object({ class => 'Koha::ItemTypes' })->itemtype,
430
        }
433
        }
431
    });
434
    });
432
435
433
    my $issuingrule2 = $builder->build({
436
    Koha::CirculationRules->set_rule(
434
        source => 'Issuingrule',
437
        {
435
        value => {
436
            categorycode => $patron->{categorycode},
438
            categorycode => $patron->{categorycode},
437
            itemtype => $item3->{itype},
439
            itemtype     => $item3->{itype},
438
            branchcode => $patron->{branchcode},
440
            branchcode   => $patron->{branchcode},
439
            reservesallowed => 10,
441
            rule_name    => 'reservesallowed',
442
            rule_value   => 10,
440
        }
443
        }
441
    });
444
    );
442
445
443
    $query = new CGI;
446
    $query = new CGI;
444
    $query->param( 'patron_id', $patron->{borrowernumber});
447
    $query->param( 'patron_id', $patron->{borrowernumber});
Lines 499-517 subtest 'Holds test for branch transfer limits' => sub { Link Here
499
            biblionumber => $biblio->{biblionumber},
502
            biblionumber => $biblio->{biblionumber},
500
            damaged => 0,
503
            damaged => 0,
501
            itemlost => 0,
504
            itemlost => 0,
505
            itype => $builder->build_object({ class => 'Koha::ItemTypes' })->itemtype,
502
        }
506
        }
503
    });
507
    });
504
508
505
    Koha::IssuingRules->search()->delete();
509
    Koha::CirculationRules->set_rule(
506
    my $issuingrule = $builder->build({
510
        {
507
        source => 'Issuingrule',
511
            categorycode => undef,
508
        value => {
512
            itemtype     => undef,
509
            categorycode => '*',
513
            branchcode   => undef,
510
            itemtype => '*',
514
            rule_name    => 'reservesallowed',
511
            branchcode => '*',
515
            rule_value   => 99,
512
            reservesallowed => 99,
513
        }
516
        }
514
    });
517
    );
515
518
516
    my $limit = Koha::Item::Transfer::Limit->new({
519
    my $limit = Koha::Item::Transfer::Limit->new({
517
        toBranch => $pickup_branch->{branchcode},
520
        toBranch => $pickup_branch->{branchcode},
(-)a/t/db_dependent/Koha/IssuingRules.t (-48 / +21 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 3;
22
use Test::More tests => 2;
23
use Test::Deep qw( cmp_methods );
23
use Test::Deep qw( cmp_methods );
24
use Test::Exception;
24
use Test::Exception;
25
25
Lines 54-59 subtest 'get_effective_issuing_rule' => sub { Link Here
54
            categorycode => undef,
54
            categorycode => undef,
55
            itemtype     => undef,
55
            itemtype     => undef,
56
            rule_name    => 'fine',
56
            rule_name    => 'fine',
57
            rule_value   => 1,
57
        });
58
        });
58
        is($rule, undef, 'When I attempt to get effective issuing rule by'
59
        is($rule, undef, 'When I attempt to get effective issuing rule by'
59
           .' providing undefined values, then undef is returned.');
60
           .' providing undefined values, then undef is returned.');
Lines 62-67 subtest 'get_effective_issuing_rule' => sub { Link Here
62
            categorycode => undef,
63
            categorycode => undef,
63
            itemtype => undef,
64
            itemtype => undef,
64
            rule_name => 'fine',
65
            rule_name => 'fine',
66
            rule_value => 2,
65
        })->store, 'Given I added an issuing rule branchcode => undef,'
67
        })->store, 'Given I added an issuing rule branchcode => undef,'
66
           .' categorycode => undef, itemtype => undef,');
68
           .' categorycode => undef, itemtype => undef,');
67
        $rule = Koha::CirculationRules->get_effective_rule({
69
        $rule = Koha::CirculationRules->get_effective_rule({
Lines 69-74 subtest 'get_effective_issuing_rule' => sub { Link Here
69
            categorycode => undef,
71
            categorycode => undef,
70
            itemtype     => undef,
72
            itemtype     => undef,
71
            rule_name    => 'fine',
73
            rule_name    => 'fine',
74
            rule_value => 3,
72
        });
75
        });
73
        _is_row_match(
76
        _is_row_match(
74
            $rule,
77
            $rule,
Lines 94-99 subtest 'get_effective_issuing_rule' => sub { Link Here
94
            categorycode => $categorycode,
97
            categorycode => $categorycode,
95
            itemtype     => $itemtype,
98
            itemtype     => $itemtype,
96
            rule_name    => 'fine',
99
            rule_name    => 'fine',
100
            rule_value   => 4,
97
        });
101
        });
98
        is($rule, undef, 'When I attempt to get effective issuing rule, then undef'
102
        is($rule, undef, 'When I attempt to get effective issuing rule, then undef'
99
                        .' is returned.');
103
                        .' is returned.');
Lines 103-114 subtest 'get_effective_issuing_rule' => sub { Link Here
103
            categorycode => undef,
107
            categorycode => undef,
104
            itemtype => undef,
108
            itemtype => undef,
105
            rule_name => 'fine',
109
            rule_name => 'fine',
110
            rule_value   => 5,
106
        })->store, 'Given I added an issuing rule branchcode => undef, categorycode => undef, itemtype => undef,');
111
        })->store, 'Given I added an issuing rule branchcode => undef, categorycode => undef, itemtype => undef,');
107
        $rule = Koha::CirculationRules->get_effective_rule({
112
        $rule = Koha::CirculationRules->get_effective_rule({
108
            branchcode   => $branchcode,
113
            branchcode   => $branchcode,
109
            categorycode => $categorycode,
114
            categorycode => $categorycode,
110
            itemtype     => $itemtype,
115
            itemtype     => $itemtype,
111
            rule_name    => 'fine',
116
            rule_name    => 'fine',
117
            rule_value   => 6,
112
        });
118
        });
113
        _is_row_match(
119
        _is_row_match(
114
            $rule,
120
            $rule,
Lines 126-137 subtest 'get_effective_issuing_rule' => sub { Link Here
126
            categorycode => undef,
132
            categorycode => undef,
127
            itemtype => $itemtype,
133
            itemtype => $itemtype,
128
            rule_name => 'fine',
134
            rule_name => 'fine',
135
            rule_value   => 7,
129
        })->store, "Given I added an issuing rule branchcode => undef, categorycode => undef, itemtype => $itemtype,");
136
        })->store, "Given I added an issuing rule branchcode => undef, categorycode => undef, itemtype => $itemtype,");
130
        $rule = Koha::CirculationRules->get_effective_rule({
137
        $rule = Koha::CirculationRules->get_effective_rule({
131
            branchcode   => $branchcode,
138
            branchcode   => $branchcode,
132
            categorycode => $categorycode,
139
            categorycode => $categorycode,
133
            itemtype     => $itemtype,
140
            itemtype     => $itemtype,
134
            rule_name    => 'fine',
141
            rule_name    => 'fine',
142
            rule_value   => 8,
135
        });
143
        });
136
        _is_row_match(
144
        _is_row_match(
137
            $rule,
145
            $rule,
Lines 149-160 subtest 'get_effective_issuing_rule' => sub { Link Here
149
            categorycode => $categorycode,
157
            categorycode => $categorycode,
150
            itemtype => undef,
158
            itemtype => undef,
151
            rule_name => 'fine',
159
            rule_name => 'fine',
160
            rule_value   => 9,
152
        })->store, "Given I added an issuing rule branchcode => undef, categorycode => $categorycode, itemtype => undef,");
161
        })->store, "Given I added an issuing rule branchcode => undef, categorycode => $categorycode, itemtype => undef,");
153
        $rule = Koha::CirculationRules->get_effective_rule({
162
        $rule = Koha::CirculationRules->get_effective_rule({
154
            branchcode   => $branchcode,
163
            branchcode   => $branchcode,
155
            categorycode => $categorycode,
164
            categorycode => $categorycode,
156
            itemtype     => $itemtype,
165
            itemtype     => $itemtype,
157
            rule_name    => 'fine',
166
            rule_name    => 'fine',
167
            rule_value   => 10,
158
        });
168
        });
159
        _is_row_match(
169
        _is_row_match(
160
            $rule,
170
            $rule,
Lines 172-183 subtest 'get_effective_issuing_rule' => sub { Link Here
172
            categorycode => $categorycode,
182
            categorycode => $categorycode,
173
            itemtype => $itemtype,
183
            itemtype => $itemtype,
174
            rule_name => 'fine',
184
            rule_name => 'fine',
185
            rule_value   => 11,
175
        })->store, "Given I added an issuing rule branchcode => undef, categorycode => $categorycode, itemtype => $itemtype,");
186
        })->store, "Given I added an issuing rule branchcode => undef, categorycode => $categorycode, itemtype => $itemtype,");
176
        $rule = Koha::CirculationRules->get_effective_rule({
187
        $rule = Koha::CirculationRules->get_effective_rule({
177
            branchcode   => $branchcode,
188
            branchcode   => $branchcode,
178
            categorycode => $categorycode,
189
            categorycode => $categorycode,
179
            itemtype     => $itemtype,
190
            itemtype     => $itemtype,
180
            rule_name    => 'fine',
191
            rule_name    => 'fine',
192
            rule_value   => 12,
181
        });
193
        });
182
        _is_row_match(
194
        _is_row_match(
183
            $rule,
195
            $rule,
Lines 195-206 subtest 'get_effective_issuing_rule' => sub { Link Here
195
            categorycode => undef,
207
            categorycode => undef,
196
            itemtype => undef,
208
            itemtype => undef,
197
            rule_name => 'fine',
209
            rule_name => 'fine',
210
            rule_value   => 13,
198
        })->store, "Given I added an issuing rule branchcode => $branchcode, categorycode => undef, itemtype => undef,");
211
        })->store, "Given I added an issuing rule branchcode => $branchcode, categorycode => undef, itemtype => undef,");
199
        $rule = Koha::CirculationRules->get_effective_rule({
212
        $rule = Koha::CirculationRules->get_effective_rule({
200
            branchcode   => $branchcode,
213
            branchcode   => $branchcode,
201
            categorycode => $categorycode,
214
            categorycode => $categorycode,
202
            itemtype     => $itemtype,
215
            itemtype     => $itemtype,
203
            rule_name    => 'fine',
216
            rule_name    => 'fine',
217
            rule_value   => 14,
204
        });
218
        });
205
        _is_row_match(
219
        _is_row_match(
206
            $rule,
220
            $rule,
Lines 218-229 subtest 'get_effective_issuing_rule' => sub { Link Here
218
            categorycode => undef,
232
            categorycode => undef,
219
            itemtype => $itemtype,
233
            itemtype => $itemtype,
220
            rule_name => 'fine',
234
            rule_name => 'fine',
235
            rule_value   => 15,
221
        })->store, "Given I added an issuing rule branchcode => $branchcode, categorycode => undef, itemtype => $itemtype,");
236
        })->store, "Given I added an issuing rule branchcode => $branchcode, categorycode => undef, itemtype => $itemtype,");
222
        $rule = Koha::CirculationRules->get_effective_rule({
237
        $rule = Koha::CirculationRules->get_effective_rule({
223
            branchcode   => $branchcode,
238
            branchcode   => $branchcode,
224
            categorycode => $categorycode,
239
            categorycode => $categorycode,
225
            itemtype     => $itemtype,
240
            itemtype     => $itemtype,
226
            rule_name    => 'fine',
241
            rule_name    => 'fine',
242
            rule_value   => 16,
227
        });
243
        });
228
        _is_row_match(
244
        _is_row_match(
229
            $rule,
245
            $rule,
Lines 241-252 subtest 'get_effective_issuing_rule' => sub { Link Here
241
            categorycode => $categorycode,
257
            categorycode => $categorycode,
242
            itemtype => undef,
258
            itemtype => undef,
243
            rule_name => 'fine',
259
            rule_name => 'fine',
260
            rule_value   => 17,
244
        })->store, "Given I added an issuing rule branchcode => $branchcode, categorycode => $categorycode, itemtype => undef,");
261
        })->store, "Given I added an issuing rule branchcode => $branchcode, categorycode => $categorycode, itemtype => undef,");
245
        $rule = Koha::CirculationRules->get_effective_rule({
262
        $rule = Koha::CirculationRules->get_effective_rule({
246
            branchcode   => $branchcode,
263
            branchcode   => $branchcode,
247
            categorycode => $categorycode,
264
            categorycode => $categorycode,
248
            itemtype     => $itemtype,
265
            itemtype     => $itemtype,
249
            rule_name    => 'fine',
266
            rule_name    => 'fine',
267
            rule_value   => 18,
250
        });
268
        });
251
        _is_row_match(
269
        _is_row_match(
252
            $rule,
270
            $rule,
Lines 264-275 subtest 'get_effective_issuing_rule' => sub { Link Here
264
            categorycode => $categorycode,
282
            categorycode => $categorycode,
265
            itemtype => $itemtype,
283
            itemtype => $itemtype,
266
            rule_name => 'fine',
284
            rule_name => 'fine',
285
            rule_value   => 19,
267
        })->store, "Given I added an issuing rule branchcode => $branchcode, categorycode => $categorycode, itemtype => $itemtype,");
286
        })->store, "Given I added an issuing rule branchcode => $branchcode, categorycode => $categorycode, itemtype => $itemtype,");
268
        $rule = Koha::CirculationRules->get_effective_rule({
287
        $rule = Koha::CirculationRules->get_effective_rule({
269
            branchcode   => $branchcode,
288
            branchcode   => $branchcode,
270
            categorycode => $categorycode,
289
            categorycode => $categorycode,
271
            itemtype     => $itemtype,
290
            itemtype     => $itemtype,
272
            rule_name    => 'fine',
291
            rule_name    => 'fine',
292
            rule_value   => 20,
273
        });
293
        });
274
        _is_row_match(
294
        _is_row_match(
275
            $rule,
295
            $rule,
Lines 460-512 subtest 'set_rule' => sub { Link Here
460
    };
480
    };
461
};
481
};
462
482
463
subtest 'delete' => sub {
464
    plan tests => 1;
465
466
    my $itemtype = $builder->build_object({ class => 'Koha::ItemTypes' });
467
    my $library  = $builder->build_object({ class => 'Koha::Libraries' });
468
    my $category = $builder->build_object({ class => 'Koha::Patron::Categories' });
469
470
    # We make an issuing rule
471
    my $issue_rule = $builder->build_object({ class => 'Koha::IssuingRules', value => {
472
            categorycode => $category->categorycode,
473
            itemtype     => $itemtype->itemtype,
474
            branchcode   => $library->branchcode
475
        }
476
    });
477
478
    my $count = Koha::CirculationRules->search()->count;
479
    # Note how many circulation rules we start with
480
481
    # We make some circulation rules for the same thing
482
    $builder->build_object({ class => 'Koha::CirculationRules', value => {
483
            categorycode => $category->categorycode,
484
            itemtype     => $itemtype->itemtype,
485
            branchcode   => $library->branchcode,
486
            rule_name    => 'maxissueqty',
487
        }
488
    });
489
    $builder->build_object({ class => 'Koha::CirculationRules', value => {
490
            categorycode => $category->categorycode,
491
            itemtype     => $itemtype->itemtype,
492
            branchcode   => $library->branchcode,
493
            rule_name    => 'maxonsiteissueqty',
494
        }
495
    });
496
    $builder->build_object({ class => 'Koha::CirculationRules', value => {
497
            categorycode => $category->categorycode,
498
            itemtype     => $itemtype->itemtype,
499
            branchcode   => $library->branchcode,
500
            rule_name    => 'another_rule', # That must not be deleted
501
        }
502
    });
503
504
    # Now we delete the issuing rule
505
    $issue_rule->delete;
506
    is( Koha::CirculationRules->search()->count ,$count +  1, "We remove related circ rules maxissueqty and maxonsiteissueqty with our issuing rule");
507
508
};
509
510
sub _is_row_match {
483
sub _is_row_match {
511
    my ( $rule, $expected, $message ) = @_;
484
    my ( $rule, $expected, $message ) = @_;
512
485
(-)a/t/db_dependent/SIP/Transaction.t (-1 lines)
Lines 14-20 use C4::SIP::ILS::Transaction::RenewAll; Link Here
14
use C4::SIP::ILS::Transaction::Checkout;
14
use C4::SIP::ILS::Transaction::Checkout;
15
15
16
use C4::Reserves;
16
use C4::Reserves;
17
use Koha::IssuingRules;
18
17
19
my $schema = Koha::Database->new->schema;
18
my $schema = Koha::Database->new->schema;
20
$schema->storage->txn_begin;
19
$schema->storage->txn_begin;
(-)a/t/db_dependent/selenium/administration_tasks.t (-2 / +1 lines)
Lines 84-90 SKIP: { Link Here
84
        $elt = $driver->find_elements('//table[@id="default-circulation-rules"]/tbody/tr/td[contains(text(),"'.$itype->description.'")]/following-sibling::td/span[text() = "Unlimited"]');
84
        $elt = $driver->find_elements('//table[@id="default-circulation-rules"]/tbody/tr/td[contains(text(),"'.$itype->description.'")]/following-sibling::td/span[text() = "Unlimited"]');
85
        is( @$elt,2,"We have unlimited checkouts");
85
        is( @$elt,2,"We have unlimited checkouts");
86
        #Clean up
86
        #Clean up
87
        Koha::IssuingRules->find({itemtype=>$itype->itemtype})->delete();
87
        Koha::CirculationRules->search( { itemtype => $itype->itemtype } )->delete;
88
        $itype->delete;
88
        $itype->delete;
89
               # TODO Create more smart rules navigation here
89
               # TODO Create more smart rules navigation here
90
    };
90
    };
91
- 

Return to bug 18936