ability to override checkin events. minor fixes.
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Tue, 28 Sep 2010 18:12:13 +0000 (18:12 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Tue, 28 Sep 2010 18:12:13 +0000 (18:12 +0000)
repaired bug that caused checkin to sometimes fail when a hold
was captured for a user that had at least 1 inactive card;
made checkin override events configurable; minor cleanup

git-svn-id: svn://svn.open-ils.org/ILS/trunk@18084 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/examples/oils_sip.xml.example
Open-ILS/src/perlmods/OpenILS/SIP.pm
Open-ILS/src/perlmods/OpenILS/SIP/Patron.pm
Open-ILS/src/perlmods/OpenILS/SIP/Transaction/Checkin.pm

index 466c304..3111626 100644 (file)
                                        -->
                                </options>
 
+                <checkin_override>
+                    <event>COPY_ALERT_MESSAGE</event>
+                    <event>COPY_BAD_STATUS</event>
+                    <event>COPY_STATUS_MISSING</event>
+                    <!--
+                    <event>COPY_STATUS_LOST</event>
+                    -->
+                </checkin_override>
+
                 <!-- If uncommented, overrides the legacy_script_support value in opensrf.xml for SIP. -->
                 <!--
                 <legacy_script_support>false</legacy_script_support>
index e101e4b..d22a5e6 100644 (file)
@@ -381,7 +381,7 @@ sub checkin {
        $xact->do_checkin( $self, $inst_id, $trans_date, $return_date, $current_loc, $item_props );
        
        if ($xact->ok) {
-        $xact->patron($self->find_patron($item->{patron}));
+        $xact->patron($self->find_patron(usr => $xact->{circ_user_id})) if $xact->{circ_user_id};
         delete $item->{patron};
         delete $item->{due_date};
         syslog('LOG_INFO', "OILS: Checkin succeeded");
index fd690bf..1933a93 100644 (file)
@@ -41,7 +41,12 @@ sub new {
 
     if ($key ne 'usr' and $key ne 'barcode') {
         syslog("LOG_ERROR", "Patron (card) lookup requested by illegeal key '$key'");
-        return;
+        return undef;
+    }
+
+    unless(defined $patron_id) {
+        syslog("LOG_WARNING", "No patron ID provided to ILS::Patron->new");
+        return undef;
     }
 
     my $type = ref($class) || $class;
@@ -50,36 +55,34 @@ sub new {
     syslog("LOG_DEBUG", "OILS: new OpenILS Patron(%s => %s): searching...", $key, $patron_id);
 
     my $e = OpenILS::SIP->editor();
+    
+    my $user_id = $patron_id;
+    if($key eq 'barcode') {
+        my $card = $e->search_actor_card({barcode => $patron_id})->[0];
+        unless($card) {
+            syslog("LOG_WARNING", "No such patron barcode: $patron_id");
+            return undef;
+        }
+        $user_id = $card->usr;
+    }
 
-    my $c = $e->search_actor_card({$key => $patron_id}, {idlist=>1});
-       my $user;
-
-       if( @$c ) {
-
-               $user = $e->search_actor_user(
-                       [
-                               { card => $$c[0] },
-                               {
-                                       flesh => 2,
-                                       flesh_fields => {
-                                               "au" => [
-                                                       #"cards",
-                                                       "card",
-                                                       "standing_penalties",
-                                                       "addresses",
-                                                       "billing_address",
-                                                       "mailing_address",
-                                                       #"stat_cat_entries",
-                                                       'profile',
-                                               ],
-                        ausp => ['standing_penalty']
-                                       }
-                               }
-                       ]
-               );
-
-               $user = (@$user) ? $$user[0] : undef;
-        }
+       my $user = $e->retrieve_actor_user([
+        $user_id,
+        {
+            flesh => 2,
+            flesh_fields => {
+                au => [
+                    "card",
+                    "standing_penalties",
+                    "addresses",
+                    "billing_address",
+                    "mailing_address",
+                    'profile',
+                ],
+                ausp => ['standing_penalty']
+            }
+        }
+    ]);
 
     if(!$user) {
         syslog("LOG_WARNING", "OILS: Unable to find patron %s => %s", $key, $patron_id);
@@ -227,7 +230,7 @@ sub recall_overdue {
 sub check_password {
        my ($self, $pwd) = @_;
        syslog('LOG_DEBUG', 'OILS: Patron->check_password()');
-       return md5_hex($pwd) eq $self->{user}->passwd;
+       return $pwd and (md5_hex($pwd) eq $self->{user}->passwd);
 }
 
 
index fc7f450..c662104 100644 (file)
@@ -44,6 +44,8 @@ sub new {
 
     @{$self}{keys %fields} = values %fields;        # copying defaults into object
 
+    $self->load_override_events;
+
     return bless $self, $class;
 }
 
@@ -53,6 +55,16 @@ sub resensitize {
     return !$self->{item}->magnetic;
 }
 
+my %override_events;
+sub load_override_events {
+    return if %override_events;
+    my $override = OpenILS::SIP->config->{implementation_config}->{checkin_override};
+    return unless $override;
+    my $events = $override->{event};
+    $events = [$events] unless ref $events eq 'ARRAY';
+    $override_events{$_} = 1 for @$events;
+}
+
 my %org_sn_cache;
 sub do_checkin {
     my $self = shift;
@@ -90,24 +102,36 @@ sub do_checkin {
         $args->{circ_lib} = $phys_location = $org_id if defined $org_id;
     }
 
-    my $resp = $U->simplereq(
-        'open-ils.circ',
-        'open-ils.circ.checkin',
-        $self->{authtoken}, $args
-    );
+    my $override = 0;
+    my ($resp, $txt, $code);
 
-    if ($debug) {
-        my $s = Dumper($resp);
-        $s =~ s/\n//mog;
-        syslog('LOG_INFO', "OILS: Checkin response: $s");
-    }
+    while(1) {
+
+        my $method = 'open-ils.circ.checkin';
+        $method .= '.override' if $override;
+
+        $resp = $U->simplereq('open-ils.circ', $method, $self->{authtoken}, $args);
+
+        if ($debug) {
+            my $s = Dumper($resp);
+            $s =~ s/\n//mog;
+            syslog('LOG_INFO', "OILS: Checkin response: $s");
+        }
 
-    # In oddball cases, we can receive an array of events.
-    # The first event received should be treated as the main result.
-    $resp = $$resp[0] if ref($resp) eq 'ARRAY';
+        # In oddball cases, we can receive an array of events.
+        # The first event received should be treated as the main result.
+        $resp = $$resp[0] if ref($resp) eq 'ARRAY';
+        $code = $U->event_code($resp);
+        $txt  = (defined $code) ? $resp->{textcode} : '';
 
-    my $code = $U->event_code($resp);
-    my $txt  = (defined $code) ? $resp->{textcode} : '';
+        last if $override;
+
+        if ( $override_events{$txt} ) {
+            $override = 1;
+        } else {
+            last;
+        }
+    }
 
     syslog('LOG_INFO', "OILS: Checkin resulted in event: $txt, phys_location: $phys_location");
 
@@ -126,13 +150,21 @@ sub do_checkin {
     
     my $payload = $resp->{payload} || {};
 
-    # Two places to look for hold data.  These are more important and more definitive than above.
-    if ($payload->{remote_hold}) {
-        # actually only used for checkin at non-owning branch w/ hold at same branch
-        $self->item->hold($payload->{remote_hold});     
+    my ($circ, $copy);
+
+    if(ref $payload eq 'HASH') {
 
-    } elsif ($payload->{hold}) {
-        $self->item->hold($payload->{hold});
+        # Two places to look for hold data.  These are more important and more definitive than above.
+        if ($payload->{remote_hold}) {
+            # actually only used for checkin at non-owning branch w/ hold at same branch
+            $self->item->hold($payload->{remote_hold});     
+
+        } elsif ($payload->{hold}) {
+            $self->item->hold($payload->{hold});
+        }
+
+        $circ = $resp->{payload}->{circ} || '';
+        $copy = $resp->{payload}->{copy} || '';
     }
 
     if ($self->item->hold) {
@@ -149,10 +181,8 @@ sub do_checkin {
 
     $self->alert(1) if defined $self->alert_type;  # alert_type could be "00", hypothetically
 
-    my $circ = $resp->{payload}->{circ} || '';
-    my $copy = $resp->{payload}->{copy} || '';
-
     if ( $circ ) {
+        $self->{circ_user_id} = $circ->usr;
         $self->ok(1);
     } elsif ($txt eq 'NO_CHANGE' or $txt eq 'SUCCESS' or $txt eq 'ROUTE_ITEM') {
         $self->ok(1); # NO_CHANGE means it wasn't checked out anyway, no problem