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 1301-1306 sub AddIssue { Link Here
1301
    my $auto_renew = $params && $params->{auto_renew};
1305
    my $auto_renew = $params && $params->{auto_renew};
1302
    my $dbh          = C4::Context->dbh;
1306
    my $dbh          = C4::Context->dbh;
1303
    my $barcodecheck = CheckValidBarcode($barcode);
1307
    my $barcodecheck = CheckValidBarcode($barcode);
1308
    my $checkout_type = $onsite_checkout
1309
        ? $switch_onsite_checkout
1310
            ? $Koha::Checkouts::type->{checkout}
1311
            : $Koha::Checkouts::type->{onsite_checkout}
1312
        : $Koha::Checkouts::type->{checkout};
1304
1313
1305
    my $issue;
1314
    my $issue;
1306
1315
Lines 1357-1362 sub AddIssue { Link Here
1357
                    patron    => $patron,
1366
                    patron    => $patron,
1358
                    library   => $library,
1367
                    library   => $library,
1359
                    item      => $item_object,
1368
                    item      => $item_object,
1369
                    checkout_type => $checkout_type,
1360
                    to_date   => $datedue,
1370
                    to_date   => $datedue,
1361
                }
1371
                }
1362
            );
1372
            );
Lines 1394-1399 sub AddIssue { Link Here
1394
                        categorycode => $borrower->{categorycode},
1404
                        categorycode => $borrower->{categorycode},
1395
                        itemtype     => $item_object->effective_itemtype,
1405
                        itemtype     => $item_object->effective_itemtype,
1396
                        branchcode   => $branchcode,
1406
                        branchcode   => $branchcode,
1407
                        checkout_type => $checkout_type,
1397
                        rule_name    => 'auto_renew'
1408
                        rule_name    => 'auto_renew'
1398
                    }
1409
                    }
1399
                );
1410
                );
Lines 1414-1422 sub AddIssue { Link Here
1414
                issuedate       => $issuedate->strftime('%Y-%m-%d %H:%M:%S'),
1425
                issuedate       => $issuedate->strftime('%Y-%m-%d %H:%M:%S'),
1415
                date_due        => $datedue->strftime('%Y-%m-%d %H:%M:%S'),
1426
                date_due        => $datedue->strftime('%Y-%m-%d %H:%M:%S'),
1416
                branchcode      => C4::Context->userenv->{'branch'},
1427
                branchcode      => C4::Context->userenv->{'branch'},
1417
                checkout_type   => $onsite_checkout ?
1428
                checkout_type   => $checkout_type,
1418
                        $Koha::Checkouts::type->{onsite_checkout}
1419
                      : $Koha::Checkouts::type->{checkout},
1420
                auto_renew      => $auto_renew ? 1 : 0,
1429
                auto_renew      => $auto_renew ? 1 : 0,
1421
            };
1430
            };
1422
1431
Lines 1991-1997 sub AddReturn { Link Here
1991
2000
1992
        if ( $issue and $issue->is_overdue ) {
2001
        if ( $issue and $issue->is_overdue ) {
1993
        # fix fine days
2002
        # fix fine days
1994
            my ($debardate,$reminder) = _debar_user_on_return( $patron_unblessed, $item->unblessed, dt_from_string($issue->date_due), $return_date );
2003
            my ($debardate,$reminder) = _debar_user_on_return( $patron_unblessed, $item->unblessed, $issue->checkout_type, dt_from_string($issue->date_due), $return_date );
1995
            if ($reminder){
2004
            if ($reminder){
1996
                $messages->{'PrevDebarred'} = $debardate;
2005
                $messages->{'PrevDebarred'} = $debardate;
1997
            } else {
2006
            } else {
Lines 2191-2202 sub MarkIssueReturned { Link Here
2191
2200
2192
=head2 _debar_user_on_return
2201
=head2 _debar_user_on_return
2193
2202
2194
    _debar_user_on_return($borrower, $item, $datedue, $returndate);
2203
    _debar_user_on_return($borrower, $item, $checkout_type, $datedue, $returndate);
2195
2204
2196
C<$borrower> borrower hashref
2205
C<$borrower> borrower hashref
2197
2206
2198
C<$item> item hashref
2207
C<$item> item hashref
2199
2208
2209
C<$checkout_type> One of $Koha::Checkouts::type values
2210
2200
C<$datedue> date due DateTime object
2211
C<$datedue> date due DateTime object
2201
2212
2202
C<$returndate> DateTime object representing the return time
2213
C<$returndate> DateTime object representing the return time
Lines 2212-2218 to ease testing. Link Here
2212
=cut
2223
=cut
2213
2224
2214
sub _calculate_new_debar_dt {
2225
sub _calculate_new_debar_dt {
2215
    my ( $borrower, $item, $dt_due, $return_date ) = @_;
2226
    my ( $borrower, $item, $checkout_type, $dt_due, $return_date ) = @_;
2216
2227
2217
    my $branchcode = _GetCircControlBranch( $item, $borrower );
2228
    my $branchcode = _GetCircControlBranch( $item, $borrower );
2218
    my $circcontrol = C4::Context->preference('CircControl');
2229
    my $circcontrol = C4::Context->preference('CircControl');
Lines 2220-2225 sub _calculate_new_debar_dt { Link Here
2220
        {   categorycode => $borrower->{categorycode},
2231
        {   categorycode => $borrower->{categorycode},
2221
            itemtype     => $item->{itype},
2232
            itemtype     => $item->{itype},
2222
            branchcode   => $branchcode,
2233
            branchcode   => $branchcode,
2234
            checkout_type => $checkout_type,
2223
            rules => [
2235
            rules => [
2224
                'finedays',
2236
                'finedays',
2225
                'lengthunit',
2237
                'lengthunit',
Lines 2293-2303 sub _calculate_new_debar_dt { Link Here
2293
}
2305
}
2294
2306
2295
sub _debar_user_on_return {
2307
sub _debar_user_on_return {
2296
    my ( $borrower, $item, $dt_due, $return_date ) = @_;
2308
    my ( $borrower, $item, $checkout_type, $dt_due, $return_date ) = @_;
2297
2309
2298
    $return_date //= dt_from_string();
2310
    $return_date //= dt_from_string();
2299
2311
2300
    my $new_debar_dt = _calculate_new_debar_dt ($borrower, $item, $dt_due, $return_date);
2312
    my $new_debar_dt = _calculate_new_debar_dt ($borrower, $item, $checkout_type, $dt_due, $return_date);
2301
2313
2302
    return unless $new_debar_dt;
2314
    return unless $new_debar_dt;
2303
2315
Lines 2925-2930 sub AddRenewal { Link Here
2925
                patron    => $patron,
2937
                patron    => $patron,
2926
                library   => $circ_library,
2938
                library   => $circ_library,
2927
                item      => $item_object,
2939
                item      => $item_object,
2940
                checkout_type => $issue->checkout_type,
2928
                from_date => dt_from_string( $issue->date_due, 'sql' ),
2941
                from_date => dt_from_string( $issue->date_due, 'sql' ),
2929
                to_date   => dt_from_string($datedue),
2942
                to_date   => dt_from_string($datedue),
2930
            }
2943
            }
Lines 3040-3051 sub GetRenewCount { Link Here
3040
    $renewcount = $data->{'renewals'} if $data->{'renewals'};
3053
    $renewcount = $data->{'renewals'} if $data->{'renewals'};
3041
    # $item and $borrower should be calculated
3054
    # $item and $borrower should be calculated
3042
    my $branchcode = _GetCircControlBranch($item->unblessed, $patron->unblessed);
3055
    my $branchcode = _GetCircControlBranch($item->unblessed, $patron->unblessed);
3056
    my $checkout_type = $data->{'checkout_type'};
3043
3057
3044
    my $rule = Koha::CirculationRules->get_effective_rule(
3058
    my $rule = Koha::CirculationRules->get_effective_rule(
3045
        {
3059
        {
3046
            categorycode => $patron->categorycode,
3060
            categorycode => $patron->categorycode,
3047
            itemtype     => $item->effective_itemtype,
3061
            itemtype     => $item->effective_itemtype,
3048
            branchcode   => $branchcode,
3062
            branchcode   => $branchcode,
3063
            checkout_type => $checkout_type,
3049
            rule_name    => 'renewalsallowed',
3064
            rule_name    => 'renewalsallowed',
3050
        }
3065
        }
3051
    );
3066
    );
(-)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 213-218 sub allows_renewal { Link Here
213
            categorycode => $checkout->patron->categorycode,
213
            categorycode => $checkout->patron->categorycode,
214
            itemtype     => $checkout->item->effective_itemtype,
214
            itemtype     => $checkout->item->effective_itemtype,
215
            branchcode   => $checkout->branchcode,
215
            branchcode   => $checkout->branchcode,
216
            checkout_type => $checkout->checkout_type,
216
            rule_name    => 'renewalsallowed',
217
            rule_name    => 'renewalsallowed',
217
        }
218
        }
218
    );
219
    );
(-)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 28-33 use t::lib::TestBuilder; Link Here
28
28
29
use Time::Fake;
29
use Time::Fake;
30
use C4::Calendar;
30
use C4::Calendar;
31
use Koha::Checkouts;
31
use Koha::DateUtils qw(dt_from_string);
32
use Koha::DateUtils qw(dt_from_string);
32
33
33
BEGIN {
34
BEGIN {
Lines 99-105 my $dt_from = $now->clone->subtract( days => 2 ); Link Here
99
my $dt_to = $now->clone->add( days => 4 );
100
my $dt_to = $now->clone->add( days => 4 );
100
101
101
subtest 'new' => sub {
102
subtest 'new' => sub {
102
    plan tests => 9;
103
    plan tests => 10;
103
104
104
    # Mandatory parameters missing
105
    # Mandatory parameters missing
105
    throws_ok {
106
    throws_ok {
Lines 177-182 subtest 'new' => sub { Link Here
177
          )
178
          )
178
    }
179
    }
179
    'dies for bad item';
180
    'dies for bad item';
181
    dies_ok {
182
        Koha::Charges::Fees->new(
183
            {
184
                patron  => $patron,
185
                library => $library,
186
                item    => $item,
187
                checkout_type => 'NON-EXISTENT-CHECKOUT-TYPE:)',
188
                to_date => $dt_to,
189
            }
190
          )
191
    }
192
    'dies for bad checkout_type';
180
    dies_ok {
193
    dies_ok {
181
        Koha::Charges::Fees->new(
194
        Koha::Charges::Fees->new(
182
            {
195
            {
Lines 326-331 subtest 'accumulate_rentalcharge tests' => sub { Link Here
326
            categorycode => $patron->categorycode,
339
            categorycode => $patron->categorycode,
327
            itemtype     => $itemtype->id,
340
            itemtype     => $itemtype->id,
328
            branchcode   => $library->id,
341
            branchcode   => $library->id,
342
            checkout_type => undef,
329
            rules => {
343
            rules => {
330
                lengthunit => 'days',
344
                lengthunit => 'days',
331
            }
345
            }
Lines 387-392 subtest 'accumulate_rentalcharge tests' => sub { Link Here
387
            categorycode => $patron->categorycode,
401
            categorycode => $patron->categorycode,
388
            itemtype     => $itemtype->id,
402
            itemtype     => $itemtype->id,
389
            branchcode   => $library->id,
403
            branchcode   => $library->id,
404
            checkout_type => undef,
390
            rules => {
405
            rules => {
391
                lengthunit => 'hours',
406
                lengthunit => 'hours',
392
            }
407
            }
Lines 403-408 subtest 'accumulate_rentalcharge tests' => sub { Link Here
403
            patron    => $patron,
418
            patron    => $patron,
404
            library   => $library,
419
            library   => $library,
405
            item      => $item,
420
            item      => $item,
421
            checkout_type => $Koha::Checkouts::type->{checkout},
406
            to_date   => $dt_to,
422
            to_date   => $dt_to,
407
            from_date => $dt_from,
423
            from_date => $dt_from,
408
        }
424
        }
(-)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