EDI invoices: Sometimes NAD/C082/3039 isn't buyer SAN, but EDI acct #
authorLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Tue, 18 Sep 2012 19:58:06 +0000 (15:58 -0400)
committerBill Erickson <berick@esilibrary.com>
Thu, 27 Sep 2012 18:16:43 +0000 (14:16 -0400)
Address an issue reported by Bill Erickson where a number that seems to
be buyer SAN in some cases is actually the number from
acq.edi_account.vendacct in others.

Signed-off-by: Lebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Signed-off-by: Bill Erickson <berick@esilibrary.com>
Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/EDI.pm

index 5b6e8a2..97aa7ac 100644 (file)
@@ -647,16 +647,33 @@ sub create_acq_invoice_from_edi {
     my $addrs =
         $e->search_actor_org_address({valid => "t", san => $buyer_san});
 
+    my $recv_ou;
+
     if (not $addrs or not @$addrs) {
-        $logger->error(
+        $logger->info(
             $log_prefix . "couldn't find OU unit matching buyer SAN in INVOIC:".
-            $e->event
+            $e->event->{textcode} . ", but sometimes this field might be an account " .
+            "number instead of a SAN, so we'll look for that next"
         );
-        return 0;
+
+        # Maybe "buyer SAN" is a misinterpretation of this
+        # field for (some?) vendors?
+        $addrs = $e->search_acq_edi_account({vendacct => $buyer_san});
+        if (not $addrs or not @$addrs) {
+            $logger->error(
+                $log_prefix . "could not find EDI account matching this " .
+                "number ($buyer_san) either: " . $e->event->{textcode}
+            );
+            return 0;
+        } else {
+            $recv_ou = $addrs->[0]->owner;
+        }
+    } else {
+        $recv_ou = $addrs->[0]->org_unit;
     }
 
     # XXX Should we verify that this matches PO ordering agency later?
-    $eg_inv->receiver($addrs->[0]->org_unit);
+    $eg_inv->receiver($recv_ou);
 
     try {
         $eg_inv->inv_ident($invoice->{BGM}[0]{1004});