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

(-)a/C4/Circulation.pm (-3 / +8 lines)
Lines 2713-2719 sub CanBookBeRenewed { Link Here
2713
2713
2714
    my $item      = Koha::Items->find($itemnumber)      or return ( 0, 'no_item' );
2714
    my $item      = Koha::Items->find($itemnumber)      or return ( 0, 'no_item' );
2715
    my $issue = $item->checkout or return ( 0, 'no_checkout' );
2715
    my $issue = $item->checkout or return ( 0, 'no_checkout' );
2716
    return ( 0, 'onsite_checkout' ) if $issue->onsite_checkout;
2717
    return ( 0, 'item_denied_renewal') if _item_denied_renewal({ item => $item });
2716
    return ( 0, 'item_denied_renewal') if _item_denied_renewal({ item => $item });
2718
2717
2719
    my $patron = $issue->patron or return;
2718
    my $patron = $issue->patron or return;
Lines 2728-2733 sub CanBookBeRenewed { Link Here
2728
                branchcode   => $branchcode,
2727
                branchcode   => $branchcode,
2729
                rules => [
2728
                rules => [
2730
                    'renewalsallowed',
2729
                    'renewalsallowed',
2730
                    'onsite_renewalsallowed',
2731
                    'no_auto_renewal_after',
2731
                    'no_auto_renewal_after',
2732
                    'no_auto_renewal_after_hard_limit',
2732
                    'no_auto_renewal_after_hard_limit',
2733
                    'lengthunit',
2733
                    'lengthunit',
Lines 2736-2743 sub CanBookBeRenewed { Link Here
2736
            }
2736
            }
2737
        );
2737
        );
2738
2738
2739
        my $renewals_allowed = $issue->onsite_checkout ?
2740
             $issuing_rule->{onsite_renewalsallowed} :  $issuing_rule->{renewalsallowed};
2741
2739
        return ( 0, "too_many" )
2742
        return ( 0, "too_many" )
2740
          if not $issuing_rule->{renewalsallowed} or $issuing_rule->{renewalsallowed} <= $issue->renewals;
2743
          if not $renewals_allowed or $renewals_allowed <= $issue->renewals;
2741
2744
2742
        my $overduesblockrenewing = C4::Context->preference('OverduesBlockRenewing');
2745
        my $overduesblockrenewing = C4::Context->preference('OverduesBlockRenewing');
2743
        my $restrictionblockrenewing = C4::Context->preference('RestrictionBlockRenewing');
2746
        my $restrictionblockrenewing = C4::Context->preference('RestrictionBlockRenewing');
Lines 3097-3108 sub GetRenewCount { Link Here
3097
    # $item and $borrower should be calculated
3100
    # $item and $borrower should be calculated
3098
    my $branchcode = _GetCircControlBranch($item->unblessed, $patron->unblessed);
3101
    my $branchcode = _GetCircControlBranch($item->unblessed, $patron->unblessed);
3099
3102
3103
    my $rule_name = $data->{'onsite_checkout'} ?
3104
        'onsite_renewalsallowed' : 'renewalsallowed';
3100
    my $rule = Koha::CirculationRules->get_effective_rule(
3105
    my $rule = Koha::CirculationRules->get_effective_rule(
3101
        {
3106
        {
3102
            categorycode => $patron->categorycode,
3107
            categorycode => $patron->categorycode,
3103
            itemtype     => $item->effective_itemtype,
3108
            itemtype     => $item->effective_itemtype,
3104
            branchcode   => $branchcode,
3109
            branchcode   => $branchcode,
3105
            rule_name    => 'renewalsallowed',
3110
            rule_name    => $rule_name,
3106
        }
3111
        }
3107
    );
3112
    );
3108
3113
(-)a/Koha/CirculationRules.pm (+3 lines)
Lines 130-135 our $RULE_KINDS = { Link Here
130
    norenewalbefore => {
130
    norenewalbefore => {
131
        scope => [ 'branchcode', 'categorycode', 'itemtype' ],
131
        scope => [ 'branchcode', 'categorycode', 'itemtype' ],
132
    },
132
    },
133
    onsite_renewalsallowed => {
134
        scope => [ 'branchcode', 'categorycode', 'itemtype' ],
135
    },
133
    onshelfholds => {
136
    onshelfholds => {
134
        scope => [ 'branchcode', 'categorycode', 'itemtype' ],
137
        scope => [ 'branchcode', 'categorycode', 'itemtype' ],
135
    },
138
    },
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/renew.tt (-4 / +1 lines)
Lines 30-36 Link Here
30
30
31
                [% IF error %]
31
                [% IF error %]
32
                    <div class="dialog alert">
32
                    <div class="dialog alert">
33
                        <h3>Cannot renew:</h3>
33
                        <h3>Cannot renew[% IF issue.onsite_checkout %] on-site checkout[% END %]:</h3>
34
34
35
                            [% IF error == "no_item" %]
35
                            [% IF error == "no_item" %]
36
36
Lines 134-142 Link Here
134
134
135
                                <p>Item is not allowed renewal.</p>
135
                                <p>Item is not allowed renewal.</p>
136
136
137
                            [% ELSIF error == "onsite_checkout" %]
138
                                <p>Item cannot be renewed because it's an onsite checkout</p>
139
140
                            [% ELSE %]
137
                            [% ELSE %]
141
138
142
                                [% error | html %]
139
                                [% error | html %]
(-)a/t/db_dependent/Circulation.t (-31 / +1 lines)
Lines 18-24 Link Here
18
use Modern::Perl;
18
use Modern::Perl;
19
use utf8;
19
use utf8;
20
20
21
use Test::More tests => 46;
21
use Test::More tests => 44;
22
use Test::MockModule;
22
use Test::MockModule;
23
use Test::Deep qw( cmp_deeply );
23
use Test::Deep qw( cmp_deeply );
24
24
Lines 1514-1549 subtest "AllowRenewalIfOtherItemsAvailable tests" => sub { Link Here
1514
    is( $renewokay, 0, 'Bug 14337 - Verify the borrower can not renew with a hold on the record if AllowRenewalIfOtherItemsAvailable is enabled but the only available item is notforloan' );
1514
    is( $renewokay, 0, 'Bug 14337 - Verify the borrower can not renew with a hold on the record if AllowRenewalIfOtherItemsAvailable is enabled but the only available item is notforloan' );
1515
};
1515
};
1516
1516
1517
{
1518
    # Don't allow renewing onsite checkout
1519
    my $branch   = $library->{branchcode};
1520
1521
    #Create another record
1522
    my $biblio = $builder->build_sample_biblio();
1523
1524
    my $item = $builder->build_sample_item(
1525
        {
1526
            biblionumber     => $biblio->biblionumber,
1527
            library          => $branch,
1528
            itype            => $itemtype,
1529
        }
1530
    );
1531
1532
    my $borrowernumber = Koha::Patron->new({
1533
        firstname =>  'fn',
1534
        surname => 'dn',
1535
        categorycode => $patron_category->{categorycode},
1536
        branchcode => $branch,
1537
    })->store->borrowernumber;
1538
1539
    my $borrower = Koha::Patrons->find( $borrowernumber )->unblessed;
1540
1541
    my $issue = AddIssue( $borrower, $item->barcode, undef, undef, undef, undef, { onsite_checkout => 1 } );
1542
    my ( $renewed, $error ) = CanBookBeRenewed( $borrowernumber, $item->itemnumber );
1543
    is( $renewed, 0, 'CanBookBeRenewed should not allow to renew on-site checkout' );
1544
    is( $error, 'onsite_checkout', 'A correct error code should be returned by CanBookBeRenewed for on-site checkout' );
1545
}
1546
1547
{
1517
{
1548
    my $library = $builder->build({ source => 'Branch' });
1518
    my $library = $builder->build({ source => 'Branch' });
1549
1519
(-)a/t/db_dependent/OnSiteCheckouts.t (-1 / +145 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
# Copyright 2020 Hypernova Oy
4
#
5
# This file is part of Koha
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
use Modern::Perl;
21
22
use Test::More tests => 1;
23
24
use C4::Circulation;
25
use Koha::Database;
26
27
use t::lib::Mocks;
28
use t::lib::TestBuilder;
29
30
my $schema  = Koha::Database->new->schema;
31
my $builder = t::lib::TestBuilder->new;
32
33
subtest 'test renewals' => sub {
34
    plan tests => 7;
35
    
36
    $schema->storage->txn_begin;
37
    
38
    t::lib::Mocks::mock_preference( 'OnSiteCheckouts', 1 );
39
    t::lib::Mocks::mock_preference( 'SwitchOnSiteCheckouts', 0 );
40
41
    Koha::CirculationRules->search->delete;
42
    Koha::CirculationRules->set_rule(
43
        {
44
            categorycode => undef,
45
            branchcode   => undef,
46
            itemtype     => undef,
47
            rule_name    => 'onsite_renewalsallowed',
48
            rule_value   => '0',
49
        }
50
    );
51
52
    my $librarian = mock_librarian_env();
53
    my $test_data = build_test_data();
54
    my $patron    = $test_data->{patron};
55
    my $item      = $test_data->{item};
56
    my $library   = $test_data->{library};
57
58
    my $checkout = C4::Circulation::AddIssue(
59
        $patron->unblessed, $item->barcode,
60
        undef, undef, undef, undef, { onsite_checkout => 1 }
61
    );
62
63
    is( $checkout->onsite_checkout, 1, 'Created an on-site checkout' );
64
    my ( $can_renew, $error ) = CanBookBeRenewed(
65
        $patron->borrowernumber, $item->itemnumber
66
    );
67
    is ( $can_renew, 0, 'Checkout cannot be renewed...' );
68
    is ( $error, 'too_many', '..because onsite_renewalsallowed = 0' );
69
70
    Koha::CirculationRules->set_rule(
71
        {
72
            categorycode => undef,
73
            branchcode   => undef,
74
            itemtype     => undef,
75
            rule_name    => 'onsite_renewalsallowed',
76
            rule_value   => '1',
77
        }
78
    );
79
80
    ( $can_renew, $error ) = CanBookBeRenewed(
81
        $patron->borrowernumber, $item->itemnumber
82
    );
83
    is ( $can_renew, 1, 'After onsite_renewalsallowed = 1, we can now renew' );
84
85
    ok ( AddRenewal( $patron->id, $item->id, $library->id ), 'Renewal success' );
86
87
    ( $can_renew, $error ) = CanBookBeRenewed(
88
        $patron->borrowernumber, $item->itemnumber
89
    );
90
    is ( $can_renew, 0, 'Now, checkout cannot be renewed...' );
91
    is ( $error, 'too_many', '..because we have exceeded max renewals' );
92
93
    $schema->storage->txn_rollback;
94
};
95
96
sub build_test_data {
97
    my $library = $builder->build_object({
98
        class => 'Koha::Libraries',
99
    });
100
        
101
    my $patron = $builder->build_object({
102
        class => 'Koha::Patrons'
103
    });
104
    
105
    my $itemtype = $builder->build_object({
106
        class => 'Koha::ItemTypes',
107
        value  => {
108
            notforloan          => undef,
109
            rentalcharge        => 0,
110
            rentalcharge_daily => 0,
111
            defaultreplacecost  => undef,
112
            processfee          => undef
113
        }
114
    });
115
    
116
    my $biblio = $builder->build_sample_biblio();
117
    my $item = $builder->build_sample_item({
118
        biblionumber     => $biblio->biblionumber,
119
        library          => $library->branchcode,
120
        replacementprice => 12.00,
121
        itype            => $itemtype->itemtype
122
    });
123
    
124
    return {
125
        biblio   => $biblio,
126
        item     => $item,
127
        itemtype => $itemtype,
128
        library  => $library,
129
        patron   => $patron,
130
    };
131
}
132
133
sub mock_librarian_env {
134
    my $librarian = $builder->build_object({
135
        class => 'Koha::Patrons',
136
        value => {
137
            flags => 1
138
        }
139
    });
140
    t::lib::Mocks::mock_userenv({
141
        patron => $librarian,
142
        branchcode => $librarian->branchcode
143
    });
144
    return $librarian;
145
}

Return to bug 24101