From 12abc36ef7c5965dc29e1b182a189a0ddc5a8528 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 +++++++++++ .../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 3617549582..cb36d18e17 100644 --- a/C4/Reserves.pm +++ b/C4/Reserves.pm @@ -357,6 +357,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}; @@ -2019,6 +2023,7 @@ sub GetReservesControlBranch { my $branchcode = ( $reserves_control eq 'ItemHomeLibrary' ) ? $item->{'homebranch'} + : ( $reserves_control eq 'ItemHoldingLibrary' ) ? $item->{'holdingbranch'} : ( $reserves_control eq 'PatronLibrary' ) ? $borrower->{'branchcode'} : undef; @@ -2123,6 +2128,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 9720430bf3..13277d3957 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 @@ -611,6 +611,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 9b526258a7..040c0bf262 100755 --- a/t/db_dependent/Reserves.t +++ b/t/db_dependent/Reserves.t @@ -17,7 +17,7 @@ use Modern::Perl; -use Test::More tests => 59; +use Test::More tests => 60; 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.20.1