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

(-)a/C4/Circulation.pm (-10 / +18 lines)
Lines 3110-3125 sub CanBookBeRenewed { Link Here
3110
                my $patron_with_reserve = Koha::Patrons->find($possible_hold->{borrowernumber});
3110
                my $patron_with_reserve = Koha::Patrons->find($possible_hold->{borrowernumber});
3111
3111
3112
                foreach my $other_item (@other_items) {
3112
                foreach my $other_item (@other_items) {
3113
                  next if defined $matched_items{$other_item->itemnumber};
3113
                    next if defined $matched_items{ $other_item->itemnumber };
3114
                  next if $other_item->holds->filter_by_found->count;
3114
                    next if $other_item->holds->filter_by_found->count;
3115
                  next unless IsAvailableForItemLevelRequest($other_item, $patron_with_reserve, undef);
3115
                    next unless IsAvailableForItemLevelRequest( $other_item, $patron_with_reserve, undef );
3116
                  next unless CanItemBeReserved($patron_with_reserve,$other_item,undef,{ignore_hold_counts=>1})->{status} eq 'OK';
3116
                    next
3117
                  # NOTE: At checkin we call 'CheckReserves' which checks hold 'policy'
3117
                        unless CanItemBeReserved(
3118
                  # CanItemBeReserved checks 'rules' and 'policies' which means
3118
                        $patron_with_reserve, $other_item, undef,
3119
                  # items will fill holds at checkin that are rejected here
3119
                        { ignore_hold_counts => 1 }
3120
                  $fillable = 1;
3120
                    )->{status} eq 'OK';
3121
                  $matched_items{$other_item->itemnumber} = 1;
3121
                    if ( C4::Context->preference('AllowRenewalIfOtherItemsAvailableLocation') eq 'holdbranch' ) {
3122
                  last;
3122
                        next unless $other_item->holdingbranch eq $possible_hold->{branchcode};
3123
                    }
3124
3125
                    # NOTE: At checkin we call 'CheckReserves' which checks hold 'policy'
3126
                    # CanItemBeReserved checks 'rules' and 'policies' which means
3127
                    # items will fill holds at checkin that are rejected here
3128
                    $fillable = 1;
3129
                    $matched_items{ $other_item->itemnumber } = 1;
3130
                    last;
3123
                }
3131
                }
3124
                return ( 0, "on_reserve" ) unless $fillable;
3132
                return ( 0, "on_reserve" ) unless $fillable;
3125
            }
3133
            }
(-)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 45-50 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
45
('AllowPatronToSetFinesVisibilityForGuarantor',  '0', NULL, 'If enabled, the patron can set fines to be visible to their guarantor',  'YesNo'),
45
('AllowPatronToSetFinesVisibilityForGuarantor',  '0', NULL, 'If enabled, the patron can set fines to be visible to their guarantor',  'YesNo'),
46
('AllowPKIAuth','None','None|Common Name|emailAddress','Use the field from a client-side SSL certificate to look a user in the Koha database','Choice'),
46
('AllowPKIAuth','None','None|Common Name|emailAddress','Use the field from a client-side SSL certificate to look a user in the Koha database','Choice'),
47
('AllowRenewalIfOtherItemsAvailable','0',NULL,'If enabled, allow a patron to renew an item with unfilled holds if other available items can fill that hold.','YesNo'),
47
('AllowRenewalIfOtherItemsAvailable','0',NULL,'If enabled, allow a patron to renew an item with unfilled holds if other available items can fill that hold.','YesNo'),
48
('AllowRenewalIfOtherItemsAvailableLocation', 'any', 'any|holdbranch', 'Specify where items must be available for fulfilling holds to allow a renewal.', 'Choice'),
48
('AllowRenewalLimitOverride','0',NULL,'if ON, allows renewal limits to be overridden on the circulation screen','YesNo'),
49
('AllowRenewalLimitOverride','0',NULL,'if ON, allows renewal limits to be overridden on the circulation screen','YesNo'),
49
('AllowRenewalOnHoldOverride','0',NULL,'If ON, allow items on hold to be renewed with a specified due date','YesNo'),
50
('AllowRenewalOnHoldOverride','0',NULL,'If ON, allow items on hold to be renewed with a specified due date','YesNo'),
50
('AllowReturnToBranch','anywhere','anywhere|homebranch|holdingbranch|homeorholdingbranch','Where an item may be returned','Choice'),
51
('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 797-803 Circulation: Link Here
797
              choices:
797
              choices:
798
                  1: Allow
798
                  1: Allow
799
                  0: "Don't allow"
799
                  0: "Don't allow"
800
            - a patron to renew an item with unfilled holds if other available items can fill that hold.
800
            - a patron to renew an item with unfilled holds if other available items
801
            - pref: AllowRenewalIfOtherItemsAvailableLocation
802
              choices:
803
                  any: "at any library"
804
                  holdbranch: "at the hold's pickup library"
805
            - can fill that hold.
801
        -
806
        -
802
            - pref: AllowHoldPolicyOverride
807
            - pref: AllowHoldPolicyOverride
803
              choices:
808
              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 => 75;
21
use Test::More tests => 76;
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 2257-2262 subtest "AllowRenewalIfOtherItemsAvailable tests" => sub { Link Here
2257
    is( Koha::Account::Lines->search({ issue_id => $issue->id })->count, 1, 'UpdateFine should not create a new accountline when updating an existing fine');
2257
    is( Koha::Account::Lines->search({ issue_id => $issue->id })->count, 1, 'UpdateFine should not create a new accountline when updating an existing fine');
2258
}
2258
}
2259
2259
2260
subtest "AllowRenewalIfOtherItemsAvailableLocation tests" => sub {
2261
    plan tests => 3;
2262
2263
    $dbh->do('DELETE FROM issues');
2264
    $dbh->do('DELETE FROM items');
2265
    $dbh->do('DELETE FROM circulation_rules');
2266
    Koha::CirculationRules->set_rules(
2267
        {
2268
            categorycode => undef,
2269
            itemtype     => undef,
2270
            branchcode   => undef,
2271
            rules        => {
2272
                reservesallowed => 25,
2273
                issuelength     => 14,
2274
                lengthunit      => 'days',
2275
                renewalsallowed => 1,
2276
                renewalperiod   => 7,
2277
                norenewalbefore => undef,
2278
                auto_renew      => 0,
2279
                fine            => .10,
2280
                chargeperiod    => 1,
2281
                maxissueqty     => 20,
2282
                onshelfholds    => 1,
2283
            }
2284
        }
2285
    );
2286
    my $biblio = $builder->build_sample_biblio();
2287
2288
    my $item_1 = $builder->build_sample_item(
2289
        {
2290
            biblionumber => $biblio->biblionumber,
2291
            library      => $library2->{branchcode},
2292
            itype        => $itemtype,
2293
        }
2294
    );
2295
2296
    # add second item with different branchcode
2297
    my $item_2 = $builder->build_sample_item(
2298
        {
2299
            biblionumber => $biblio->biblionumber,
2300
            library      => $library->{branchcode},
2301
            itype        => $itemtype,
2302
        }
2303
    );
2304
2305
    my $borrower1 = Koha::Patron->new(
2306
        {
2307
            firstname    => 'Kyle',
2308
            surname      => 'Hall',
2309
            categorycode => $patron_category->{categorycode},
2310
            branchcode   => $library2->{branchcode},
2311
        }
2312
    )->store;
2313
    my $borrowernumber1 = $borrower1->id;
2314
    my $borrower2 = Koha::Patron->new(
2315
        {
2316
            firstname    => 'Chelsea',
2317
            surname      => 'Hall',
2318
            categorycode => $patron_category->{categorycode},
2319
            branchcode   => $library2->{branchcode},
2320
        }
2321
    )->store;
2322
    my $borrowernumber2 = $borrower2->id;
2323
2324
    my $issue = AddIssue( $borrower1, $item_1->barcode );
2325
2326
    # place bib-level reserve
2327
    AddReserve(
2328
        {
2329
            branchcode     => $library2->{branchcode},
2330
            borrowernumber => $borrowernumber2,
2331
            biblionumber   => $biblio->biblionumber,
2332
            priority       => 1,
2333
        }
2334
    );
2335
2336
    t::lib::Mocks::mock_preference( 'AllowRenewalIfOtherItemsAvailable',         1 );
2337
    t::lib::Mocks::mock_preference( 'AllowRenewalIfOtherItemsAvailableLocation', 'any' );
2338
    my ( $renewokay, $error ) = CanBookBeRenewed( $borrower1, $issue );
2339
    is( $renewokay, 1, 'Renewal allowed if items available at any branch' );
2340
2341
    t::lib::Mocks::mock_preference( 'AllowRenewalIfOtherItemsAvailableLocation', 'holdbranch' );
2342
    ( $renewokay, $error ) = CanBookBeRenewed( $borrower1, $issue );
2343
    is( $renewokay, 0, 'Renewal not allowed as available item is at a different branch' );
2344
2345
    # adjust 2nd item to have same branchcode
2346
    $item_2->update( { homebranch => $library2->{branchcode}, holdingbranch => $library2->{branchcode} } )->store;
2347
    ( $renewokay, $error ) = CanBookBeRenewed( $borrower1, $issue );
2348
    is( $renewokay, 1, 'Renewal allowed if items available at hold branch' );
2349
};
2350
2260
subtest 'CanBookBeIssued & AllowReturnToBranch' => sub {
2351
subtest 'CanBookBeIssued & AllowReturnToBranch' => sub {
2261
    plan tests => 24;
2352
    plan tests => 24;
2262
2353
2263
- 

Return to bug 25193