Acq: Fixes to new vencode parsing for incoming EDI messages
authorLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Thu, 24 Jan 2013 22:25:50 +0000 (17:25 -0500)
committerLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Tue, 5 Feb 2013 22:17:26 +0000 (17:17 -0500)
Signed-off-by: Lebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/EDI.pm

index f26e98c..962ad41 100644 (file)
@@ -493,7 +493,7 @@ sub process_message_buyer {
 
         # some vendors encode the SAN as "$SAN $vendcode"
         my $vendcode;
-        ($buyer, $vendcode) = $_ =~ /(\S+)\s*(\S+)?$/;
+        ($buyer, $vendcode) = $buyer =~ /(\S+)\s*(\S+)?$/;
 
         my $addr = $e->search_actor_org_address(
             {valid => "t", san => $buyer})->[0];
@@ -502,15 +502,15 @@ sub process_message_buyer {
 
             $eg_inv->receiver($addr->org_unit) if $eg_inv;
 
-            if (defined $vendcode) {
+            my $orig_acct = $e->retrieve_acq_edi_account($message->account);
+
+            if (defined($vendcode) and ($orig_acct->vendcode ne $vendcode)) {
                 # The vendcode can give us the opportunity to change the
                 # acq.edi_account with which our acq.edi_message is associated
                 # in case it's wrong.
 
-                my $orig_acct = $e->retrieve_acq_edi_account($message->account);
                 my $other_accounts = $e->search_acq_edi_account(
                     {
-                        id => {"!=" => $orig_acct->id},
                         vendcode => $vendcode,
                         host => $orig_acct->host,
                         username => $orig_acct->username,
@@ -520,25 +520,17 @@ sub process_message_buyer {
                 );
 
                 if (@$other_accounts) {
-                    if (@$other_accounts == 1) {
-                        # We can update this object because the caller saves
-                        # it with cstore later.
-                        $message->account($other_accounts->[0]->id);
-
-                        $logger->info(
-                            $log_prefix . sprintf(
-                                "changing edi_account from %d to %d based on " .
-                                "vendcode '%s'",
-                                $orig_acct->id, $message->account, $vendcode
-                            )
-                        );
-                    } else {
-                        $logger->info(
-                            $log_prefix .
-                            "too many matching edi_account's based on " .
-                            "vendcode $vendcode to be certain which to use"
-                        );
-                    }
+                    # We can update this object because the caller saves
+                    # it with cstore later.
+                    $message->account($other_accounts->[0]->id);
+
+                    $logger->info(
+                        $log_prefix . sprintf(
+                            "changing edi_account from %d to %d based on " .
+                            "vendcode '%s'",
+                            $orig_acct->id, $message->account, $vendcode
+                        )
+                    );
                 }
             }
 
@@ -571,9 +563,9 @@ sub process_parsed_msg {
     # ORDRSP
 
     #  First do this for the whole message...
-    my $e = new_editor;
-    $class->process_message_buyer($e, $msg_hash, $incoming, "ORDRSP processing");
-    $e->disconnect;
+    $class->process_message_buyer(
+        new_editor, $msg_hash, $incoming, "ORDRSP processing"
+    );
 
     #  ... now do this stuff per-lineitem.
     for my $li_hash (@{$msg_hash->{lineitems}}) {