Acq: When building invoices from EDI messages, avoid bad data
authorLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Tue, 16 Apr 2013 19:18:17 +0000 (15:18 -0400)
committerBen Shum <bshum@biblio.org>
Wed, 7 Aug 2013 02:57:36 +0000 (22:57 -0400)
From some vendors, these EDI messages contain strings (useless ones,
like just the name of the vendor) where we had been expecting numeric
identifiers.

Signed-off-by: Lebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Signed-off-by: Ben Shum <bshum@biblio.org>

Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/EDI.pm

index 924787a..71c6881 100644 (file)
@@ -218,11 +218,24 @@ sub process_retrieval {
         $incoming->translate_time('NOW');
 
         if ($msg_hash->{purchase_order}) {
-            $logger->info("EDI: processing message for PO " . $msg_hash->{purchase_order});
-            $incoming->purchase_order($msg_hash->{purchase_order});
-            unless ($e->retrieve_acq_purchase_order($incoming->purchase_order)) {
-                $logger->warn("EDI: received order response for nonexistent PO.  Skipping...");
-                next;
+            # Some vendors just put their name where there ought to be a number,
+            # and others put alphanumeric strings that mean nothing to us, so
+            # we sure won't match a PO in the system this way. We can pick
+            # up PO number later from the lineitems themselves if necessary.
+
+            if ($msg_hash->{purchase_order} !~ /^\d+$/) {
+                $logger->warn("EDI: PO identifier is non-numeric. Continuing.");
+                # No "next" here; we'll process this and just not link to acqpo.
+            } else {
+                $logger->info("EDI: processing message for PO " .
+                    $msg_hash->{purchase_order});
+                $incoming->purchase_order($msg_hash->{purchase_order});
+                unless ($e->retrieve_acq_purchase_order(
+                        $incoming->purchase_order)) {
+                    $logger->warn("EDI: received order response for " .
+                        "nonexistent PO.  Skipping...");
+                    next;
+                }
             }
         }