From 5da47a7f6ac5b7cbd94c549960f652eb8d205811 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 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. --- C4/Reserves.pm | 6 ++++++ installer/data/mysql/atomicupdate/bug_22562.perl | 11 +++++++++++ .../prog/en/modules/admin/preferences/circulation.pref | 1 + t/db_dependent/Reserves.t | 9 ++++++++- 4 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 installer/data/mysql/atomicupdate/bug_22562.perl diff --git a/C4/Reserves.pm b/C4/Reserves.pm index 00d921d77e..554876ba1d 100644 --- a/C4/Reserves.pm +++ b/C4/Reserves.pm @@ -392,6 +392,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}; @@ -2098,6 +2102,7 @@ sub GetReservesControlBranch { my $branchcode = ( $reserves_control eq 'ItemHomeLibrary' ) ? $item->{'homebranch'} + : ( $reserves_control eq 'ItemHoldingLibrary' ) ? $item->{'holdingbranch'} : ( $reserves_control eq 'PatronLibrary' ) ? $borrower->{'branchcode'} : undef; @@ -2202,6 +2207,7 @@ sub GetMaxPatronHoldsForRecord { my $itemtype = $item->effective_itemtype(); $branchcode = $item->homebranch if ( $controlbranch eq "ItemHomeLibrary" ); + $branchcode = $item->holdingbranch if ( $controlbranch eq "ItemHoldingLibrary" ); my $rule = GetHoldRule( $categorycode, $itemtype, $branchcode ); my $holds_per_record = $rule ? $rule->{holds_per_record} : 0; 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/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref index 1683d9f034..2937bdb46a 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 @@ -642,6 +642,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 ef47e26473..36a9c4e1be 100755 --- a/t/db_dependent/Reserves.t +++ b/t/db_dependent/Reserves.t @@ -17,7 +17,7 @@ use Modern::Perl; -use Test::More tests => 62; +use Test::More tests => 63; use Test::MockModule; use Test::Warn; @@ -147,6 +147,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.11.0