From 7c7a766ace6ad29bc9b606640f53ee4c8e4717c6 Mon Sep 17 00:00:00 2001 From: Julian Maurice Date: Fri, 22 Mar 2019 11:42:28 +0100 Subject: [PATCH] Bug 22562: Add option ItemHoldingLibrary to ReservesControlBranch MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Test plan: 1. Apply patch 2. Run updatedatabase 3. Set syspref ReservesControlBranch to "item's holding library" 4. Create biblios, items, patrons on different libraries and define circulation (hold) rules for them 5. Verify that these rules are taken into account and that they use the holding library 6. Verify that the behaviour for other values of ReservesControlBranch still work as expected. Signed-off-by: Nazlı Çetin --- C4/Reserves.pm | 6 ++++++ installer/data/mysql/atomicupdate/bug_22562.perl | 11 +++++++++++ installer/data/mysql/mandatory/sysprefs.sql | 2 +- .../en/modules/admin/preferences/circulation.pref | 1 + t/db_dependent/Reserves.t | 9 ++++++++- 5 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 installer/data/mysql/atomicupdate/bug_22562.perl diff --git a/C4/Reserves.pm b/C4/Reserves.pm index 8941d4f72c..32b2ae650f 100644 --- a/C4/Reserves.pm +++ b/C4/Reserves.pm @@ -420,6 +420,10 @@ sub CanItemBeReserved { $branchfield = "items.homebranch"; $branchcode = $item->homebranch; } + elsif ( $controlbranch eq "ItemHoldingLibrary" ) { + $branchfield = "items.holdingbranch"; + $branchcode = $item->holdingbranch; + } elsif ( $controlbranch eq "PatronLibrary" ) { $branchfield = "borrowers.branchcode"; $branchcode = $borrower->{branchcode}; @@ -2169,6 +2173,7 @@ sub GetReservesControlBranch { my $branchcode = ( $reserves_control eq 'ItemHomeLibrary' ) ? $item->{'homebranch'} + : ( $reserves_control eq 'ItemHoldingLibrary' ) ? $item->{'holdingbranch'} : ( $reserves_control eq 'PatronLibrary' ) ? $borrower->{'branchcode'} : undef; @@ -2273,6 +2278,7 @@ sub GetMaxPatronHoldsForRecord { my $itemtype = $item->effective_itemtype(); $branchcode = $item->homebranch if ( $controlbranch eq "ItemHomeLibrary" ); + $branchcode = $item->holdingbranch if ( $controlbranch eq "ItemHoldingLibrary" ); my $rule = Koha::CirculationRules->get_effective_rule({ categorycode => $categorycode, diff --git a/installer/data/mysql/atomicupdate/bug_22562.perl b/installer/data/mysql/atomicupdate/bug_22562.perl new file mode 100644 index 0000000000..5ec73361ef --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_22562.perl @@ -0,0 +1,11 @@ +$DBversion = 'XXX'; +if( CheckVersion( $DBversion ) ) { + $dbh->do(q{ + UPDATE systempreferences + SET options = 'ItemHomeLibrary|ItemHoldingLibrary|PatronLibrary' + WHERE variable = 'ReservesControlBranch' + }); + + SetVersion( $DBversion ); + print "Upgrade to $DBversion done (Bug 22562 - Add ItemHoldingLibrary to ReservesControlBranch)\n"; +} diff --git a/installer/data/mysql/mandatory/sysprefs.sql b/installer/data/mysql/mandatory/sysprefs.sql index f163912142..b1c437a04c 100644 --- a/installer/data/mysql/mandatory/sysprefs.sql +++ b/installer/data/mysql/mandatory/sysprefs.sql @@ -567,7 +567,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('ReportsLog','0',NULL,'If ON, log information about reports.','YesNo'), ('RequestOnOpac','1',NULL,'If ON, globally enables patron holds on OPAC','YesNo'), ('RequireStrongPassword','1','','Require a strong login password for staff and patrons','YesNo'), -('ReservesControlBranch','PatronLibrary','ItemHomeLibrary|PatronLibrary','Branch checked for members reservations rights','Choice'), +('ReservesControlBranch','PatronLibrary','ItemHomeLibrary|ItemHoldingLibrary|PatronLibrary','Branch checked for members reservations rights','Choice'), ('ReservesMaxPickUpDelay','7','','Define the Maximum delay to pick up an item on hold','Integer'), ('ReservesNeedReturns','1','','If ON, a hold placed on an item available in this library must be checked-in, otherwise, a hold on a specific item, that is in the library & available is considered available','YesNo'), ('RESTBasicAuth','0',NULL,'If enabled, Basic authentication is enabled for the REST API.','YesNo'), 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 0bf3b7c518..e36fa92647 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 @@ -721,6 +721,7 @@ Circulation: - pref: ReservesControlBranch choices: ItemHomeLibrary: "item's home library" + ItemHoldingLibrary: "item's holding library" PatronLibrary: "patron's home library" - to see if the patron can place a hold on the item. - diff --git a/t/db_dependent/Reserves.t b/t/db_dependent/Reserves.t index 5d661ee97f..b1f22e7ea7 100755 --- a/t/db_dependent/Reserves.t +++ b/t/db_dependent/Reserves.t @@ -17,7 +17,7 @@ use Modern::Perl; -use Test::More tests => 67; +use Test::More tests => 68; use Test::MockModule; use Test::Warn; @@ -139,6 +139,13 @@ ok( { branchcode => 'PatronHomeLib' } ), "GetReservesControlBranch returns item home branch when set to ItemHomeLibrary" ); +t::lib::Mocks::mock_preference( 'ReservesControlBranch', 'ItemHoldingLibrary' ); +ok( + 'ItemHoldingLib' eq GetReservesControlBranch( + { holdingbranch => 'ItemHoldingLib' }, + { branchcode => 'PatronHomeLib' } + ), "GetReservesControlBranch returns item holding branch when set to ItemHoldingLibrary" +); t::lib::Mocks::mock_preference( 'ReservesControlBranch', 'PatronLibrary' ); ok( 'PatronHomeLib' eq GetReservesControlBranch( -- 2.20.1