From 66eb75981b7929181025a87b43b88595451b75c8 Mon Sep 17 00:00:00 2001 From: Lebbeous Fogle-Weekley Date: Tue, 18 Sep 2012 15:58:06 -0400 Subject: [PATCH] EDI invoices: Sometimes NAD/C082/3039 isn't buyer SAN, but EDI acct # 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 --- .../perlmods/lib/OpenILS/Application/Acq/EDI.pm | 25 ++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/EDI.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/EDI.pm index 6e9ce69d0d..c0b7db3cc4 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/EDI.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/EDI.pm @@ -644,16 +644,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}); -- 2.11.0