Lp 1803734: Only push on-order purchase orders in edi_order_pusher.pl.
[Evergreen.git] / Open-ILS / src / support-scripts / edi_order_pusher.pl
index 3d383f2..4aaa965 100755 (executable)
@@ -129,6 +129,7 @@ if ($po_id) {
         },
         where => {
             '+acqpo' => {
+                state => 'on-order', # on-order only
                 order_date => {'!=' => undef} # activated
             },
             '+acqpro' => {
@@ -183,6 +184,22 @@ for $po_id (@$po_ids) {
         $message->purchase_order($po_id);
         $message->message_type('ORDERS');
         $message->isnew(1);
+
+        my $po = $e->retrieve_acq_purchase_order([$po_id, {
+            flesh => 2,
+            flesh_fields => {
+                acqpo  => ['provider'],
+                acqpro => ['edi_default'],
+            }
+        }]);
+
+        if (!$po->provider->edi_default) {
+            announce('error', "Provider for PO $po_id has no default EDI ".
+                "account, EDI message will not be sent.");
+            next;
+        }
+
+        $message->account($po->provider->edi_default->id);
     }
 
     $message->edi($edi);