From 4092a48f558ebd1c4a224e9d8fd2da8328d1275d Mon Sep 17 00:00:00 2001 From: Matthias Meusburger Date: Thu, 17 Oct 2019 10:32:18 +0200 Subject: [PATCH] Bug 25815: SIP Checkout: add more information on why the patron is blocked. Currently, on SIP checkout, Koha only returns "Patron Blocked" when there is a problem with the patron. This patch adds more specific informations, with the following messages: - "Patron expired" - "Patron debarred" - "Patron has fines" (see system preference "noissuescharge") - "Patron blocked" (see system preference "OverduesBlockCirc") Test plan: - Try to do a SIP checkout with a patron that is in one of the above situations. - Check that the displayed message matches the patron's situation. Signed-off-by: Sonia Signed-off-by: Martin Renvoize --- C4/SIP/ILS.pm | 13 +++-- C4/SIP/ILS/Patron.pm | 4 ++ t/db_dependent/SIP/Transaction.t | 92 +++++++++++++++++++++++++++++++- 3 files changed, 104 insertions(+), 5 deletions(-) diff --git a/C4/SIP/ILS.pm b/C4/SIP/ILS.pm index 145fe89aac..e6c75671be 100644 --- a/C4/SIP/ILS.pm +++ b/C4/SIP/ILS.pm @@ -123,21 +123,26 @@ sub offline_ok { sub checkout { my ( $self, $patron_id, $item_id, $sc_renew, $fee_ack, $account ) = @_; my ( $patron, $item, $circ ); - $circ = C4::SIP::ILS::Transaction::Checkout->new(); - # BEGIN TRANSACTION $circ->patron( $patron = C4::SIP::ILS::Patron->new($patron_id) ); $circ->item( $item = C4::SIP::ILS::Item->new($item_id) ); if ($fee_ack) { $circ->fee_ack($fee_ack); } - if ( !$patron ) { $circ->screen_msg("Invalid Patron"); } elsif ( !$patron->charge_ok ) { - $circ->screen_msg("Patron Blocked"); + if ($patron->debarred) { + $circ->screen_msg("Patron debarred"); + } elsif ($patron->expired) { + $circ->screen_msg("Patron expired"); + } elsif ($patron->fine_blocked) { + $circ->screen_msg("Patron has fines"); + } else { + $circ->screen_msg("Patron blocked"); + } } elsif ( !$item ) { $circ->screen_msg("Invalid Item"); diff --git a/C4/SIP/ILS/Patron.pm b/C4/SIP/ILS/Patron.pm index 95166d3da8..7d77b7e9be 100644 --- a/C4/SIP/ILS/Patron.pm +++ b/C4/SIP/ILS/Patron.pm @@ -126,7 +126,9 @@ sub new { recall_items => [], unavail_holds => [], inet => ( !$debarred && !$expired ), + debarred => $debarred, expired => $expired, + fine_blocked => $fine_blocked, fee_limit => $fee_limit, userid => $kp->{userid}, ); @@ -181,6 +183,8 @@ my %fields = ( birthdate_iso => 0, dateexpiry => 0, dateexpiry_iso => 0, + debarred => 0, + fine_blocked => 0, ptype => 0, charge_ok => 0, # for patron_status[0] (inverted) renew_ok => 0, # for patron_status[1] (inverted) diff --git a/t/db_dependent/SIP/Transaction.t b/t/db_dependent/SIP/Transaction.t index b54ca6f085..f11efa8038 100755 --- a/t/db_dependent/SIP/Transaction.t +++ b/t/db_dependent/SIP/Transaction.t @@ -4,7 +4,7 @@ # Current state is very rudimentary. Please help to extend it! use Modern::Perl; -use Test::More tests => 13; +use Test::More tests => 14; use Koha::Database; use t::lib::TestBuilder; @@ -377,6 +377,96 @@ subtest do_checkin => sub { }; }; +subtest do_checkout_with_patron_blocked => sub { + plan tests => 4; + + my $library = $builder->build_object( { class => 'Koha::Libraries' } ); + my $institution = { + id => $library->id, + implementation => "ILS", + policy => { + checkin => "true", + renewal => "true", + checkout => "true", + timeout => 100, + retries => 5, + } + }; + my $ils = C4::SIP::ILS->new($institution); + my $item = $builder->build_sample_item( + { + library => $library->branchcode, + } + ); + + my $expired_patron = $builder->build_object( + { + class => 'Koha::Patrons', + value => { + branchcode => $library->branchcode, + dateexpiry => '2020/01/01', + } + } + ); + my $circ = $ils->checkout($expired_patron->cardnumber, $item->barcode); + is( $circ->{screen_msg}, 'Patron expired', "Got correct expired screen message" ); + + my $fines_patron = $builder->build_object( + { + class => 'Koha::Patrons', + value => { + branchcode => $library->branchcode, + } + } + ); + my $fee1 = $builder->build( + { + source => 'Accountline', + value => { + borrowernumber => $fines_patron->borrowernumber, + amountoutstanding => 10, + } + } + ); + + my $fines_sip_patron = C4::SIP::ILS::Patron->new( $fines_patron->cardnumber ); + $circ = $ils->checkout($fines_patron->cardnumber, $item->barcode); + is( $circ->{screen_msg}, 'Patron has fines', "Got correct fines screen message" ); + + my $debarred_patron = $builder->build_object( + { + class => 'Koha::Patrons', + value => { + branchcode => $library->branchcode, + debarred => '9999/01/01', + } + } + ); + my $debarred_sip_patron = C4::SIP::ILS::Patron->new( $debarred_patron->cardnumber ); + $circ = $ils->checkout($debarred_patron->cardnumber, $item->barcode); + is( $circ->{screen_msg}, 'Patron debarred', "Got correct debarred screen message" ); + + my $overdue_patron = $builder->build_object( + { + class => 'Koha::Patrons', + value => { + branchcode => $library->branchcode, + } + } + ); + + my $odue = $builder->build({ source => 'Issue', value => { + borrowernumber => $overdue_patron->borrowernumber, + date_due => '2017-01-01', + } + }); + t::lib::Mocks::mock_preference( 'OverduesBlockCirc', 'block' ); + my $overdue_sip_patron = C4::SIP::ILS::Patron->new( $overdue_patron->cardnumber ); + $circ = $ils->checkout($overdue_patron->cardnumber, $item->barcode); + is( $circ->{screen_msg}, 'Patron blocked', "Got correct blocked screen message" ); + +}; + subtest do_checkout_with_holds => sub { plan tests => 7; -- 2.20.1