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

(-)a/C4/Circulation.pm (+6 lines)
Lines 2851-2856 sub CanBookBeRenewed { Link Here
2851
        }
2851
        }
2852
        else {
2852
        else {
2853
2853
2854
2855
2854
            # Get all other items that could possibly fill reserves
2856
            # Get all other items that could possibly fill reserves
2855
            my @itemnumbers = $schema->resultset('Item')->search(
2857
            my @itemnumbers = $schema->resultset('Item')->search(
2856
                {
2858
                {
Lines 2889-2894 sub CanBookBeRenewed { Link Here
2889
                    my $patron = $patrons{$borrowernumber} //= Koha::Patrons->find( $borrowernumber );
2891
                    my $patron = $patrons{$borrowernumber} //= Koha::Patrons->find( $borrowernumber );
2890
                    next unless IsAvailableForItemLevelRequest($item, $patron);
2892
                    next unless IsAvailableForItemLevelRequest($item, $patron);
2891
                    next unless CanItemBeReserved($borrowernumber,$itemnumber);
2893
                    next unless CanItemBeReserved($borrowernumber,$itemnumber);
2894
                    if ( C4::Context->preference('AllowRenewalIfOtherItemsAvailableLocation') eq 'holdbranch' ){
2895
                        my $res = Koha::Holds->search({ biblionumber => $item->biblionumber, borrowernumber => $patron->borrowernumber })->next;
2896
                        next unless $item->holdingbranch eq $res->branchcode;
2897
                    }
2892
2898
2893
                    push @reservable, $itemnumber;
2899
                    push @reservable, $itemnumber;
2894
                    if (@reservable >= @borrowernumbers) {
2900
                    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 40-45 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
40
('AllowPKIAuth','None','None|Common Name|emailAddress','Use the field from a client-side SSL certificate to look a user in the Koha database','Choice'),
40
('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
('AllowPurchaseSuggestionBranchChoice','0','1','Allow user to choose branch when making a purchase suggestion','YesNo'),
41
('AllowPurchaseSuggestionBranchChoice','0','1','Allow user to choose branch when making a purchase suggestion','YesNo'),
42
('AllowRenewalIfOtherItemsAvailable','0',NULL,'If enabled, allow a patron to renew an item with unfilled holds if other available items can fill that hold.','YesNo'),
42
('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
('AllowRenewalIfOtherItemsAvailableLocation', 'any', 'any|holdbranch', 'Specify where items must be available for fulfilling holds to allow a renewal.', 'Choice'),
43
('AllowRenewalLimitOverride','0',NULL,'if ON, allows renewal limits to be overridden on the circulation screen','YesNo'),
44
('AllowRenewalLimitOverride','0',NULL,'if ON, allows renewal limits to be overridden on the circulation screen','YesNo'),
44
('AllowRenewalOnHoldOverride','0',NULL,'If ON, allow items on hold to be renewed with a specified due date','YesNo'),
45
('AllowRenewalOnHoldOverride','0',NULL,'If ON, allow items on hold to be renewed with a specified due date','YesNo'),
45
('AllowReturnToBranch','anywhere','anywhere|homebranch|holdingbranch|homeorholdingbranch','Where an item may be returned','Choice'),
46
('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 628-634 Circulation: Link Here
628
              choices:
628
              choices:
629
                  yes: Allow
629
                  yes: Allow
630
                  no: "Don't allow"
630
                  no: "Don't allow"
631
            - a patron to renew an item with unfilled holds if other available items can fill that hold.
631
            - a patron to renew an item with unfilled holds if other available items
632
            - pref: AllowRenewalIfOtherItemsAvailableLocation
633
              choices:
634
                  any: "at any branch"
635
                  holdbranch: "at the hold's pickup branch"
636
            - can fill that hold.
632
        -
637
        -
633
            - pref: AllowHoldPolicyOverride
638
            - pref: AllowHoldPolicyOverride
634
              choices:
639
              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::MockModule;
22
use Test::MockModule;
23
use Test::Deep qw( cmp_deeply );
23
use Test::Deep qw( cmp_deeply );
24
24
Lines 1583-1588 subtest "AllowRenewalIfOtherItemsAvailable tests" => sub { Link Here
1583
    is( Koha::Account::Lines->search({ issue_id => $issue->id })->count, 1, 'UpdateFine should not create a new accountline when updating an existing fine');
1583
    is( Koha::Account::Lines->search({ issue_id => $issue->id })->count, 1, 'UpdateFine should not create a new accountline when updating an existing fine');
1584
}
1584
}
1585
1585
1586
subtest "AllowRenewalIfOtherItemsAvailableLocation tests" => sub {
1587
    plan tests => 3;
1588
1589
    $dbh->do('DELETE FROM issues');
1590
    $dbh->do('DELETE FROM items');
1591
    $dbh->do('DELETE FROM circulation_rules');
1592
    Koha::CirculationRules->set_rules(
1593
        {
1594
            categorycode => undef,
1595
            itemtype     => undef,
1596
            branchcode   => undef,
1597
            rules        => {
1598
                reservesallowed => 25,
1599
                issuelength     => 14,
1600
                lengthunit      => 'days',
1601
                renewalsallowed => 1,
1602
                renewalperiod   => 7,
1603
                norenewalbefore => undef,
1604
                auto_renew      => 0,
1605
                fine            => .10,
1606
                chargeperiod    => 1,
1607
                maxissueqty     => 20,
1608
                onshelfholds    => 1,
1609
            }
1610
        }
1611
    );
1612
    my $biblio = $builder->build_sample_biblio();
1613
1614
    my $item_1 = $builder->build_sample_item({
1615
        biblionumber     => $biblio->biblionumber,
1616
        library          => $library2->{branchcode},
1617
        itype            => $itemtype,
1618
    });
1619
    # add second item with different branchcode
1620
    my $item_2 = $builder->build_sample_item({
1621
        biblionumber     => $biblio->biblionumber,
1622
        library          => $library->{branchcode},
1623
        itype            => $itemtype,
1624
    });
1625
1626
    my $borrowernumber1 = Koha::Patron->new({
1627
        firstname    => 'Kyle',
1628
        surname      => 'Hall',
1629
        categorycode => $patron_category->{categorycode},
1630
        branchcode   => $library2->{branchcode},
1631
    })->store->borrowernumber;
1632
    my $borrowernumber2 = Koha::Patron->new({
1633
        firstname    => 'Chelsea',
1634
        surname      => 'Hall',
1635
        categorycode => $patron_category->{categorycode},
1636
        branchcode   => $library2->{branchcode},
1637
    })->store->borrowernumber;
1638
1639
    my $borrower1 = Koha::Patrons->find( $borrowernumber1 )->unblessed;
1640
    my $borrower2 = Koha::Patrons->find( $borrowernumber2 )->unblessed;
1641
1642
    my $issue = AddIssue( $borrower1, $item_1->barcode );
1643
1644
    # place bib-level reserve
1645
    AddReserve({
1646
        branchcode     => $library2->{branchcode},
1647
        borrowernumber => $borrowernumber2,
1648
        biblionumber   => $biblio->biblionumber,
1649
        priority       => 1,
1650
    });
1651
1652
    t::lib::Mocks::mock_preference( 'AllowRenewalIfOtherItemsAvailable', 1 );
1653
    t::lib::Mocks::mock_preference( 'AllowRenewalIfOtherItemsAvailableLocation', 'any' );
1654
    my ( $renewokay, $error ) = CanBookBeRenewed( $borrowernumber1, $item_1->itemnumber );
1655
    is( $renewokay, 1, 'Renewal allowed if items available at any branch' );
1656
1657
    t::lib::Mocks::mock_preference( 'AllowRenewalIfOtherItemsAvailableLocation', 'holdbranch' );
1658
    ( $renewokay, $error ) = CanBookBeRenewed( $borrowernumber1, $item_1->itemnumber );
1659
    is( $renewokay, 0, 'Renewal not allowed as available item is at a different branch' );
1660
1661
    # adjust 2nd item to have same branchcode
1662
    $item_2->update({ homebranch => $library2->{branchcode}, holdingbranch => $library2->{branchcode} })->store;
1663
    ( $renewokay, $error ) = CanBookBeRenewed( $borrowernumber1, $item_1->itemnumber );
1664
    is( $renewokay, 1, 'Renewal allowed if items available at hold branch' );
1665
};
1666
1586
subtest 'CanBookBeIssued & AllowReturnToBranch' => sub {
1667
subtest 'CanBookBeIssued & AllowReturnToBranch' => sub {
1587
    plan tests => 24;
1668
    plan tests => 24;
1588
1669
1589
- 

Return to bug 25193