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

(-)a/C4/Circulation.pm (+6 lines)
Lines 2784-2789 sub CanBookBeRenewed { Link Here
2784
        }
2784
        }
2785
        else {
2785
        else {
2786
2786
2787
2788
2787
            # Get all other items that could possibly fill reserves
2789
            # Get all other items that could possibly fill reserves
2788
            my @itemnumbers = $schema->resultset('Item')->search(
2790
            my @itemnumbers = $schema->resultset('Item')->search(
2789
                {
2791
                {
Lines 2822-2827 sub CanBookBeRenewed { Link Here
2822
                    my $patron = $patrons{$borrowernumber} //= Koha::Patrons->find( $borrowernumber );
2824
                    my $patron = $patrons{$borrowernumber} //= Koha::Patrons->find( $borrowernumber );
2823
                    next unless IsAvailableForItemLevelRequest($item, $patron);
2825
                    next unless IsAvailableForItemLevelRequest($item, $patron);
2824
                    next unless CanItemBeReserved($borrowernumber,$itemnumber);
2826
                    next unless CanItemBeReserved($borrowernumber,$itemnumber);
2827
                    if ( C4::Context->preference('AllowRenewalIfOtherItemsAvailableLocation') eq 'holdbranch' ){
2828
                        my $res = Koha::Holds->search({ biblionumber => $item->biblionumber, borrowernumber => $patron->borrowernumber })->next;
2829
                        next unless $item->holdingbranch eq $res->branchcode;
2830
                    }
2825
2831
2826
                    push @reservable, $itemnumber;
2832
                    push @reservable, $itemnumber;
2827
                    if (@reservable >= @borrowernumbers) {
2833
                    if (@reservable >= @borrowernumbers) {
(-)a/installer/data/mysql/atomicupdate/bug_25193-add_AllowRenewalIfOtherItemsAvailableLocation_syspref.perl (+6 lines)
Line 0 Link Here
1
$DBversion = 'XXX';
2
if( CheckVersion( $DBversion ) ) {
3
    $dbh->do(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') });
4
5
    NewVersion( $DBversion, 25193, "AllowRenewalIfOtherItemsAvailableLocation");
6
}
(-)a/installer/data/mysql/sysprefs.sql (+1 lines)
Lines 41-46 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
41
('AllowPKIAuth','None','None|Common Name|emailAddress','Use the field from a client-side SSL certificate to look a user in the Koha database','Choice'),
41
('AllowPKIAuth','None','None|Common Name|emailAddress','Use the field from a client-side SSL certificate to look a user in the Koha database','Choice'),
42
('AllowPurchaseSuggestionBranchChoice','0','1','Allow user to choose branch when making a purchase suggestion','YesNo'),
42
('AllowPurchaseSuggestionBranchChoice','0','1','Allow user to choose branch when making a purchase suggestion','YesNo'),
43
('AllowRenewalIfOtherItemsAvailable','0',NULL,'If enabled, allow a patron to renew an item with unfilled holds if other available items can fill that hold.','YesNo'),
43
('AllowRenewalIfOtherItemsAvailable','0',NULL,'If enabled, allow a patron to renew an item with unfilled holds if other available items can fill that hold.','YesNo'),
44
('AllowRenewalIfOtherItemsAvailableLocation', 'any', 'any|holdbranch', 'Specify where items must be available for fulfilling holds to allow a renewal.', 'Choice'),
44
('AllowRenewalLimitOverride','0',NULL,'if ON, allows renewal limits to be overridden on the circulation screen','YesNo'),
45
('AllowRenewalLimitOverride','0',NULL,'if ON, allows renewal limits to be overridden on the circulation screen','YesNo'),
45
('AllowRenewalOnHoldOverride','0',NULL,'If ON, allow items on hold to be renewed with a specified due date','YesNo'),
46
('AllowRenewalOnHoldOverride','0',NULL,'If ON, allow items on hold to be renewed with a specified due date','YesNo'),
46
('AllowReturnToBranch','anywhere','anywhere|homebranch|holdingbranch|homeorholdingbranch','Where an item may be returned','Choice'),
47
('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 654-660 Circulation: Link Here
654
              choices:
654
              choices:
655
                  yes: Allow
655
                  yes: Allow
656
                  no: "Don't allow"
656
                  no: "Don't allow"
657
            - a patron to renew an item with unfilled holds if other available items can fill that hold.
657
            - a patron to renew an item with unfilled holds if other available items
658
            - pref: AllowRenewalIfOtherItemsAvailableLocation
659
              choices:
660
                  any: "at any library"
661
                  holdbranch: "at the hold's pickup library"
662
            - can fill that hold.
658
        -
663
        -
659
            - pref: AllowHoldPolicyOverride
664
            - pref: AllowHoldPolicyOverride
660
              choices:
665
              choices:
(-)a/t/db_dependent/Circulation.t (-2 / +82 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 => 48;
21
use Test::More tests => 49;
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 1578-1583 subtest "AllowRenewalIfOtherItemsAvailable tests" => sub { Link Here
1578
    is( Koha::Account::Lines->search({ issue_id => $issue->id })->count, 1, 'UpdateFine should not create a new accountline when updating an existing fine');
1578
    is( Koha::Account::Lines->search({ issue_id => $issue->id })->count, 1, 'UpdateFine should not create a new accountline when updating an existing fine');
1579
}
1579
}
1580
1580
1581
subtest "AllowRenewalIfOtherItemsAvailableLocation tests" => sub {
1582
    plan tests => 3;
1583
1584
    $dbh->do('DELETE FROM issues');
1585
    $dbh->do('DELETE FROM items');
1586
    $dbh->do('DELETE FROM circulation_rules');
1587
    Koha::CirculationRules->set_rules(
1588
        {
1589
            categorycode => undef,
1590
            itemtype     => undef,
1591
            branchcode   => undef,
1592
            rules        => {
1593
                reservesallowed => 25,
1594
                issuelength     => 14,
1595
                lengthunit      => 'days',
1596
                renewalsallowed => 1,
1597
                renewalperiod   => 7,
1598
                norenewalbefore => undef,
1599
                auto_renew      => 0,
1600
                fine            => .10,
1601
                chargeperiod    => 1,
1602
                maxissueqty     => 20,
1603
                onshelfholds    => 1,
1604
            }
1605
        }
1606
    );
1607
    my $biblio = $builder->build_sample_biblio();
1608
1609
    my $item_1 = $builder->build_sample_item({
1610
        biblionumber     => $biblio->biblionumber,
1611
        library          => $library2->{branchcode},
1612
        itype            => $itemtype,
1613
    });
1614
    # add second item with different branchcode
1615
    my $item_2 = $builder->build_sample_item({
1616
        biblionumber     => $biblio->biblionumber,
1617
        library          => $library->{branchcode},
1618
        itype            => $itemtype,
1619
    });
1620
1621
    my $borrowernumber1 = Koha::Patron->new({
1622
        firstname    => 'Kyle',
1623
        surname      => 'Hall',
1624
        categorycode => $patron_category->{categorycode},
1625
        branchcode   => $library2->{branchcode},
1626
    })->store->borrowernumber;
1627
    my $borrowernumber2 = Koha::Patron->new({
1628
        firstname    => 'Chelsea',
1629
        surname      => 'Hall',
1630
        categorycode => $patron_category->{categorycode},
1631
        branchcode   => $library2->{branchcode},
1632
    })->store->borrowernumber;
1633
1634
    my $borrower1 = Koha::Patrons->find( $borrowernumber1 )->unblessed;
1635
    my $borrower2 = Koha::Patrons->find( $borrowernumber2 )->unblessed;
1636
1637
    my $issue = AddIssue( $borrower1, $item_1->barcode );
1638
1639
    # place bib-level reserve
1640
    AddReserve({
1641
        branchcode     => $library2->{branchcode},
1642
        borrowernumber => $borrowernumber2,
1643
        biblionumber   => $biblio->biblionumber,
1644
        priority       => 1,
1645
    });
1646
1647
    t::lib::Mocks::mock_preference( 'AllowRenewalIfOtherItemsAvailable', 1 );
1648
    t::lib::Mocks::mock_preference( 'AllowRenewalIfOtherItemsAvailableLocation', 'any' );
1649
    my ( $renewokay, $error ) = CanBookBeRenewed( $borrowernumber1, $item_1->itemnumber );
1650
    is( $renewokay, 1, 'Renewal allowed if items available at any branch' );
1651
1652
    t::lib::Mocks::mock_preference( 'AllowRenewalIfOtherItemsAvailableLocation', 'holdbranch' );
1653
    ( $renewokay, $error ) = CanBookBeRenewed( $borrowernumber1, $item_1->itemnumber );
1654
    is( $renewokay, 0, 'Renewal not allowed as available item is at a different branch' );
1655
1656
    # adjust 2nd item to have same branchcode
1657
    $item_2->update({ homebranch => $library2->{branchcode}, holdingbranch => $library2->{branchcode} })->store;
1658
    ( $renewokay, $error ) = CanBookBeRenewed( $borrowernumber1, $item_1->itemnumber );
1659
    is( $renewokay, 1, 'Renewal allowed if items available at hold branch' );
1660
};
1661
1581
subtest 'CanBookBeIssued & AllowReturnToBranch' => sub {
1662
subtest 'CanBookBeIssued & AllowReturnToBranch' => sub {
1582
    plan tests => 24;
1663
    plan tests => 24;
1583
1664
1584
- 

Return to bug 25193