@@ -, +, @@ SIP2 based on itemtypes --- 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(-) --- a/C4/SIP/ILS/Item.pm +++ a/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 { --- a/C4/SIP/Sip/MsgType.pm +++ a/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; --- a/etc/SIPconfig.xml +++ a/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=""> --- a/t/db_dependent/SIP/Message.t +++ a/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 --