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

(-)a/C4/Circulation.pm (+6 lines)
Lines 2892-2897 sub CanBookBeRenewed { Link Here
2892
        }
2892
        }
2893
        else {
2893
        else {
2894
2894
2895
2896
2895
            # Get all other items that could possibly fill reserves
2897
            # Get all other items that could possibly fill reserves
2896
            my @itemnumbers = $schema->resultset('Item')->search(
2898
            my @itemnumbers = $schema->resultset('Item')->search(
2897
                {
2899
                {
Lines 2930-2935 sub CanBookBeRenewed { Link Here
2930
                    my $patron = $patrons{$borrowernumber} //= Koha::Patrons->find( $borrowernumber );
2932
                    my $patron = $patrons{$borrowernumber} //= Koha::Patrons->find( $borrowernumber );
2931
                    next unless IsAvailableForItemLevelRequest($item, $patron);
2933
                    next unless IsAvailableForItemLevelRequest($item, $patron);
2932
                    next unless CanItemBeReserved($borrowernumber,$itemnumber);
2934
                    next unless CanItemBeReserved($borrowernumber,$itemnumber);
2935
                    if ( C4::Context->preference('AllowRenewalIfOtherItemsAvailableLocation') eq 'holdbranch' ){
2936
                        my $res = Koha::Holds->search({ biblionumber => $item->biblionumber, borrowernumber => $patron->borrowernumber })->next;
2937
                        next unless $item->holdingbranch eq $res->branchcode;
2938
                    }
2933
2939
2934
                    push @reservable, $itemnumber;
2940
                    push @reservable, $itemnumber;
2935
                    if (@reservable >= @borrowernumbers) {
2941
                    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 646-652 Circulation: Link Here
646
              choices:
646
              choices:
647
                  yes: Allow
647
                  yes: Allow
648
                  no: "Don't allow"
648
                  no: "Don't allow"
649
            - a patron to renew an item with unfilled holds if other available items can fill that hold.
649
            - a patron to renew an item with unfilled holds if other available items
650
            - pref: AllowRenewalIfOtherItemsAvailableLocation
651
              choices:
652
                  any: "at any branch"
653
                  holdbranch: "at the hold's pickup branch"
654
            - can fill that hold.
650
        -
655
        -
651
            - pref: AllowHoldPolicyOverride
656
            - pref: AllowHoldPolicyOverride
652
              choices:
657
              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 => 49;
21
use Test::More tests => 50;
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 1587-1592 subtest "AllowRenewalIfOtherItemsAvailable tests" => sub { Link Here
1587
    is( Koha::Account::Lines->search({ issue_id => $issue->id })->count, 1, 'UpdateFine should not create a new accountline when updating an existing fine');
1587
    is( Koha::Account::Lines->search({ issue_id => $issue->id })->count, 1, 'UpdateFine should not create a new accountline when updating an existing fine');
1588
}
1588
}
1589
1589
1590
subtest "AllowRenewalIfOtherItemsAvailableLocation tests" => sub {
1591
    plan tests => 3;
1592
1593
    $dbh->do('DELETE FROM issues');
1594
    $dbh->do('DELETE FROM items');
1595
    $dbh->do('DELETE FROM circulation_rules');
1596
    Koha::CirculationRules->set_rules(
1597
        {
1598
            categorycode => undef,
1599
            itemtype     => undef,
1600
            branchcode   => undef,
1601
            rules        => {
1602
                reservesallowed => 25,
1603
                issuelength     => 14,
1604
                lengthunit      => 'days',
1605
                renewalsallowed => 1,
1606
                renewalperiod   => 7,
1607
                norenewalbefore => undef,
1608
                auto_renew      => 0,
1609
                fine            => .10,
1610
                chargeperiod    => 1,
1611
                maxissueqty     => 20,
1612
                onshelfholds    => 1,
1613
            }
1614
        }
1615
    );
1616
    my $biblio = $builder->build_sample_biblio();
1617
1618
    my $item_1 = $builder->build_sample_item({
1619
        biblionumber     => $biblio->biblionumber,
1620
        library          => $library2->{branchcode},
1621
        itype            => $itemtype,
1622
    });
1623
    # add second item with different branchcode
1624
    my $item_2 = $builder->build_sample_item({
1625
        biblionumber     => $biblio->biblionumber,
1626
        library          => $library->{branchcode},
1627
        itype            => $itemtype,
1628
    });
1629
1630
    my $borrowernumber1 = Koha::Patron->new({
1631
        firstname    => 'Kyle',
1632
        surname      => 'Hall',
1633
        categorycode => $patron_category->{categorycode},
1634
        branchcode   => $library2->{branchcode},
1635
    })->store->borrowernumber;
1636
    my $borrowernumber2 = Koha::Patron->new({
1637
        firstname    => 'Chelsea',
1638
        surname      => 'Hall',
1639
        categorycode => $patron_category->{categorycode},
1640
        branchcode   => $library2->{branchcode},
1641
    })->store->borrowernumber;
1642
1643
    my $borrower1 = Koha::Patrons->find( $borrowernumber1 )->unblessed;
1644
    my $borrower2 = Koha::Patrons->find( $borrowernumber2 )->unblessed;
1645
1646
    my $issue = AddIssue( $borrower1, $item_1->barcode );
1647
1648
    # place bib-level reserve
1649
    AddReserve({
1650
        branchcode     => $library2->{branchcode},
1651
        borrowernumber => $borrowernumber2,
1652
        biblionumber   => $biblio->biblionumber,
1653
        priority       => 1,
1654
    });
1655
1656
    t::lib::Mocks::mock_preference( 'AllowRenewalIfOtherItemsAvailable', 1 );
1657
    t::lib::Mocks::mock_preference( 'AllowRenewalIfOtherItemsAvailableLocation', 'any' );
1658
    my ( $renewokay, $error ) = CanBookBeRenewed( $borrowernumber1, $item_1->itemnumber );
1659
    is( $renewokay, 1, 'Renewal allowed if items available at any branch' );
1660
1661
    t::lib::Mocks::mock_preference( 'AllowRenewalIfOtherItemsAvailableLocation', 'holdbranch' );
1662
    ( $renewokay, $error ) = CanBookBeRenewed( $borrowernumber1, $item_1->itemnumber );
1663
    is( $renewokay, 0, 'Renewal not allowed as available item is at a different branch' );
1664
1665
    # adjust 2nd item to have same branchcode
1666
    $item_2->update({ homebranch => $library2->{branchcode}, holdingbranch => $library2->{branchcode} })->store;
1667
    ( $renewokay, $error ) = CanBookBeRenewed( $borrowernumber1, $item_1->itemnumber );
1668
    is( $renewokay, 1, 'Renewal allowed if items available at hold branch' );
1669
};
1670
1590
subtest 'CanBookBeIssued & AllowReturnToBranch' => sub {
1671
subtest 'CanBookBeIssued & AllowReturnToBranch' => sub {
1591
    plan tests => 24;
1672
    plan tests => 24;
1592
1673
1593
- 

Return to bug 25193