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

(-)a/C4/Circulation.pm (-9 / +24 lines)
Lines 391-403 sub TooMany { Link Here
391
            : $Koha::Checkouts::type->{onsite_checkout}
391
            : $Koha::Checkouts::type->{onsite_checkout}
392
        : $Koha::Checkouts::type->{checkout};
392
        : $Koha::Checkouts::type->{checkout};
393
393
394
    # given branch, patron category, and item type, determine
394
    # given branch, patron category, item type, and checkout type, determine
395
    # applicable issuing rule
395
    # applicable issuing rule
396
    my $maxissueqty_rule = Koha::CirculationRules->get_effective_rule(
396
    my $maxissueqty_rule = Koha::CirculationRules->get_effective_rule(
397
        {
397
        {
398
            categorycode => $cat_borrower,
398
            categorycode => $cat_borrower,
399
            itemtype     => $type,
399
            itemtype     => $type,
400
            branchcode   => $branch,
400
            branchcode   => $branch,
401
            checkout_type => $checkout_type,
401
            rule_name    => 'maxissueqty',
402
            rule_name    => 'maxissueqty',
402
        }
403
        }
403
    );
404
    );
Lines 676-681 sub CanBookBeIssued { Link Here
676
    my $onsite_checkout     = $params->{onsite_checkout}     || 0;
677
    my $onsite_checkout     = $params->{onsite_checkout}     || 0;
677
    my $override_high_holds = $params->{override_high_holds} || 0;
678
    my $override_high_holds = $params->{override_high_holds} || 0;
678
679
680
    my $checkout_type = $onsite_checkout
681
        ? $Koha::Checkouts::type->{onsite_checkout}
682
        : $Koha::Checkouts::type->{checkout};
679
    my $item_object = Koha::Items->find({barcode => $barcode });
683
    my $item_object = Koha::Items->find({barcode => $barcode });
680
684
681
    # MANDATORY CHECKS - unless item exists, nothing else matters
685
    # MANDATORY CHECKS - unless item exists, nothing else matters
Lines 1310-1315 sub AddIssue { Link Here
1310
    my $auto_renew = $params && $params->{auto_renew};
1314
    my $auto_renew = $params && $params->{auto_renew};
1311
    my $dbh          = C4::Context->dbh;
1315
    my $dbh          = C4::Context->dbh;
1312
    my $barcodecheck = CheckValidBarcode($barcode);
1316
    my $barcodecheck = CheckValidBarcode($barcode);
1317
    my $checkout_type = $onsite_checkout
1318
        ? $switch_onsite_checkout
1319
            ? $Koha::Checkouts::type->{checkout}
1320
            : $Koha::Checkouts::type->{onsite_checkout}
1321
        : $Koha::Checkouts::type->{checkout};
1313
1322
1314
    my $issue;
1323
    my $issue;
1315
1324
Lines 1366-1371 sub AddIssue { Link Here
1366
                    patron    => $patron,
1375
                    patron    => $patron,
1367
                    library   => $library,
1376
                    library   => $library,
1368
                    item      => $item_object,
1377
                    item      => $item_object,
1378
                    checkout_type => $checkout_type,
1369
                    to_date   => $datedue,
1379
                    to_date   => $datedue,
1370
                }
1380
                }
1371
            );
1381
            );
Lines 1403-1408 sub AddIssue { Link Here
1403
                        categorycode => $borrower->{categorycode},
1413
                        categorycode => $borrower->{categorycode},
1404
                        itemtype     => $item_object->effective_itemtype,
1414
                        itemtype     => $item_object->effective_itemtype,
1405
                        branchcode   => $branchcode,
1415
                        branchcode   => $branchcode,
1416
                        checkout_type => $checkout_type,
1406
                        rule_name    => 'auto_renew'
1417
                        rule_name    => 'auto_renew'
1407
                    }
1418
                    }
1408
                );
1419
                );
Lines 1423-1431 sub AddIssue { Link Here
1423
                issuedate       => $issuedate->strftime('%Y-%m-%d %H:%M:%S'),
1434
                issuedate       => $issuedate->strftime('%Y-%m-%d %H:%M:%S'),
1424
                date_due        => $datedue->strftime('%Y-%m-%d %H:%M:%S'),
1435
                date_due        => $datedue->strftime('%Y-%m-%d %H:%M:%S'),
1425
                branchcode      => C4::Context->userenv->{'branch'},
1436
                branchcode      => C4::Context->userenv->{'branch'},
1426
                checkout_type   => $onsite_checkout ?
1437
                checkout_type   => $checkout_type,
1427
                        $Koha::Checkouts::type->{onsite_checkout}
1428
                      : $Koha::Checkouts::type->{checkout},
1429
                auto_renew      => $auto_renew ? 1 : 0,
1438
                auto_renew      => $auto_renew ? 1 : 0,
1430
            };
1439
            };
1431
1440
Lines 2032-2038 sub AddReturn { Link Here
2032
2041
2033
        if ( $issue and $issue->is_overdue($return_date) ) {
2042
        if ( $issue and $issue->is_overdue($return_date) ) {
2034
        # fix fine days
2043
        # fix fine days
2035
            my ($debardate,$reminder) = _debar_user_on_return( $patron_unblessed, $item->unblessed, dt_from_string($issue->date_due), $return_date );
2044
            my ($debardate,$reminder) = _debar_user_on_return( $patron_unblessed, $item->unblessed, $issue->checkout_type, dt_from_string($issue->date_due), $return_date );
2036
            if ($reminder){
2045
            if ($reminder){
2037
                $messages->{'PrevDebarred'} = $debardate;
2046
                $messages->{'PrevDebarred'} = $debardate;
2038
            } else {
2047
            } else {
Lines 2234-2245 sub MarkIssueReturned { Link Here
2234
2243
2235
=head2 _debar_user_on_return
2244
=head2 _debar_user_on_return
2236
2245
2237
    _debar_user_on_return($borrower, $item, $datedue, $returndate);
2246
    _debar_user_on_return($borrower, $item, $checkout_type, $datedue, $returndate);
2238
2247
2239
C<$borrower> borrower hashref
2248
C<$borrower> borrower hashref
2240
2249
2241
C<$item> item hashref
2250
C<$item> item hashref
2242
2251
2252
C<$checkout_type> One of $Koha::Checkouts::type values
2253
2243
C<$datedue> date due DateTime object
2254
C<$datedue> date due DateTime object
2244
2255
2245
C<$returndate> DateTime object representing the return time
2256
C<$returndate> DateTime object representing the return time
Lines 2255-2261 to ease testing. Link Here
2255
=cut
2266
=cut
2256
2267
2257
sub _calculate_new_debar_dt {
2268
sub _calculate_new_debar_dt {
2258
    my ( $borrower, $item, $dt_due, $return_date ) = @_;
2269
    my ( $borrower, $item, $checkout_type, $dt_due, $return_date ) = @_;
2259
2270
2260
    my $branchcode = _GetCircControlBranch( $item, $borrower );
2271
    my $branchcode = _GetCircControlBranch( $item, $borrower );
2261
    my $circcontrol = C4::Context->preference('CircControl');
2272
    my $circcontrol = C4::Context->preference('CircControl');
Lines 2263-2268 sub _calculate_new_debar_dt { Link Here
2263
        {   categorycode => $borrower->{categorycode},
2274
        {   categorycode => $borrower->{categorycode},
2264
            itemtype     => $item->{itype},
2275
            itemtype     => $item->{itype},
2265
            branchcode   => $branchcode,
2276
            branchcode   => $branchcode,
2277
            checkout_type => $checkout_type,
2266
            rules => [
2278
            rules => [
2267
                'finedays',
2279
                'finedays',
2268
                'lengthunit',
2280
                'lengthunit',
Lines 2336-2346 sub _calculate_new_debar_dt { Link Here
2336
}
2348
}
2337
2349
2338
sub _debar_user_on_return {
2350
sub _debar_user_on_return {
2339
    my ( $borrower, $item, $dt_due, $return_date ) = @_;
2351
    my ( $borrower, $item, $checkout_type, $dt_due, $return_date ) = @_;
2340
2352
2341
    $return_date //= dt_from_string();
2353
    $return_date //= dt_from_string();
2342
2354
2343
    my $new_debar_dt = _calculate_new_debar_dt ($borrower, $item, $dt_due, $return_date);
2355
    my $new_debar_dt = _calculate_new_debar_dt ($borrower, $item, $checkout_type, $dt_due, $return_date);
2344
2356
2345
    return unless $new_debar_dt;
2357
    return unless $new_debar_dt;
2346
2358
Lines 2972-2977 sub AddRenewal { Link Here
2972
                patron    => $patron,
2984
                patron    => $patron,
2973
                library   => $circ_library,
2985
                library   => $circ_library,
2974
                item      => $item_object,
2986
                item      => $item_object,
2987
                checkout_type => $issue->checkout_type,
2975
                from_date => dt_from_string( $issue->date_due, 'sql' ),
2988
                from_date => dt_from_string( $issue->date_due, 'sql' ),
2976
                to_date   => dt_from_string($datedue),
2989
                to_date   => dt_from_string($datedue),
2977
            }
2990
            }
Lines 3087-3098 sub GetRenewCount { Link Here
3087
    $renewcount = $data->{'renewals'} if $data->{'renewals'};
3100
    $renewcount = $data->{'renewals'} if $data->{'renewals'};
3088
    # $item and $borrower should be calculated
3101
    # $item and $borrower should be calculated
3089
    my $branchcode = _GetCircControlBranch($item->unblessed, $patron->unblessed);
3102
    my $branchcode = _GetCircControlBranch($item->unblessed, $patron->unblessed);
3103
    my $checkout_type = $data->{'checkout_type'};
3090
3104
3091
    my $rule = Koha::CirculationRules->get_effective_rule(
3105
    my $rule = Koha::CirculationRules->get_effective_rule(
3092
        {
3106
        {
3093
            categorycode => $patron->categorycode,
3107
            categorycode => $patron->categorycode,
3094
            itemtype     => $item->effective_itemtype,
3108
            itemtype     => $item->effective_itemtype,
3095
            branchcode   => $branchcode,
3109
            branchcode   => $branchcode,
3110
            checkout_type => $checkout_type,
3096
            rule_name    => 'renewalsallowed',
3111
            rule_name    => 'renewalsallowed',
3097
        }
3112
        }
3098
    );
3113
    );
(-)a/Koha/Charges/Fees.pm (+30 lines)
Lines 22-27 use Modern::Perl; Link Here
22
use Carp qw( carp confess );
22
use Carp qw( carp confess );
23
23
24
use Koha::Calendar;
24
use Koha::Calendar;
25
use Koha::Checkouts;
25
use Koha::DateUtils qw( dt_from_string );
26
use Koha::DateUtils qw( dt_from_string );
26
use Koha::Exceptions;
27
use Koha::Exceptions;
27
28
Lines 38-43 Koha::Charges::Fees->new( Link Here
38
        patron    => $patron,
39
        patron    => $patron,
39
        library   => $library,
40
        library   => $library,
40
        item      => $item,
41
        item      => $item,
42
        [ checkout_type => $checkout_type, ]
41
        to_date   => $to_dt,
43
        to_date   => $to_dt,
42
        [ from_date => $from_dt, ]
44
        [ from_date => $from_dt, ]
43
    }
45
    }
Lines 57-68 sub new { Link Here
57
    Koha::Exceptions::MissingParameter->throw("Missing mandatory parameter: to_date")
59
    Koha::Exceptions::MissingParameter->throw("Missing mandatory parameter: to_date")
58
        unless $params->{to_date};
60
        unless $params->{to_date};
59
61
62
    $params->{checkout_type} = exists $params->{checkout_type}
63
            ? $params->{checkout_type}
64
            : $Koha::Checkouts::type->{checkout};
65
60
    Carp::confess("Key 'patron' is not a Koha::Patron object!")
66
    Carp::confess("Key 'patron' is not a Koha::Patron object!")
61
      unless $params->{patron}->isa('Koha::Patron');
67
      unless $params->{patron}->isa('Koha::Patron');
62
    Carp::confess("Key 'library' is not a Koha::Library object!")
68
    Carp::confess("Key 'library' is not a Koha::Library object!")
63
      unless $params->{library}->isa('Koha::Library');
69
      unless $params->{library}->isa('Koha::Library');
64
    Carp::confess("Key 'item' is not a Koha::Item object!")
70
    Carp::confess("Key 'item' is not a Koha::Item object!")
65
      unless $params->{item}->isa('Koha::Item');
71
      unless $params->{item}->isa('Koha::Item');
72
    my @valid_types = values %$Koha::Checkouts::type;
73
    Carp::confess("Key 'checkout_type' is not valid! Valid are: " . join(', ', @valid_types))
74
      unless grep { $_ eq $params->{checkout_type} } @valid_types;
66
    Carp::confess("Key 'to_date' is not a DateTime object!")
75
    Carp::confess("Key 'to_date' is not a DateTime object!")
67
      unless $params->{to_date}->isa('DateTime');
76
      unless $params->{to_date}->isa('DateTime');
68
77
Lines 95-100 sub accumulate_rentalcharge { Link Here
95
            categorycode => $self->patron->categorycode,
104
            categorycode => $self->patron->categorycode,
96
            itemtype     => $itemtype->id,
105
            itemtype     => $itemtype->id,
97
            branchcode   => $self->library->id,
106
            branchcode   => $self->library->id,
107
            checkout_type => $self->checkout_type,
98
            rule_name    => 'lengthunit',
108
            rule_name    => 'lengthunit',
99
        }
109
        }
100
    );
110
    );
Lines 188-193 sub item { Link Here
188
    return $self->{item};
198
    return $self->{item};
189
}
199
}
190
200
201
=head3 checkout_type
202
203
my $item = $fees->checkout_type( $checkout_type );
204
205
=cut
206
207
sub checkout_type {
208
    my ( $self, $checkout_type ) = @_;
209
210
    if ( $checkout_type ) {
211
        my @valid_types = values %$Koha::Checkouts::type;
212
        Carp::carp("Given 'checkout_type' is not valid! Valid are: " . join(', ', @valid_types))
213
          unless grep { $_ eq $checkout_type } @valid_types;
214
215
        $self->{checkout_type} = $checkout_type if $checkout_type;
216
    }
217
218
    return $self->{checkout_type};
219
}
220
191
=head3 to_date
221
=head3 to_date
192
222
193
my $to_date = $fees->to_date( $to_date );
223
my $to_date = $fees->to_date( $to_date );
(-)a/Koha/REST/V1/Checkouts.pm (+1 lines)
Lines 214-219 sub allows_renewal { Link Here
214
                categorycode => $checkout->patron->categorycode,
214
                categorycode => $checkout->patron->categorycode,
215
                itemtype     => $checkout->item->effective_itemtype,
215
                itemtype     => $checkout->item->effective_itemtype,
216
                branchcode   => $checkout->branchcode,
216
                branchcode   => $checkout->branchcode,
217
                checkout_type => $checkout->checkout_type,
217
                rule_name    => 'renewalsallowed',
218
                rule_name    => 'renewalsallowed',
218
            }
219
            }
219
        );
220
        );
(-)a/Koha/Template/Plugin/CirculationRules.pm (-2 / +6 lines)
Lines 24-40 use base qw( Template::Plugin ); Link Here
24
use Koha::CirculationRules;
24
use Koha::CirculationRules;
25
25
26
sub Get {
26
sub Get {
27
    my ( $self, $branchcode, $categorycode, $itemtype, $rule_name ) = @_;
27
    my ( $self, $branchcode, $categorycode, $itemtype, $checkout_type, $rule_name ) = @_;
28
28
29
    $branchcode   = undef if $branchcode eq q{}   or $branchcode eq q{*};
29
    $branchcode   = undef if $branchcode eq q{}   or $branchcode eq q{*};
30
    $categorycode = undef if $categorycode eq q{} or $categorycode eq q{*};
30
    $categorycode = undef if $categorycode eq q{} or $categorycode eq q{*};
31
    $itemtype     = undef if $itemtype eq q{}     or $itemtype  eq q{*};
31
    $itemtype     = undef if $itemtype eq q{}     or $itemtype  eq q{*};
32
    $checkout_type = undef if $checkout_type eq {} or $checkout_type eq q{*};
32
33
33
    my $rule = Koha::CirculationRules->get_effective_rule(
34
    my $rule = Koha::CirculationRules->get_effective_rule(
34
        {
35
        {
35
            branchcode   => $branchcode,
36
            branchcode   => $branchcode,
36
            categorycode => $categorycode,
37
            categorycode => $categorycode,
37
            itemtype     => $itemtype,
38
            itemtype     => $itemtype,
39
            checkout_type => $checkout_type,
38
            rule_name    => $rule_name,
40
            rule_name    => $rule_name,
39
        }
41
        }
40
    );
42
    );
Lines 43-59 sub Get { Link Here
43
}
45
}
44
46
45
sub Search {
47
sub Search {
46
    my ( $self, $branchcode, $categorycode, $itemtype, $rule_name ) = @_;
48
    my ( $self, $branchcode, $categorycode, $itemtype, $checkout_type, $rule_name ) = @_;
47
49
48
    $branchcode   = undef if $branchcode eq q{}   or $branchcode eq q{*};
50
    $branchcode   = undef if $branchcode eq q{}   or $branchcode eq q{*};
49
    $categorycode = undef if $categorycode eq q{} or $categorycode eq q{*};
51
    $categorycode = undef if $categorycode eq q{} or $categorycode eq q{*};
50
    $itemtype     = undef if $itemtype eq q{}     or $itemtype eq q{*};
52
    $itemtype     = undef if $itemtype eq q{}     or $itemtype eq q{*};
53
    $checkout_type = undef if $checkout_type eq q{} or $checkout_type eq q{*};
51
54
52
    my $rule = Koha::CirculationRules->search(
55
    my $rule = Koha::CirculationRules->search(
53
        {
56
        {
54
            branchcode   => $branchcode,
57
            branchcode   => $branchcode,
55
            categorycode => $categorycode,
58
            categorycode => $categorycode,
56
            itemtype     => $itemtype,
59
            itemtype     => $itemtype,
60
            checkout_type => $checkout_type,
57
            rule_name    => $rule_name,
61
            rule_name    => $rule_name,
58
        }
62
        }
59
    )->next;
63
    )->next;
(-)a/api/v1/swagger/definitions/circ-rule-kind.json (-1 / +1 lines)
Lines 6-12 Link Here
6
      "type": "array",
6
      "type": "array",
7
      "items": {
7
      "items": {
8
        "type": "string",
8
        "type": "string",
9
        "enum": [ "branchcode", "categorycode", "itemtype" ]
9
        "enum": [ "branchcode", "categorycode", "itemtype", "checkout_type" ]
10
      }
10
      }
11
    }
11
    }
12
  },
12
  },
(-)a/t/db_dependent/Circulation/IssuingRules/maxsuspensiondays.t (-2 / +4 lines)
Lines 33-38 Koha::CirculationRules->set_rules( Link Here
33
        categorycode => undef,
33
        categorycode => undef,
34
        itemtype     => undef,
34
        itemtype     => undef,
35
        branchcode   => undef,
35
        branchcode   => undef,
36
        checkout_type => undef,
36
        rules        => {
37
        rules        => {
37
            firstremind => 0,
38
            firstremind => 0,
38
            finedays    => 2,
39
            finedays    => 2,
Lines 90-95 Koha::CirculationRules->set_rules( Link Here
90
        categorycode => undef,
91
        categorycode => undef,
91
        itemtype     => undef,
92
        itemtype     => undef,
92
        branchcode   => undef,
93
        branchcode   => undef,
94
        checkout_type => undef,
93
        rules        => {
95
        rules        => {
94
            maxsuspensiondays => 10,
96
            maxsuspensiondays => 10,
95
        }
97
        }
Lines 128-134 subtest "suspension_chargeperiod" => sub { Link Here
128
130
129
    my $last_year = dt_from_string->clone->subtract( years => 1 );
131
    my $last_year = dt_from_string->clone->subtract( years => 1 );
130
    my $today = dt_from_string;
132
    my $today = dt_from_string;
131
    my $new_debar_dt = C4::Circulation::_calculate_new_debar_dt( $patron->unblessed, $item->unblessed, $last_year, $today );
133
    my $new_debar_dt = C4::Circulation::_calculate_new_debar_dt( $patron->unblessed, $item->unblessed, undef, $last_year, $today );
132
    is( $new_debar_dt->truncate( to => 'day' ),
134
    is( $new_debar_dt->truncate( to => 'day' ),
133
        $today->clone->add( days => 365 / 15 * 7 )->truncate( to => 'day' ) );
135
        $today->clone->add( days => 365 / 15 * 7 )->truncate( to => 'day' ) );
134
136
Lines 155-161 subtest "maxsuspensiondays" => sub { Link Here
155
157
156
    my $last_year = dt_from_string->clone->subtract( years => 1 );
158
    my $last_year = dt_from_string->clone->subtract( years => 1 );
157
    my $today = dt_from_string;
159
    my $today = dt_from_string;
158
    my $new_debar_dt = C4::Circulation::_calculate_new_debar_dt( $patron->unblessed, $item->unblessed, $last_year, $today );
160
    my $new_debar_dt = C4::Circulation::_calculate_new_debar_dt( $patron->unblessed, $item->unblessed, undef, $last_year, $today );
159
    is( $new_debar_dt->truncate( to => 'day' ),
161
    is( $new_debar_dt->truncate( to => 'day' ),
160
        $today->clone->add( days => 333 )->truncate( to => 'day' ) );
162
        $today->clone->add( days => 333 )->truncate( to => 'day' ) );
161
};
163
};
(-)a/t/db_dependent/Koha/Charges/Fees.t (-1 / +17 lines)
Lines 29-34 use t::lib::Dates; Link Here
29
29
30
use Time::Fake;
30
use Time::Fake;
31
use C4::Calendar;
31
use C4::Calendar;
32
use Koha::Checkouts;
32
use Koha::DateUtils qw(dt_from_string);
33
use Koha::DateUtils qw(dt_from_string);
33
34
34
BEGIN {
35
BEGIN {
Lines 100-106 my $dt_from = $now->clone->subtract( days => 2 ); Link Here
100
my $dt_to = $now->clone->add( days => 4 );
101
my $dt_to = $now->clone->add( days => 4 );
101
102
102
subtest 'new' => sub {
103
subtest 'new' => sub {
103
    plan tests => 9;
104
    plan tests => 10;
104
105
105
    # Mandatory parameters missing
106
    # Mandatory parameters missing
106
    throws_ok {
107
    throws_ok {
Lines 178-183 subtest 'new' => sub { Link Here
178
          )
179
          )
179
    }
180
    }
180
    'dies for bad item';
181
    'dies for bad item';
182
    dies_ok {
183
        Koha::Charges::Fees->new(
184
            {
185
                patron  => $patron,
186
                library => $library,
187
                item    => $item,
188
                checkout_type => 'NON-EXISTENT-CHECKOUT-TYPE:)',
189
                to_date => $dt_to,
190
            }
191
          )
192
    }
193
    'dies for bad checkout_type';
181
    dies_ok {
194
    dies_ok {
182
        Koha::Charges::Fees->new(
195
        Koha::Charges::Fees->new(
183
            {
196
            {
Lines 327-332 subtest 'accumulate_rentalcharge tests' => sub { Link Here
327
            categorycode => $patron->categorycode,
340
            categorycode => $patron->categorycode,
328
            itemtype     => $itemtype->id,
341
            itemtype     => $itemtype->id,
329
            branchcode   => $library->id,
342
            branchcode   => $library->id,
343
            checkout_type => undef,
330
            rules => {
344
            rules => {
331
                lengthunit => 'days',
345
                lengthunit => 'days',
332
            }
346
            }
Lines 388-393 subtest 'accumulate_rentalcharge tests' => sub { Link Here
388
            categorycode => $patron->categorycode,
402
            categorycode => $patron->categorycode,
389
            itemtype     => $itemtype->id,
403
            itemtype     => $itemtype->id,
390
            branchcode   => $library->id,
404
            branchcode   => $library->id,
405
            checkout_type => undef,
391
            rules => {
406
            rules => {
392
                lengthunit => 'hours',
407
                lengthunit => 'hours',
393
            }
408
            }
Lines 404-409 subtest 'accumulate_rentalcharge tests' => sub { Link Here
404
            patron    => $patron,
419
            patron    => $patron,
405
            library   => $library,
420
            library   => $library,
406
            item      => $item,
421
            item      => $item,
422
            checkout_type => $Koha::Checkouts::type->{checkout},
407
            to_date   => $dt_to,
423
            to_date   => $dt_to,
408
            from_date => $dt_from,
424
            from_date => $dt_from,
409
        }
425
        }
(-)a/t/db_dependent/Koha/IssuingRules.t (-8 / +40 lines)
Lines 25-30 use Test::Exception; Link Here
25
25
26
use Benchmark;
26
use Benchmark;
27
27
28
use Koha::Checkouts;
28
use Koha::CirculationRules;
29
use Koha::CirculationRules;
29
30
30
use t::lib::TestBuilder;
31
use t::lib::TestBuilder;
Lines 41-46 subtest 'get_effective_issuing_rule' => sub { Link Here
41
    my $categorycode = $builder->build({ source => 'Category' })->{'categorycode'};
42
    my $categorycode = $builder->build({ source => 'Category' })->{'categorycode'};
42
    my $itemtype     = $builder->build({ source => 'Itemtype' })->{'itemtype'};
43
    my $itemtype     = $builder->build({ source => 'Itemtype' })->{'itemtype'};
43
    my $branchcode   = $builder->build({ source => 'Branch' })->{'branchcode'};
44
    my $branchcode   = $builder->build({ source => 'Branch' })->{'branchcode'};
45
    my $checkout_type = $Koha::Checkouts::type->{checkout};
44
46
45
    subtest 'Call with undefined values' => sub {
47
    subtest 'Call with undefined values' => sub {
46
        plan tests => 5;
48
        plan tests => 5;
Lines 54-59 subtest 'get_effective_issuing_rule' => sub { Link Here
54
            branchcode   => undef,
56
            branchcode   => undef,
55
            categorycode => undef,
57
            categorycode => undef,
56
            itemtype     => undef,
58
            itemtype     => undef,
59
            checkout_type => undef,
57
            rule_name    => 'fine',
60
            rule_name    => 'fine',
58
            rule_value   => 1,
61
            rule_value   => 1,
59
        });
62
        });
Lines 67-72 subtest 'get_effective_issuing_rule' => sub { Link Here
67
                    branchcode   => undef,
70
                    branchcode   => undef,
68
                    categorycode => undef,
71
                    categorycode => undef,
69
                    itemtype     => undef,
72
                    itemtype     => undef,
73
                    checkout_type => undef,
70
                    rule_name    => 'fine',
74
                    rule_name    => 'fine',
71
                    rule_value   => 2,
75
                    rule_value   => 2,
72
                }
76
                }
Lines 77-82 subtest 'get_effective_issuing_rule' => sub { Link Here
77
            branchcode   => undef,
81
            branchcode   => undef,
78
            categorycode => undef,
82
            categorycode => undef,
79
            itemtype     => undef,
83
            itemtype     => undef,
84
            checkout_type => undef,
80
            rule_name    => 'fine',
85
            rule_name    => 'fine',
81
        });
86
        });
82
        _is_row_match(
87
        _is_row_match(
Lines 85-90 subtest 'get_effective_issuing_rule' => sub { Link Here
85
                branchcode   => undef,
90
                branchcode   => undef,
86
                categorycode => undef,
91
                categorycode => undef,
87
                itemtype     => undef,
92
                itemtype     => undef,
93
                checkout_type => undef,
88
                rule_name    => 'fine',
94
                rule_name    => 'fine',
89
                rule_value   => 2,
95
                rule_value   => 2,
90
            },
96
            },
Lines 95-125 subtest 'get_effective_issuing_rule' => sub { Link Here
95
    };
101
    };
96
102
97
    subtest 'Performance' => sub {
103
    subtest 'Performance' => sub {
98
        plan tests => 4;
104
        plan tests => 5;
99
105
100
        my $worst_case = timethis(500,
106
        my $worst_case = timethis(500,
101
                    sub { Koha::CirculationRules->get_effective_rule({
107
                    sub { Koha::CirculationRules->get_effective_rule({
102
                            branchcode   => 'nonexistent',
108
                            branchcode   => 'nonexistent',
103
                            categorycode => 'nonexistent',
109
                            categorycode => 'nonexistent',
104
                            itemtype     => 'nonexistent',
110
                            itemtype     => 'nonexistent',
111
                            checkout_type => 'nonexistent',
105
                            rule_name    => 'nonexistent',
112
                            rule_name    => 'nonexistent',
106
                        });
113
                        });
107
                    }
114
                    }
108
                );
115
                );
109
        my $mid_case = timethis(500,
116
        my $mid_case1 = timethis(500,
110
                    sub { Koha::CirculationRules->get_effective_rule({
117
                    sub { Koha::CirculationRules->get_effective_rule({
111
                            branchcode   => $branchcode,
118
                            branchcode   => $branchcode,
112
                            categorycode => 'nonexistent',
119
                            categorycode => 'nonexistent',
113
                            itemtype     => 'nonexistent',
120
                            itemtype     => 'nonexistent',
121
                            checkout_type => 'nonexistent',
114
                            rule_name    => 'nonexistent',
122
                            rule_name    => 'nonexistent',
115
                        });
123
                        });
116
                    }
124
                    }
117
                );
125
                );
118
        my $sec_best_case = timethis(500,
126
        my $mid_case2 = timethis(500,
119
                    sub { Koha::CirculationRules->get_effective_rule({
127
                    sub { Koha::CirculationRules->get_effective_rule({
120
                            branchcode   => $branchcode,
128
                            branchcode   => $branchcode,
121
                            categorycode => $categorycode,
129
                            categorycode => $categorycode,
122
                            itemtype     => 'nonexistent',
130
                            itemtype     => 'nonexistent',
131
                            checkout_type => 'nonexistent',
132
                            rule_name    => 'nonexistent',
133
                        });
134
                    }
135
                );
136
        my $mid_case3 = timethis(500,
137
                    sub { Koha::CirculationRules->get_effective_rule({
138
                            branchcode   => $branchcode,
139
                            categorycode => $categorycode,
140
                            itemtype     => $itemtype,
141
                            checkout_type => 'nonexistent',
123
                            rule_name    => 'nonexistent',
142
                            rule_name    => 'nonexistent',
124
                        });
143
                        });
125
                    }
144
                    }
Lines 129-134 subtest 'get_effective_issuing_rule' => sub { Link Here
129
                            branchcode   => $branchcode,
148
                            branchcode   => $branchcode,
130
                            categorycode => $categorycode,
149
                            categorycode => $categorycode,
131
                            itemtype     => $itemtype,
150
                            itemtype     => $itemtype,
151
                            checkout_type => $checkout_type,
132
                            rule_name    => 'nonexistent',
152
                            rule_name    => 'nonexistent',
133
                        });
153
                        });
134
                    }
154
                    }
Lines 136-146 subtest 'get_effective_issuing_rule' => sub { Link Here
136
        ok($worst_case, 'In worst case, get_effective_issuing_rule finds matching'
156
        ok($worst_case, 'In worst case, get_effective_issuing_rule finds matching'
137
           .' rule '.sprintf('%.2f', $worst_case->iters/$worst_case->cpu_a)
157
           .' rule '.sprintf('%.2f', $worst_case->iters/$worst_case->cpu_a)
138
           .' times per second.');
158
           .' times per second.');
139
        ok($mid_case, 'In mid case, get_effective_issuing_rule finds matching'
159
        ok($mid_case1, 'In mid case 1, get_effective_issuing_rule finds matching'
140
           .' rule '.sprintf('%.2f', $mid_case->iters/$mid_case->cpu_a)
160
           .' rule '.sprintf('%.2f', $mid_case1->iters/$mid_case1->cpu_a)
161
           .' times per second.');
162
        ok($mid_case2, 'In mid case 2, get_effective_issuing_rule finds matching'
163
           .' rule '.sprintf('%.2f', $mid_case2->iters/$mid_case2->cpu_a)
141
           .' times per second.');
164
           .' times per second.');
142
        ok($sec_best_case, 'In second best case, get_effective_issuing_rule finds matching'
165
        ok($mid_case3, 'In mid case 3, get_effective_issuing_rule finds matching'
143
           .' rule '.sprintf('%.2f', $sec_best_case->iters/$sec_best_case->cpu_a)
166
           .' rule '.sprintf('%.2f', $mid_case3->iters/$mid_case3->cpu_a)
144
           .' times per second.');
167
           .' times per second.');
145
        ok($best_case, 'In best case, get_effective_issuing_rule finds matching'
168
        ok($best_case, 'In best case, get_effective_issuing_rule finds matching'
146
           .' rule '.sprintf('%.2f', $best_case->iters/$best_case->cpu_a)
169
           .' rule '.sprintf('%.2f', $best_case->iters/$best_case->cpu_a)
Lines 292-297 subtest 'clone' => sub { Link Here
292
    my $branchcode   = $builder->build({ source => 'Branch' })->{'branchcode'};
315
    my $branchcode   = $builder->build({ source => 'Branch' })->{'branchcode'};
293
    my $categorycode = $builder->build({ source => 'Category' })->{'categorycode'};
316
    my $categorycode = $builder->build({ source => 'Category' })->{'categorycode'};
294
    my $itemtype     = $builder->build({ source => 'Itemtype' })->{'itemtype'};
317
    my $itemtype     = $builder->build({ source => 'Itemtype' })->{'itemtype'};
318
    my $checkout_type = $Koha::Checkouts::type->{checkout};
295
319
296
    subtest 'Clone multiple rules' => sub {
320
    subtest 'Clone multiple rules' => sub {
297
        plan tests => 4;
321
        plan tests => 4;
Lines 302-307 subtest 'clone' => sub { Link Here
302
            branchcode   => undef,
326
            branchcode   => undef,
303
            categorycode => $categorycode,
327
            categorycode => $categorycode,
304
            itemtype     => $itemtype,
328
            itemtype     => $itemtype,
329
            checkout_type => $checkout_type,
305
            rule_name    => 'fine',
330
            rule_name    => 'fine',
306
            rule_value   => 5,
331
            rule_value   => 5,
307
        })->store;
332
        })->store;
Lines 310-315 subtest 'clone' => sub { Link Here
310
            branchcode   => undef,
335
            branchcode   => undef,
311
            categorycode => $categorycode,
336
            categorycode => $categorycode,
312
            itemtype     => $itemtype,
337
            itemtype     => $itemtype,
338
            checkout_type => $checkout_type,
313
            rule_name    => 'lengthunit',
339
            rule_name    => 'lengthunit',
314
            rule_value   => 'days',
340
            rule_value   => 'days',
315
        })->store;
341
        })->store;
Lines 320-331 subtest 'clone' => sub { Link Here
320
            branchcode   => $branchcode,
346
            branchcode   => $branchcode,
321
            categorycode => $categorycode,
347
            categorycode => $categorycode,
322
            itemtype     => $itemtype,
348
            itemtype     => $itemtype,
349
            checkout_type => $checkout_type,
323
            rule_name    => 'fine',
350
            rule_name    => 'fine',
324
        });
351
        });
325
        my $rule_lengthunit = Koha::CirculationRules->get_effective_rule({
352
        my $rule_lengthunit = Koha::CirculationRules->get_effective_rule({
326
            branchcode   => $branchcode,
353
            branchcode   => $branchcode,
327
            categorycode => $categorycode,
354
            categorycode => $categorycode,
328
            itemtype     => $itemtype,
355
            itemtype     => $itemtype,
356
            checkout_type => $checkout_type,
329
            rule_name    => 'lengthunit',
357
            rule_name    => 'lengthunit',
330
        });
358
        });
331
359
Lines 335-340 subtest 'clone' => sub { Link Here
335
                branchcode   => $branchcode,
363
                branchcode   => $branchcode,
336
                categorycode => $categorycode,
364
                categorycode => $categorycode,
337
                itemtype     => $itemtype,
365
                itemtype     => $itemtype,
366
                checkout_type => $checkout_type,
338
                rule_name    => 'fine',
367
                rule_name    => 'fine',
339
                rule_value   => 5,
368
                rule_value   => 5,
340
            },
369
            },
Lines 347-352 subtest 'clone' => sub { Link Here
347
                branchcode   => $branchcode,
376
                branchcode   => $branchcode,
348
                categorycode => $categorycode,
377
                categorycode => $categorycode,
349
                itemtype     => $itemtype,
378
                itemtype     => $itemtype,
379
                checkout_type => $checkout_type,
350
                rule_name    => 'lengthunit',
380
                rule_name    => 'lengthunit',
351
                rule_value   => 'days',
381
                rule_value   => 'days',
352
            },
382
            },
Lines 365-370 subtest 'clone' => sub { Link Here
365
            branchcode   => undef,
395
            branchcode   => undef,
366
            categorycode => $categorycode,
396
            categorycode => $categorycode,
367
            itemtype     => $itemtype,
397
            itemtype     => $itemtype,
398
            checkout_type => $checkout_type,
368
            rule_name    => 'fine',
399
            rule_name    => 'fine',
369
            rule_value   => 5,
400
            rule_value   => 5,
370
        })->store;
401
        })->store;
Lines 376-381 subtest 'clone' => sub { Link Here
376
            branchcode   => $branchcode,
407
            branchcode   => $branchcode,
377
            categorycode => $categorycode,
408
            categorycode => $categorycode,
378
            itemtype     => $itemtype,
409
            itemtype     => $itemtype,
410
            checkout_type => $checkout_type,
379
            rule_name    => 'fine',
411
            rule_name    => 'fine',
380
        });
412
        });
381
413
Lines 385-390 subtest 'clone' => sub { Link Here
385
                branchcode   => $branchcode,
417
                branchcode   => $branchcode,
386
                categorycode => $categorycode,
418
                categorycode => $categorycode,
387
                itemtype     => $itemtype,
419
                itemtype     => $itemtype,
420
                checkout_type => $checkout_type,
388
                rule_name    => 'fine',
421
                rule_name    => 'fine',
389
                rule_value   => '5',
422
                rule_value   => '5',
390
            },
423
            },
391
- 

Return to bug 25089