From 3af4fb7ebe4a8144503b3f9d269292ac93b66478 Mon Sep 17 00:00:00 2001 From: Aleisha Amohia Date: Mon, 20 Apr 2020 07:12:59 +0000 Subject: [PATCH] Bug 25193: Add AllowRenewalIfOtherItemsAvailableLocation syspref This syspref works in conjunction with AllowRenewalIfOtherItemsAvailable syspref. It has two options - allow renewal if other items are available to fill holds at any branch, or only at the hold's pickup branch. To test: 1) Apply patch, update database, restart services 2) Go to Administration -> system preferences. Search for AllowRenewalIfOtherItemsAvailable. Notice the two sysprefs exist in the same row. By default they should be set to "Don't allow" and "at any library". 3) Set up a biblio with two items. Have both items held at Branch A. 4) Check out Item A to Borrower A. 5) Place a biblio-level reserve for Borrower B with pickup branch at Branch A. 6) View Borrower A's checkouts. Confirm you cannot renew Item A ('On hold' message). 7) Edit Item B, set the current location to Branch B. The items should now have different locations. 8) Enable the AllowRenewalIfOtherItemsAvailable syspref. Leave the AllowRenewalIfOtherItemsAvailableLocation syspref set to "at any library". 9) View Borrower A's checkouts. Confirm you CAN renew Item A (because Item B can fill Borrower B's reserve). 10) Set the AllowRenewalIfOtherItemsAvailableLocation syspref to "at the hold's pickup library". Keep AllowRenewalIfOtherItemsAvailable syspref enabled. 11) View Borrower A's checkouts. Confirm you CANNOT renew Item A (because Item B cannot fill Borrower B's reserve due to being at a different branch). 12) Edit Item B, set the current location to Branch A. The items should have the same location now. 13) View Borrower A's checkouts. Confirm you CAN renew Item A. Sponsored-by: Chartered Accountants Australia & New Zealand Signed-off-by: David Nind Signed-off-by: David Nind Signed-off-by: Katrin Fischer --- C4/Circulation.pm | 6 ++ ...newalIfOtherItemsAvailableLocation_syspref.perl | 6 ++ installer/data/mysql/sysprefs.sql | 1 + .../en/modules/admin/preferences/circulation.pref | 7 +- t/db_dependent/Circulation.t | 83 +++++++++++++++++++++- 5 files changed, 101 insertions(+), 2 deletions(-) create mode 100644 installer/data/mysql/atomicupdate/bug_25193-add_AllowRenewalIfOtherItemsAvailableLocation_syspref.perl diff --git a/C4/Circulation.pm b/C4/Circulation.pm index 3571051e84..b248df4122 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -2784,6 +2784,8 @@ sub CanBookBeRenewed { } else { + + # Get all other items that could possibly fill reserves my @itemnumbers = $schema->resultset('Item')->search( { @@ -2822,6 +2824,10 @@ sub CanBookBeRenewed { my $patron = $patrons{$borrowernumber} //= Koha::Patrons->find( $borrowernumber ); next unless IsAvailableForItemLevelRequest($item, $patron); next unless CanItemBeReserved($borrowernumber,$itemnumber); + if ( C4::Context->preference('AllowRenewalIfOtherItemsAvailableLocation') eq 'holdbranch' ){ + my $res = Koha::Holds->search({ biblionumber => $item->biblionumber, borrowernumber => $patron->borrowernumber })->next; + next unless $item->holdingbranch eq $res->branchcode; + } push @reservable, $itemnumber; if (@reservable >= @borrowernumbers) { diff --git a/installer/data/mysql/atomicupdate/bug_25193-add_AllowRenewalIfOtherItemsAvailableLocation_syspref.perl b/installer/data/mysql/atomicupdate/bug_25193-add_AllowRenewalIfOtherItemsAvailableLocation_syspref.perl new file mode 100644 index 0000000000..a8eec9d456 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_25193-add_AllowRenewalIfOtherItemsAvailableLocation_syspref.perl @@ -0,0 +1,6 @@ +$DBversion = 'XXX'; +if( CheckVersion( $DBversion ) ) { + $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') }); + + NewVersion( $DBversion, 25193, "AllowRenewalIfOtherItemsAvailableLocation"); +} diff --git a/installer/data/mysql/sysprefs.sql b/installer/data/mysql/sysprefs.sql index 1df6a1fb53..6a5041b9c8 100644 --- a/installer/data/mysql/sysprefs.sql +++ b/installer/data/mysql/sysprefs.sql @@ -41,6 +41,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('AllowPKIAuth','None','None|Common Name|emailAddress','Use the field from a client-side SSL certificate to look a user in the Koha database','Choice'), ('AllowPurchaseSuggestionBranchChoice','0','1','Allow user to choose branch when making a purchase suggestion','YesNo'), ('AllowRenewalIfOtherItemsAvailable','0',NULL,'If enabled, allow a patron to renew an item with unfilled holds if other available items can fill that hold.','YesNo'), +('AllowRenewalIfOtherItemsAvailableLocation', 'any', 'any|holdbranch', 'Specify where items must be available for fulfilling holds to allow a renewal.', 'Choice'), ('AllowRenewalLimitOverride','0',NULL,'if ON, allows renewal limits to be overridden on the circulation screen','YesNo'), ('AllowRenewalOnHoldOverride','0',NULL,'If ON, allow items on hold to be renewed with a specified due date','YesNo'), ('AllowReturnToBranch','anywhere','anywhere|homebranch|holdingbranch|homeorholdingbranch','Where an item may be returned','Choice'), diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref index 9e6dbe3d4f..c72d4c2ac6 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref @@ -654,7 +654,12 @@ Circulation: choices: yes: Allow no: "Don't allow" - - a patron to renew an item with unfilled holds if other available items can fill that hold. + - a patron to renew an item with unfilled holds if other available items + - pref: AllowRenewalIfOtherItemsAvailableLocation + choices: + any: "at any library" + holdbranch: "at the hold's pickup library" + - can fill that hold. - - pref: AllowHoldPolicyOverride choices: diff --git a/t/db_dependent/Circulation.t b/t/db_dependent/Circulation.t index f26f2f3255..9c4c70ae33 100755 --- a/t/db_dependent/Circulation.t +++ b/t/db_dependent/Circulation.t @@ -18,7 +18,7 @@ use Modern::Perl; use utf8; -use Test::More tests => 48; +use Test::More tests => 49; use Test::Exception; use Test::MockModule; use Test::Deep qw( cmp_deeply ); @@ -1578,6 +1578,87 @@ subtest "AllowRenewalIfOtherItemsAvailable tests" => sub { is( Koha::Account::Lines->search({ issue_id => $issue->id })->count, 1, 'UpdateFine should not create a new accountline when updating an existing fine'); } +subtest "AllowRenewalIfOtherItemsAvailableLocation tests" => sub { + plan tests => 3; + + $dbh->do('DELETE FROM issues'); + $dbh->do('DELETE FROM items'); + $dbh->do('DELETE FROM circulation_rules'); + Koha::CirculationRules->set_rules( + { + categorycode => undef, + itemtype => undef, + branchcode => undef, + rules => { + reservesallowed => 25, + issuelength => 14, + lengthunit => 'days', + renewalsallowed => 1, + renewalperiod => 7, + norenewalbefore => undef, + auto_renew => 0, + fine => .10, + chargeperiod => 1, + maxissueqty => 20, + onshelfholds => 1, + } + } + ); + my $biblio = $builder->build_sample_biblio(); + + my $item_1 = $builder->build_sample_item({ + biblionumber => $biblio->biblionumber, + library => $library2->{branchcode}, + itype => $itemtype, + }); + # add second item with different branchcode + my $item_2 = $builder->build_sample_item({ + biblionumber => $biblio->biblionumber, + library => $library->{branchcode}, + itype => $itemtype, + }); + + my $borrowernumber1 = Koha::Patron->new({ + firstname => 'Kyle', + surname => 'Hall', + categorycode => $patron_category->{categorycode}, + branchcode => $library2->{branchcode}, + })->store->borrowernumber; + my $borrowernumber2 = Koha::Patron->new({ + firstname => 'Chelsea', + surname => 'Hall', + categorycode => $patron_category->{categorycode}, + branchcode => $library2->{branchcode}, + })->store->borrowernumber; + + my $borrower1 = Koha::Patrons->find( $borrowernumber1 )->unblessed; + my $borrower2 = Koha::Patrons->find( $borrowernumber2 )->unblessed; + + my $issue = AddIssue( $borrower1, $item_1->barcode ); + + # place bib-level reserve + AddReserve({ + branchcode => $library2->{branchcode}, + borrowernumber => $borrowernumber2, + biblionumber => $biblio->biblionumber, + priority => 1, + }); + + t::lib::Mocks::mock_preference( 'AllowRenewalIfOtherItemsAvailable', 1 ); + t::lib::Mocks::mock_preference( 'AllowRenewalIfOtherItemsAvailableLocation', 'any' ); + my ( $renewokay, $error ) = CanBookBeRenewed( $borrowernumber1, $item_1->itemnumber ); + is( $renewokay, 1, 'Renewal allowed if items available at any branch' ); + + t::lib::Mocks::mock_preference( 'AllowRenewalIfOtherItemsAvailableLocation', 'holdbranch' ); + ( $renewokay, $error ) = CanBookBeRenewed( $borrowernumber1, $item_1->itemnumber ); + is( $renewokay, 0, 'Renewal not allowed as available item is at a different branch' ); + + # adjust 2nd item to have same branchcode + $item_2->update({ homebranch => $library2->{branchcode}, holdingbranch => $library2->{branchcode} })->store; + ( $renewokay, $error ) = CanBookBeRenewed( $borrowernumber1, $item_1->itemnumber ); + is( $renewokay, 1, 'Renewal allowed if items available at hold branch' ); +}; + subtest 'CanBookBeIssued & AllowReturnToBranch' => sub { plan tests => 24; -- 2.11.0