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

(-)a/C4/Circulation.pm (-10 / +18 lines)
Lines 3099-3114 sub CanBookBeRenewed { Link Here
3099
                # FIXME: We are not checking whether the item we are renewing can fill the hold
3099
                # FIXME: We are not checking whether the item we are renewing can fill the hold
3100
3100
3101
                foreach my $other_item (@other_items) {
3101
                foreach my $other_item (@other_items) {
3102
                  next if defined $matched_items{$other_item->itemnumber};
3102
                    next if defined $matched_items{ $other_item->itemnumber };
3103
                  next if IsItemOnHoldAndFound( $other_item->itemnumber );
3103
                    next if IsItemOnHoldAndFound( $other_item->itemnumber );
3104
                  next unless IsAvailableForItemLevelRequest($other_item, $patron_with_reserve, undef);
3104
                    next unless IsAvailableForItemLevelRequest( $other_item, $patron_with_reserve, undef );
3105
                  next unless CanItemBeReserved($patron_with_reserve,$other_item,undef,{ignore_hold_counts=>1})->{status} eq 'OK';
3105
                    next
3106
                  # NOTE: At checkin we call 'CheckReserves' which checks hold 'policy'
3106
                        unless CanItemBeReserved(
3107
                  # CanItemBeReserved checks 'rules' and 'policies' which means
3107
                        $patron_with_reserve, $other_item, undef,
3108
                  # items will fill holds at checkin that are rejected here
3108
                        { ignore_hold_counts => 1 }
3109
                  $fillable = 1;
3109
                    )->{status} eq 'OK';
3110
                  $matched_items{$other_item->itemnumber} = 1;
3110
                    if ( C4::Context->preference('AllowRenewalIfOtherItemsAvailableLocation') eq 'holdbranch' ) {
3111
                  last;
3111
                        next unless $other_item->holdingbranch eq $possible_hold->branchcode;
3112
                    }
3113
3114
                    # NOTE: At checkin we call 'CheckReserves' which checks hold 'policy'
3115
                    # CanItemBeReserved checks 'rules' and 'policies' which means
3116
                    # items will fill holds at checkin that are rejected here
3117
                    $fillable = 1;
3118
                    $matched_items{ $other_item->itemnumber } = 1;
3119
                    last;
3112
                }
3120
                }
3113
                return ( 0, "on_reserve" ) unless $fillable;
3121
                return ( 0, "on_reserve" ) unless $fillable;
3114
            }
3122
            }
(-)a/installer/data/mysql/atomicupdate/bug_25193-add_AllowRenewalIfOtherItemsAvailableLocation_syspref.pl (+16 lines)
Line 0 Link Here
1
use Modern::Perl;
2
3
return {
4
    bug_number  => "25193",
5
    description => "Add syspref to control location for use of AllowRenewalIfOtherItemsAvailable",
6
    up          => sub {
7
        my ($args) = @_;
8
        my ( $dbh, $out ) = @$args{qw(dbh out)};
9
10
        $dbh->do(
11
            q{INSERT IGNORE INTO systempreferences (variable,value,options,explanation,type) VALUES ('AllowRenewalIfOtherItemsAvailableLocation', 'any', 'any|holdbranch', 'Specify where items must be available for fulfilling holds to allow a renewal.', 'Choice') }
12
        );
13
14
        say $out "Added system preference 'AllowRenewalIfOtherItemsAvailableLocation'";
15
    },
16
};
(-)a/installer/data/mysql/mandatory/sysprefs.sql (+1 lines)
Lines 43-48 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
43
('AllowPatronToSetFinesVisibilityForGuarantor',  '0', NULL, 'If enabled, the patron can set fines to be visible to their guarantor',  'YesNo'),
43
('AllowPatronToSetFinesVisibilityForGuarantor',  '0', NULL, 'If enabled, the patron can set fines to be visible to their guarantor',  'YesNo'),
44
('AllowPKIAuth','None','None|Common Name|emailAddress','Use the field from a client-side SSL certificate to look a user in the Koha database','Choice'),
44
('AllowPKIAuth','None','None|Common Name|emailAddress','Use the field from a client-side SSL certificate to look a user in the Koha database','Choice'),
45
('AllowRenewalIfOtherItemsAvailable','0',NULL,'If enabled, allow a patron to renew an item with unfilled holds if other available items can fill that hold.','YesNo'),
45
('AllowRenewalIfOtherItemsAvailable','0',NULL,'If enabled, allow a patron to renew an item with unfilled holds if other available items can fill that hold.','YesNo'),
46
('AllowRenewalIfOtherItemsAvailableLocation', 'any', 'any|holdbranch', 'Specify where items must be available for fulfilling holds to allow a renewal.', 'Choice'),
46
('AllowRenewalLimitOverride','0',NULL,'if ON, allows renewal limits to be overridden on the circulation screen','YesNo'),
47
('AllowRenewalLimitOverride','0',NULL,'if ON, allows renewal limits to be overridden on the circulation screen','YesNo'),
47
('AllowRenewalOnHoldOverride','0',NULL,'If ON, allow items on hold to be renewed with a specified due date','YesNo'),
48
('AllowRenewalOnHoldOverride','0',NULL,'If ON, allow items on hold to be renewed with a specified due date','YesNo'),
48
('AllowReturnToBranch','anywhere','anywhere|homebranch|holdingbranch|homeorholdingbranch','Where an item may be returned','Choice'),
49
('AllowReturnToBranch','anywhere','anywhere|homebranch|holdingbranch|homeorholdingbranch','Where an item may be returned','Choice'),
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref (-1 / +6 lines)
Lines 728-734 Circulation: Link Here
728
              choices:
728
              choices:
729
                  1: Allow
729
                  1: Allow
730
                  0: "Don't allow"
730
                  0: "Don't allow"
731
            - a patron to renew an item with unfilled holds if other available items can fill that hold.
731
            - a patron to renew an item with unfilled holds if other available items
732
            - pref: AllowRenewalIfOtherItemsAvailableLocation
733
              choices:
734
                  any: "at any library"
735
                  holdbranch: "at the hold's pickup library"
736
            - can fill that hold.
732
        -
737
        -
733
            - pref: AllowHoldPolicyOverride
738
            - pref: AllowHoldPolicyOverride
734
              choices:
739
              choices:
(-)a/t/db_dependent/Circulation.t (-2 / +92 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 => 68;
21
use Test::More tests => 69;
22
use Test::Exception;
22
use Test::Exception;
23
use Test::MockModule;
23
use Test::MockModule;
24
use Test::Deep qw( cmp_deeply );
24
use Test::Deep qw( cmp_deeply );
Lines 2090-2095 subtest "AllowRenewalIfOtherItemsAvailable tests" => sub { Link Here
2090
    is( Koha::Account::Lines->search({ issue_id => $issue->id })->count, 1, 'UpdateFine should not create a new accountline when updating an existing fine');
2090
    is( Koha::Account::Lines->search({ issue_id => $issue->id })->count, 1, 'UpdateFine should not create a new accountline when updating an existing fine');
2091
}
2091
}
2092
2092
2093
subtest "AllowRenewalIfOtherItemsAvailableLocation tests" => sub {
2094
    plan tests => 3;
2095
2096
    $dbh->do('DELETE FROM issues');
2097
    $dbh->do('DELETE FROM items');
2098
    $dbh->do('DELETE FROM circulation_rules');
2099
    Koha::CirculationRules->set_rules(
2100
        {
2101
            categorycode => undef,
2102
            itemtype     => undef,
2103
            branchcode   => undef,
2104
            rules        => {
2105
                reservesallowed => 25,
2106
                issuelength     => 14,
2107
                lengthunit      => 'days',
2108
                renewalsallowed => 1,
2109
                renewalperiod   => 7,
2110
                norenewalbefore => undef,
2111
                auto_renew      => 0,
2112
                fine            => .10,
2113
                chargeperiod    => 1,
2114
                maxissueqty     => 20,
2115
                onshelfholds    => 1,
2116
            }
2117
        }
2118
    );
2119
    my $biblio = $builder->build_sample_biblio();
2120
2121
    my $item_1 = $builder->build_sample_item(
2122
        {
2123
            biblionumber => $biblio->biblionumber,
2124
            library      => $library2->{branchcode},
2125
            itype        => $itemtype,
2126
        }
2127
    );
2128
2129
    # add second item with different branchcode
2130
    my $item_2 = $builder->build_sample_item(
2131
        {
2132
            biblionumber => $biblio->biblionumber,
2133
            library      => $library->{branchcode},
2134
            itype        => $itemtype,
2135
        }
2136
    );
2137
2138
    my $borrower1 = Koha::Patron->new(
2139
        {
2140
            firstname    => 'Kyle',
2141
            surname      => 'Hall',
2142
            categorycode => $patron_category->{categorycode},
2143
            branchcode   => $library2->{branchcode},
2144
        }
2145
    )->store;
2146
    my $borrowernumber1 = $borrower1->id;
2147
    my $borrower2 = Koha::Patron->new(
2148
        {
2149
            firstname    => 'Chelsea',
2150
            surname      => 'Hall',
2151
            categorycode => $patron_category->{categorycode},
2152
            branchcode   => $library2->{branchcode},
2153
        }
2154
    )->store;
2155
    my $borrowernumber2 = $borrower2->id;
2156
2157
    my $issue = AddIssue( $borrower1, $item_1->barcode );
2158
2159
    # place bib-level reserve
2160
    AddReserve(
2161
        {
2162
            branchcode     => $library2->{branchcode},
2163
            borrowernumber => $borrowernumber2,
2164
            biblionumber   => $biblio->biblionumber,
2165
            priority       => 1,
2166
        }
2167
    );
2168
2169
    t::lib::Mocks::mock_preference( 'AllowRenewalIfOtherItemsAvailable',         1 );
2170
    t::lib::Mocks::mock_preference( 'AllowRenewalIfOtherItemsAvailableLocation', 'any' );
2171
    my ( $renewokay, $error ) = CanBookBeRenewed( $borrower1, $issue );
2172
    is( $renewokay, 1, 'Renewal allowed if items available at any branch' );
2173
2174
    t::lib::Mocks::mock_preference( 'AllowRenewalIfOtherItemsAvailableLocation', 'holdbranch' );
2175
    ( $renewokay, $error ) = CanBookBeRenewed( $borrower1, $issue );
2176
    is( $renewokay, 0, 'Renewal not allowed as available item is at a different branch' );
2177
2178
    # adjust 2nd item to have same branchcode
2179
    $item_2->update( { homebranch => $library2->{branchcode}, holdingbranch => $library2->{branchcode} } )->store;
2180
    ( $renewokay, $error ) = CanBookBeRenewed( $borrower1, $issue );
2181
    is( $renewokay, 1, 'Renewal allowed if items available at hold branch' );
2182
};
2183
2093
subtest 'CanBookBeIssued & AllowReturnToBranch' => sub {
2184
subtest 'CanBookBeIssued & AllowReturnToBranch' => sub {
2094
    plan tests => 24;
2185
    plan tests => 24;
2095
2186
2096
- 

Return to bug 25193