@@ -, +, @@ lost" --- C4/SIP/Sip/MsgType.pm | 8 +++- etc/SIPconfig.xml | 2 + t/db_dependent/SIP/Message.t | 78 +++++++++++++++++++++++++++++++++++- 3 files changed, 85 insertions(+), 3 deletions(-) --- a/C4/SIP/Sip/MsgType.pm +++ a/C4/SIP/Sip/MsgType.pm @@ -1714,6 +1714,12 @@ sub patron_status_string { my $patron_status; + my $too_many_lost = 0; + if ( my $lost_block_checkout = $server->{account}->{lost_block_checkout} ) { + my $lost_checkouts = Koha::Checkouts->search({ borrowernumber => $patron->borrowernumber, 'itemlost' => { '>', 0 } }, { join => 'item'} )->count; + $too_many_lost = $lost_checkouts >= $lost_block_checkout; + } + siplog( "LOG_DEBUG", "patron_status_string: %s charge_ok: %s", $patron->id, $patron->charge_ok ); $patron_status = sprintf( '%s%s%s%s%s%s%s%s%s%s%s%s%s%s', @@ -1726,7 +1732,7 @@ sub patron_status_string { $server->{account}->{overdues_block_checkout} ? boolspace( $patron->too_many_overdue ) : q{ }, boolspace( $patron->too_many_renewal ), boolspace( $patron->too_many_claim_return ), - boolspace( $patron->too_many_lost ), + boolspace( $too_many_lost ), boolspace( $patron->excessive_fines ), boolspace( $patron->excessive_fees ), boolspace( $patron->recall_overdue ), --- a/etc/SIPconfig.xml +++ a/etc/SIPconfig.xml @@ -74,9 +74,11 @@ holds_get_captured="1" prevcheckout_block_checkout="0" overdues_block_checkout="1" + lost_block_checkout="2" format_due_date="0" inhouse_item_types="" inhouse_patron_categories=""> + --- a/t/db_dependent/SIP/Message.t +++ a/t/db_dependent/SIP/Message.t @@ -21,7 +21,7 @@ # along with Koha; if not, see . use Modern::Perl; -use Test::More tests => 15; +use Test::More tests => 16; use Test::Exception; use Test::MockObject; use Test::MockModule; @@ -31,7 +31,7 @@ use t::lib::Mocks; use t::lib::TestBuilder; use C4::Reserves qw( AddReserve ); -use C4::Circulation qw( AddReturn ); +use C4::Circulation qw( AddIssue AddReturn ); use Koha::Database; use Koha::AuthUtils qw(hash_password); use Koha::DateUtils qw( dt_from_string output_pref ); @@ -237,6 +237,80 @@ subtest 'Lastseen response' => sub { }; +subtest "Test patron_status_string" => sub { + my $schema = Koha::Database->new->schema; + $schema->storage->txn_begin; + + plan tests => 7; + + my $builder = t::lib::TestBuilder->new(); + my $branchcode = $builder->build({ source => 'Branch' })->{branchcode}; + my $patron = $builder->build({ + source => 'Borrower', + value => { + branchcode => $branchcode, + }, + }); + my $sip_patron = C4::SIP::ILS::Patron->new( $patron->{cardnumber} ); + + t::lib::Mocks::mock_userenv({ branchcode => $branchcode }); + + my $item1 = $builder->build_sample_item( + { + damaged => 0, + withdrawn => 0, + itemlost => 0, + restricted => 0, + homebranch => $branchcode, + holdingbranch => $branchcode, + permanent_location => "PERMANENT_LOCATION" + } + ); + AddIssue( $patron, $item1->barcode ); + + my $item2 = $builder->build_sample_item( + { + damaged => 0, + withdrawn => 0, + itemlost => 0, + restricted => 0, + homebranch => $branchcode, + holdingbranch => $branchcode, + permanent_location => "PERMANENT_LOCATION" + } + ); + AddIssue( $patron, $item2->barcode ); + + is( Koha::Checkouts->search({ borrowernumber => $patron->{borrowernumber} })->count, 2, "Found 2 checkouts for this patron" ); + + $item1->itemlost(1)->store(); + $item2->itemlost(2)->store(); + + is( Koha::Checkouts->search({ borrowernumber => $patron->{borrowernumber}, 'itemlost' => { '>', 0 } }, { join => 'item'} )->count, 2, "Found 2 lost checkouts for this patron" ); + + my $server->{account}->{lost_block_checkout} = undef; + my $patron_status_string = C4::SIP::Sip::MsgType::patron_status_string( $sip_patron, $server ); + is( substr($patron_status_string, 9, 1), q{ }, "lost_block_checkout = 0 does not block checkouts with 2 lost checkouts" );; + + $server->{account}->{lost_block_checkout} = 0; + $patron_status_string = C4::SIP::Sip::MsgType::patron_status_string( $sip_patron, $server ); + is( substr($patron_status_string, 9, 1), q{ }, "lost_block_checkout = 0 does not block checkouts with 2 lost checkouts" );; + + $server->{account}->{lost_block_checkout} = 1; + $patron_status_string = C4::SIP::Sip::MsgType::patron_status_string( $sip_patron, $server ); + is( substr($patron_status_string, 9, 1), q{Y}, "lost_block_checkout = 1 does not block checkouts with 2 lost checkouts" );; + + $server->{account}->{lost_block_checkout} = 2; + $patron_status_string = C4::SIP::Sip::MsgType::patron_status_string( $sip_patron, $server ); + is( substr($patron_status_string, 9, 1), q{Y}, "lost_block_checkout = 2 does not block checkouts with 2 lost checkouts" );; + + $server->{account}->{lost_block_checkout} = 3; + $patron_status_string = C4::SIP::Sip::MsgType::patron_status_string( $sip_patron, $server ); + is( substr($patron_status_string, 9, 1), q{ }, "lost_block_checkout = 3 does not block checkouts with 2 lost checkouts" );; + + $schema->storage->txn_rollback; +}; + subtest "Test build_additional_item_fields_string" => sub { my $schema = Koha::Database->new->schema; $schema->storage->txn_begin; --