From ec6b82343c492fc9f529d28f63ac810643c44aba Mon Sep 17 00:00:00 2001 From: Kyle Hall Date: Fri, 5 Aug 2022 07:14:14 -0400 Subject: [PATCH] Bug 31296: Add ability to disable demagnetizing items via SIP2 based on itemtypes Some libraries have certain item types that can only do in house checkouts via SIP self check machines. In these cases, the items should not be demagnetized since the items cannot leave the library. Test Plan: 1) Apply this patch 2) prove t/db_dependent/SIP/Message.t --- C4/SIP/ILS/Item.pm | 2 ++ C4/SIP/Sip/MsgType.pm | 28 +++++++++++++++++---- etc/SIPconfig.xml | 1 + t/db_dependent/SIP/Message.t | 47 ++++++++++++++++++++++++++++++++++-- 4 files changed, 71 insertions(+), 7 deletions(-) diff --git a/C4/SIP/ILS/Item.pm b/C4/SIP/ILS/Item.pm index 105b8d01003..5d0a24a8c7b 100644 --- a/C4/SIP/ILS/Item.pm +++ b/C4/SIP/ILS/Item.pm @@ -93,6 +93,7 @@ sub new { $self->{object} = $item; my $it = $item->effective_itemtype; + $self->{itemtype} = $it; my $itemtype = Koha::Database->new()->schema()->resultset('Itemtype')->find( $it ); $self->{sip_media_type} = $itemtype->sip_media_type() if $itemtype; @@ -142,6 +143,7 @@ my %fields = ( location => 0, author => 0, title => 0, + itemtype => 0, ); sub next_hold { diff --git a/C4/SIP/Sip/MsgType.pm b/C4/SIP/Sip/MsgType.pm index 2f7ba7da0fa..90287726303 100644 --- a/C4/SIP/Sip/MsgType.pm +++ b/C4/SIP/Sip/MsgType.pm @@ -556,7 +556,16 @@ sub handle_checkout { } # We never return the obsolete 'U' value for 'desensitize' - $resp .= sipbool( desensitize( { status => $status, patron => $patron, server => $server } ) ); + $resp .= sipbool( + desensitize( + { + item => $item, + patron => $patron, + server => $server, + status => $status, + } + ) + ); $resp .= timestamp; # Now for the variable fields @@ -1745,17 +1754,26 @@ sub desensitize { return unless $desensitize; my $patron = $params->{patron}; + my $item = $params->{item}; my $server = $params->{server}; - my $patron_categories = $server->{account}->{inhouse_patron_categories}; + my $patron_categories = $server->{account}->{inhouse_patron_categories} // q{}; + my $item_types = $server->{account}->{inhouse_item_types} // q{}; - # If no patron categories are set for never desensitize, no need to do anything - return $desensitize unless $patron_categories; + # If no patron categorie or item typess are set for never desensitize, no need to do anything + return $desensitize unless $patron_categories || $item_types; my $patron_category = $patron->ptype(); my @patron_categories = split( /,/, $patron_categories ); + my $found_patron_category = grep( /^$patron_category$/, @patron_categories ); + return 0 if $found_patron_category; + + my $item_type = $item->itemtype; + my @item_types = split( /,/, $item_types ); + my $found_item_type = grep( /^$item_type$/, @item_types ); + return 0 if $found_item_type; - return !grep( /^$patron_category$/, @patron_categories ); + return 1; } 1; diff --git a/etc/SIPconfig.xml b/etc/SIPconfig.xml index e273cfc25bc..3635d59d5c8 100644 --- a/etc/SIPconfig.xml +++ b/etc/SIPconfig.xml @@ -74,6 +74,7 @@ prevcheckout_block_checkout="0" overdues_block_checkout="1" format_due_date="0" + inhouse_item_types="" inhouse_patron_categories=""> diff --git a/t/db_dependent/SIP/Message.t b/t/db_dependent/SIP/Message.t index fc0e11944b0..cf4e183a489 100755 --- a/t/db_dependent/SIP/Message.t +++ b/t/db_dependent/SIP/Message.t @@ -80,7 +80,7 @@ subtest 'Checkout V2' => sub { subtest 'Test checkout desensitize' => sub { my $schema = Koha::Database->new->schema; $schema->storage->txn_begin; - plan tests => 3; + plan tests => 6; $C4::SIP::Sip::protocol_version = 2; test_checkout_desensitize(); $schema->storage->txn_rollback; @@ -89,7 +89,7 @@ subtest 'Test checkout desensitize' => sub { subtest 'Test renew desensitize' => sub { my $schema = Koha::Database->new->schema; $schema->storage->txn_begin; - plan tests => 3; + plan tests => 6; $C4::SIP::Sip::protocol_version = 2; test_renew_desensitize(); $schema->storage->txn_rollback; @@ -899,6 +899,7 @@ sub test_checkout_desensitize { homebranch => $branchcode, holdingbranch => $branchcode, }); + my $itemtype = $item_object->effective_itemtype; my $mockILS = $mocks->{ils}; my $server = { ils => $mockILS, account => {} }; @@ -937,6 +938,26 @@ sub test_checkout_desensitize { $msg->handle_checkout( $server ); $respcode = substr( $response, 5, 1 ); is( $respcode, 'Y', "Desensitize flag was set for empty inhouse_patron_categories" ); + + $server->{account}->{inhouse_patron_categories} = ""; + + undef $response; + $server->{account}->{inhouse_item_types} = "A,$itemtype,Z"; + $msg->handle_checkout( $server ); + $respcode = substr( $response, 5, 1 ); + is( $respcode, 'N', "Desensitize flag was not set for itemtype in inhouse_item_types" ); + + undef $response; + $server->{account}->{inhouse_item_types} = "A,B,C"; + $msg->handle_checkout( $server ); + $respcode = substr( $response, 5, 1 ); + is( $respcode, 'Y', "Desensitize flag was set for item type not in inhouse_item_types" ); + + undef $response; + $server->{account}->{inhouse_item_types} = ""; + $msg->handle_checkout( $server ); + $respcode = substr( $response, 5, 1 ); + is( $respcode, 'Y', "Desensitize flag was set for empty inhouse_item_types" ); } sub test_renew_desensitize { @@ -964,6 +985,7 @@ sub test_renew_desensitize { homebranch => $branchcode, holdingbranch => $branchcode, }); + my $itemtype = $item_object->effective_itemtype; my $mockILS = $mocks->{ils}; my $server = { ils => $mockILS, account => {} }; @@ -1003,6 +1025,27 @@ sub test_renew_desensitize { $msg->handle_checkout( $server ); $respcode = substr( $response, 5, 1 ); is( $respcode, 'Y', "Desensitize flag was set for empty inhouse_patron_categories" ); + + $server->{account}->{inhouse_patron_categories} = ""; + + undef $response; + $server->{account}->{inhouse_item_types} = "A,B,C"; + $msg->handle_checkout( $server ); + $respcode = substr( $response, 5, 1 ); + is( $respcode, 'Y', "Desensitize flag was set for item type not in inhouse_item_types" ); + + undef $response; + $server->{account}->{inhouse_item_types} = ""; + $msg->handle_checkout( $server ); + $respcode = substr( $response, 5, 1 ); + is( $respcode, 'Y', "Desensitize flag was set for empty inhouse_item_types" ); + + undef $response; + $server->{account}->{inhouse_item_types} = "A,$itemtype,Z"; + $msg->handle_checkout( $server ); + $respcode = substr( $response, 5, 1 ); + is( $respcode, 'N', "Desensitize flag was not set for itemtype in inhouse_item_types" ); + } # Helper routines -- 2.30.2