From 205d2752adaa64d82b6c67ec93107dea3f728197 Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Wed, 8 Mar 2023 12:45:53 +0000 Subject: [PATCH] Bug 32684: (QA follow-up) Move too_many_lost to Patron Alternative implementation outside sub new. Test plan: Run t/db_dependent/SIP/Message.t Signed-off-by: Marcel de Rooy Signed-off-by: Kyle M Hall Signed-off-by: Tomas Cohen Arazi (cherry picked from commit e630624e5e0d6a1c1e14e2715b152be9aa139fe6) Signed-off-by: Jacob O'Mara --- C4/SIP/ILS/Patron.pm | 22 ++++++++++++++++++++-- C4/SIP/ILS/Patron.pod | 4 ++-- C4/SIP/Sip/MsgType.pm | 9 +-------- 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/C4/SIP/ILS/Patron.pm b/C4/SIP/ILS/Patron.pm index e5542bfb2b..0aea8ab63c 100644 --- a/C4/SIP/ILS/Patron.pm +++ b/C4/SIP/ILS/Patron.pm @@ -26,10 +26,11 @@ use C4::Auth qw(checkpw); use Koha::Items; use Koha::Libraries; use Koha::Patrons; +use Koha::Checkouts; our $kp; # koha patron -=head1 Methods +=head1 METHODS =cut @@ -209,7 +210,6 @@ my %fields = ( too_many_overdue => 0, # for patron_status[6] too_many_renewal => 0, # for patron_status[7] too_many_claim_return => 0, # for patron_status[8] - too_many_lost => 0, # for patron_status[9] # excessive_fines => 0, # for patron_status[10] # excessive_fees => 0, # for patron_status[11] recall_overdue => 0, # for patron_status[12] @@ -287,6 +287,24 @@ sub check_password { } # A few special cases, not in AUTOLOADed %fields + +=head2 too_many_lost + +This method checks if number of checkouts of lost items exceeds a threshold (defined in server account). + +=cut + +sub too_many_lost { + my ( $self, $server ) = @_; + my $too_many_lost = 0; + if( $server && $server->{account} && ( my $lost_block_checkout = $server->{account}->{lost_block_checkout} )) { + my $lost_block_checkout_value = $server->{account}->{lost_block_checkout_value} // 1; + my $lost_checkouts = Koha::Checkouts->search({ borrowernumber => $self->borrowernumber, 'itemlost' => { '>=', $lost_block_checkout_value } }, { join => 'item'} )->count; + $too_many_lost = $lost_checkouts >= $lost_block_checkout; + } + return $too_many_lost; +} + sub fee_amount { my $self = shift; if ( $self->{fines} ) { diff --git a/C4/SIP/ILS/Patron.pod b/C4/SIP/ILS/Patron.pod index 71c167c0b9..80061b0172 100644 --- a/C4/SIP/ILS/Patron.pod +++ b/C4/SIP/ILS/Patron.pod @@ -41,7 +41,7 @@ and to display information about the patron's borrowing activity. $bool = $patron->too_many_overdue; $bool = $patron->too_many_renewal; $bool = $patron->too_many_claim_return; - $bool = $patron->too_many_lost; + $bool = $patron->too_many_lost( $server ); $bool = $patron->excessive_fines; $bool = $patron->excessive_fees; $bool = $patron->too_many_billed; @@ -149,7 +149,7 @@ checking if they're authorized to perform various actions: $bool = $patron-Etoo_many_overdue; $bool = $patron-Etoo_many_renewal; $bool = $patron-Etoo_many_claim_return; - $bool = $patron-Etoo_many_lost; + $bool = $patron-Etoo_many_lost( $server ); $bool = $patron-Eexcessive_fines; $bool = $patron-Eexcessive_fees; $bool = $patron-Etoo_many_billed; diff --git a/C4/SIP/Sip/MsgType.pm b/C4/SIP/Sip/MsgType.pm index 658eb5eb91..3510683d84 100644 --- a/C4/SIP/Sip/MsgType.pm +++ b/C4/SIP/Sip/MsgType.pm @@ -1717,13 +1717,6 @@ sub patron_status_string { my $patron_status; - my $too_many_lost = 0; - if ( my $lost_block_checkout = $server->{account}->{lost_block_checkout} ) { - my $lost_block_checkout_value = $server->{account}->{lost_block_checkout_value} // 1; - my $lost_checkouts = Koha::Checkouts->search({ borrowernumber => $patron->borrowernumber, 'itemlost' => { '>=', $lost_block_checkout_value } }, { 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', @@ -1736,7 +1729,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( $too_many_lost ), + boolspace( $patron->too_many_lost( $server ) ), boolspace( $patron->excessive_fines ), boolspace( $patron->excessive_fees ), boolspace( $patron->recall_overdue ), -- 2.39.5