lp1861319 Expired Patron Item Renewal WIP Cont'd user/khuckins/lp1861319-expired-patron-ite-renewal
authorKyle Huckins <khuckins@catalyte.io>
Tue, 7 Apr 2020 17:52:49 +0000 (17:52 +0000)
committerKyle Huckins <khuckins@catalyte.io>
Tue, 7 Apr 2020 17:52:49 +0000 (17:52 +0000)
- Include YAOUS to allow/disallow renewal of items
to expired patrons
- Logging to debug no_matchpoint error

Signed-off-by: Kyle Huckins <khuckins@catalyte.io>
 Changes to be committed:
modified:   Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Circulate.pm
modified:   Open-ILS/src/sql/Pg/950.data.seed-values.sql
modified:   Open-ILS/src/sql/Pg/upgrade/XXXX.data.org-setting-circ-renew-expired.sql

Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/Circulate.pm
Open-ILS/src/sql/Pg/950.data.seed-values.sql
Open-ILS/src/sql/Pg/upgrade/XXXX.data.org-setting-circ-renew-expired.sql

index d99d525..ca00c57 100644 (file)
@@ -192,9 +192,11 @@ sub run_method {
     # --------------------------------------------------------------------------
 
     if ($circulator->use_booking && (my $bc = $circulator->copy_barcode) && $api !~ /checkout|inspect/) { # do we have a barcode?
+
         my $resources = $circulator->editor->search_booking_resource( { barcode => $bc } ); # any resources by this barcode?
         if (@$resources) { # yes!
 
+
             my $res_id_list = [ map { $_->id } @$resources ];
             my $transit = $circulator->editor->search_action_reservation_transit_copy(
                 [
@@ -254,6 +256,7 @@ sub run_method {
     $circulator->override(1) if $api =~ /override/o;
 
     $circulator->mk_env();
+
     $circulator->noop(1) if $circulator->claims_never_checked_out;
 
     return circ_events($circulator) if $circulator->bail_out;
@@ -296,7 +299,7 @@ sub run_method {
     }
 
     if( $circulator->bail_out ) {
-
+        $logger->error("Bailing out");
         my @ee;
         # make sure no success event accidentally slip in
         $circulator->events(
@@ -1027,9 +1030,14 @@ sub mk_env {
     
         my $expire = DateTime::Format::ISO8601->new->parse_datetime(
             clean_ISO8601($patron->expire_date));
-    
-        $self->bail_on_events(OpenILS::Event->new('PATRON_ACCOUNT_EXPIRED'))
-            if( CORE::time > $expire->epoch ) ;
+
+        # An expired patron needs an OUS disabled to renew
+        my $expire_setting = $U->ou_ancestor_setting_value($patron->home_ou, OILS_SETTING_BLOCK_RENEW_FOR_EXPIRED_PATRON);
+        $logger->error($expire_setting);
+        if(CORE::time > $expire->epoch) {
+            $self->bail_on_events(OpenILS::Event->new('PATRON_ACCOUNT_EXPIRED'))
+                unless ($expire_setting == 0 && $self->is_renewal);
+        }
     }
 }
 
@@ -1050,11 +1058,15 @@ sub do_permit {
     $self->check_captured_holds();
     $self->do_copy_checks();
     return if $self->bail_out;
+    
     $self->run_patron_permit_scripts();
     $self->run_copy_permit_scripts() 
         unless $self->is_precat or $self->is_noncat;
     $self->check_item_deposit_events();
     $self->override_events();
+
+    $logger->error("Checking bailout after override events");
+    $logger->error($self->bail_out);
     return if $self->bail_out;
 
     if($self->is_precat and not $self->request_precat) {
@@ -1303,6 +1315,7 @@ sub matrix_test_result_codes {
 
 sub matrix_test_result_events {
     my $self = shift;
+    $logger->error("Entering matrix_test_result_events");
     map {
         my $event = new OpenILS::Event(
             $LEGACY_CIRC_EVENT_MAP->{$_->{"fail_part"}} || $_->{"fail_part"}
@@ -1314,7 +1327,9 @@ sub matrix_test_result_events {
 
 sub run_indb_circ_test {
     my $self = shift;
+    $logger->error("entering run_indb_circ_test");
     return $self->matrix_test_result if $self->matrix_test_result;
+    $logger->error("Not immediately returning...");
 
     my $dbfunc = ($self->is_renewal) ? 
         'action.item_user_renew_test' : 'action.item_user_circ_test';
@@ -1323,7 +1338,7 @@ sub run_indb_circ_test {
         $self->make_precat_copy;
         return if $self->bail_out;
     }
-
+    $logger->error("Patron id is ");$logger->error($self->patron->id);
     my $results = $self->editor->json_query(
         {   from => [
                 $dbfunc,
@@ -1333,10 +1348,15 @@ sub run_indb_circ_test {
             ]
         }
     );
-
+    $logger->error("Gathered results:");
+    $logger->error($results);
+    $logger->error($results->[0]);
+    $logger->error($results->[0]->{success});
     $self->circ_test_success($U->is_true($results->[0]->{success}));
 
     if(my $mp = $results->[0]->{matchpoint}) {
+        $logger->error("Matchpoint found as");
+        $logger->error($mp);
         $logger->info("circulator: circ policy test found matchpoint built via rows " . $results->[0]->{buildrows});
         $self->circ_matrix_matchpoint($self->editor->retrieve_config_circ_matrix_matchpoint($mp));
         $self->circ_matrix_matchpoint->duration_rule($self->editor->retrieve_config_rules_circ_duration($results->[0]->{duration_rule}));
@@ -1529,12 +1549,14 @@ sub override_events {
     my @events = @{$self->events};
     return unless @events;
     my $oargs = $self->override_args;
-
+    $logger->error("Events amount are @events");
+    $logger->error($events[0]->{textcode}); # No matchpoint
+    $logger->error($events[1]->{textcode}); # Success
     if(!$self->override) {
         return $self->bail_out(1) 
             if( @events > 1 or $events[0]->{textcode} ne 'SUCCESS' );
     }   
-
+    $logger->error("Only one event or first event is a success");
     $self->events([]);
     
     for my $e (@events) {
@@ -4053,7 +4075,7 @@ sub do_renew {
     unless( $circ->usr eq $self->editor->requestor->id ) {
         return $self->bail_on_events($self->editor->events)
             unless $self->editor->allowed('RENEW_CIRC', $circ->circ_lib);
-    }   
+    }
 
     $self->push_events(OpenILS::Event->new('MAX_RENEWALS_REACHED'))
         if $circ->renewal_remaining < 1;
@@ -4101,9 +4123,13 @@ sub do_renew {
     #$self->handle_fines;
 
     $self->run_renew_permit;
+    $logger->error("Checking events post renew_permit");
+    $logger->error(@{$self->events}); # One
+    $logger->error(@{$self->events}[0]->{textcode}); # No matchpoint
 
     # Check the item in
     $self->do_checkin();
+    
     return if $self->bail_out;
 
     unless( $self->permit_override ) {
@@ -4139,7 +4165,7 @@ sub have_event {
 
 sub run_renew_permit {
     my $self = shift;
-
+    $logger->error("Entering run_renew_permit");
     if ($U->ou_ancestor_setting_value($self->circ_lib, 'circ.block_renews_for_holds')) {
         my ($hold, undef, $retarget) = $holdcode->find_nearest_permitted_hold(
             $self->editor, $self->copy, $self->editor->requestor, 1
@@ -4148,8 +4174,11 @@ sub run_renew_permit {
     }
 
     my $results = $self->run_indb_circ_test;
+    $logger->error("Pushing events");
     $self->push_events($self->matrix_test_result_events)
         unless $self->circ_test_success;
+        
+    $logger->error(@{$self->events});
 }
 
 
index e7e1a37..c170775 100644 (file)
@@ -3558,6 +3558,15 @@ INSERT into config.org_unit_setting_type
         'coust', 'description'),
     'bool', null)
 
+,( 'circ.renew.expired_patron_block', 'circ',
+    oils_i18n_gettext('circ.renew.expired_patron_block',
+        'Block renewal request if renewal recipient privileges have expired',
+        'coust', 'label'),
+    oils_i18n_gettext('circ.renew.expired_patron_block',
+        'Block renewal request if renewal recipient privileges have expired',
+        'coust', 'description'),
+    'bool', null)
+
 ,( 'circ.holds.hold_has_copy_at.alert', 'holds',
     oils_i18n_gettext('circ.holds.hold_has_copy_at.alert',
         'Has Local Copy Alert',
index 18472ff..88a8779 100644 (file)
@@ -9,7 +9,7 @@ VALUES (
     'circ.renew.expired_patron_block', 'bool',
     oils_i18n_gettext(
         'circ.renew.expired_patron_block',
-        'Circulation: Block renewal request if renewal recipient privileges have expired',
+        'Block renewal request if renewal recipient privileges have expired',
         'coust',
         'label'
     ),