From 853990a52d51cd112f0a7c8e205713a13ee4d70c 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 Signed-off-by: Martin Renvoize Signed-off-by: Tomas Cohen Arazi (cherry picked from commit 00f489de6d05fd8a5d4c8b4599a72d55e1ee8005) Signed-off-by: Lucas Gass --- 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 105b8d0100..5d0a24a8c7 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 74e7dfff24..6c7da24732 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 ce2e8947e8..68c00ed8d0 100644 --- a/etc/SIPconfig.xml +++ b/etc/SIPconfig.xml @@ -75,6 +75,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 fc0e11944b..cf4e183a48 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.39.5