Bug 25232: Add ability to skip trapping items with a given notforloan value
authorKyle M Hall <kyle@bywatersolutions.com>
Tue, 21 Apr 2020 17:52:40 +0000 (13:52 -0400)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Thu, 25 Jun 2020 08:50:02 +0000 (10:50 +0200)
This is a companion/alternative to bug 25184, in that it allows an
explicit workflow for placing returned books into temporary storage for
a few days for decontamination purposes.

The idea here is to create a specific notforloan value for "In
Decontamination" or something along along those lines. This notforloan
value would never be trappable. At the end of decon,
UpdateNotForLoanStatusOnCheckin  could be used to remove the
notforloan status and allow checkins to be trapped to fill holds.

Test Plan:
1) Apply this patch
2) Restart all the things!
3) Give an item a negative notforloan value
4) Place a hold on the item
5) Check the item in
6) Note the item is trapped for hold
7) Set SkipHoldTrapOnNotForLoanValue to the same notforloan value
   you used in step 3
8) Check the item in again
9) Note Koha did not ask you to trap the item for hold!

Signed-off-by: Sally <sally.healey@cheshiresharedservices.gov.uk>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

C4/Reserves.pm
installer/data/mysql/atomicupdate/bug_25232.perl [new file with mode: 0644]
installer/data/mysql/sysprefs.sql
koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref
t/db_dependent/Holds.t

index d328773..fb7aba2 100644 (file)
@@ -794,6 +794,9 @@ sub CheckReserves {
     # if item is not for loan it cannot be reserved either.....
     # except where items.notforloan < 0 :  This indicates the item is holdable.
 
+    my $SkipHoldTrapOnNotForLoanValue = C4::Context->preference('SkipHoldTrapOnNotForLoanValue');
+    return if $SkipHoldTrapOnNotForLoanValue && $notforloan_per_item eq $SkipHoldTrapOnNotForLoanValue;
+
     my $dont_trap = C4::Context->preference('TrapHoldsOnOrder') ? ($notforloan_per_item > 0) : ($notforloan_per_item && 1 );
     return if $dont_trap or $notforloan_per_itemtype;
 
diff --git a/installer/data/mysql/atomicupdate/bug_25232.perl b/installer/data/mysql/atomicupdate/bug_25232.perl
new file mode 100644 (file)
index 0000000..2d33185
--- /dev/null
@@ -0,0 +1,11 @@
+$DBversion = 'XXX'; # will be replaced by the RM
+if( CheckVersion( $DBversion ) ) {
+    # $dbh->do( "ALTER TABLE biblio ADD COLUMN badtaste int" );
+    $dbh->do(q{
+        INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `type` ) VALUES
+        ('SkipHoldTrapOnNotForLoanValue','',NULL,'If set, Koha will never trap items for hold with this notforloan value','Integer')
+    });
+
+    # Always end with this (adjust the bug info)
+    NewVersion( $DBversion, 25184, "Items with a negative notforloan status should not be captured for holds");
+}
index 4ad73ef..d67a02b 100644 (file)
@@ -587,6 +587,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `
 ('ShowPatronImageInWebBasedSelfCheck','0','','If ON, displays patron image when a patron uses web-based self-checkout','YesNo'),
 ('ShowReviewer','full','none|full|first|surname|firstandinitial|username','Choose how a commenter\'s identity is presented alongside comments in the OPAC','Choice'),
 ('ShowReviewerPhoto','1','','If ON, photo of reviewer will be shown beside comments in OPAC','YesNo'),
+('SkipHoldTrapOnNotForLoanValue','',NULL,'If set, Koha will never trap items for hold with this notforloan value','Integer'),
 ('SlipCSS','',NULL,'Slips CSS url.','free'),
 ('SMSSendDriver','','','Sets which SMS::Send driver is used to send SMS messages.','free'),
 ('SMSSendPassword', '', '', 'Password used to send SMS messages', 'free'),
index 9213789..0fd5438 100644 (file)
@@ -527,6 +527,11 @@ Circulation:
                   no: "Don't trap"
             - items that are not for loan but holdable ( notforloan < 0 ) to fill holds.
         -
+            - Never trap items with a 'not for loan' value of
+            - pref: SkipHoldTrapOnNotForLoanValue
+              class: integer
+            - to fill holds.
+        -
             - pref: HoldsAutoFill
               choices:
                   yes: Do
index 688b12f..a82fa53 100755 (executable)
@@ -7,7 +7,7 @@ use t::lib::TestBuilder;
 
 use C4::Context;
 
-use Test::More tests => 64;
+use Test::More tests => 65;
 use MARC::Record;
 
 use C4::Biblio;
@@ -363,6 +363,8 @@ $hold = Koha::Hold->new(
 ok( !defined( ( CheckReserves($itemnumber) )[1] ), "Hold cannot be trapped for item that is not for loan but holdable ( notforloan < 0 )" );
 t::lib::Mocks::mock_preference( 'TrapHoldsOnOrder', 1 );
 ok( defined( ( CheckReserves($itemnumber) )[1] ), "Hold is trapped for item that is not for loan but holdable ( notforloan < 0 )" );
+t::lib::Mocks::mock_preference( 'SkipHoldTrapOnNotForLoanValue', '-1' );
+ok( !defined( ( CheckReserves($itemnumber) )[1] ), "Hold cannot be trapped for item with notforloan value matching SkipHoldTrapOnNotForLoanValue" );
 $hold->delete();
 
 # Regression test for bug 9532