LP1952931 ASN shipment notifiation Perl Test
authorBill Erickson <berickxx@gmail.com>
Mon, 6 Dec 2021 16:01:23 +0000 (11:01 -0500)
committerBill Erickson <berickxx@gmail.com>
Tue, 4 Jan 2022 16:00:35 +0000 (11:00 -0500)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/perlmods/live_t/35-acq-asn-edi.t

index 19109f7..d5e246a 100755 (executable)
@@ -10,8 +10,14 @@ diag("Tests EDI Shipment Notifications");
 
 use constant {
     BR1_ID => 4,
-    BIB_ID => 248,
+    BR1_ADDR_ID => 4,
+    BR1_SAN => 1234567,
+    PROVIDER_SAN => 7654321,
     PROVIDER_ID => 2,
+    BIB_ID => 248,
+    LOCATION_ID => 1,
+    FUND_ID => 1,
+    ADMIN_ID => 1,
     ADMIN_USER => 'admin',
     ADMIN_PASS => 'demo123'
 };
@@ -31,18 +37,99 @@ $script->authenticate({
 
 BAIL_OUT('Failed to Login') unless $script->authtoken;
 
+sub main {
+    create_seed_data();
+    process_asn(create_po());
+}
 
-sub create_po {
+
+sub create_seed_data {
+
+    my $addr = $e->retrieve_actor_org_address(BR1_ADDR_ID);
+    $addr->san(BR1_SAN);
+
+    BAIL_OUT("Could not apply SAN to BR1 " . $e->die_event)
+        unless $e->update_actor_org_address($addr);
     
-    my $li = Fieldmapper::acq::lineitem->new;
-    $li->eg_bib_id(BIB_ID);
-    $li->marc('<record xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    xsi:schemaLocation="http://www.loc.gov/MARC21/slim http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd" xmlns="http://www.loc.gov/MARC21/slim"><leader>         a              </leader><datafield tag="020" ind1=" " ind2=" "><subfield code="a">9780307887436</subfield></record>');
-    $li->
+    my $acct = Fieldmapper::acq::edi_account->new;
+    $acct->provider(PROVIDER_ID);
+    $acct->host("example.org");
+    $acct->label("ASN TEST");
+
+    BAIL_OUT("Could not create EDI account " . $e->die_event)
+        unless $e->create_acq_edi_account($acct);
+}
+
+sub create_po {
 
     my $po = Fieldmapper::acq::purchase_order->new;
     $po->ordering_agency(BR1_ID);
     $po->provider(PROVIDER_ID);
     $po->name("ASN-Test");
+
+    my $resp = $U->simplereq('open-ils.acq', 
+        'open-ils.acq.purchase_order.create', $script->authtoken, $po);
+
+    BAIL_OUT("Failed to create PO: $resp") if $U->is_event($resp);
+    
+    my $li = Fieldmapper::acq::lineitem->new;
+    $li->purchase_order($resp->purchase_order->id);
+    $li->eg_bib_id(BIB_ID);
+    $li->marc('<record xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    xsi:schemaLocation="http://www.loc.gov/MARC21/slim http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd" xmlns="http://www.loc.gov/MARC21/slim"><leader>         a              </leader><datafield tag="020" ind1=" " ind2=" "><subfield code="a">9780307887436</subfield></record>');
+    $li->creator(ADMIN_ID);
+    $li->editor(ADMIN_ID);
+    $li->selector(ADMIN_ID);
+    $li->provider(PROVIDER_ID);
+    $li->estimated_unit_price('25.00');
+
+    my $li_id = $U->simplereq('open-ils.acq',
+        'open-ils.acq.lineitem.create', $script->authtoken, $li);
+
+    BAIL_OUT("Failed to create Lineitem: $li_id") if $U->is_event($li_id);
+
+    my $lid = Fieldmapper::acq::lineitem_detail->new;
+    $lid->lineitem($lid);
+    $lid->fund(FUND_ID);
+    $lid->owning_lib(BR1_ID);
+    $lid->location(LOCATION_ID);
+
+    $resp = $U->simplereq('open-ils.acq',
+        'open-ils.acq.lineitem_detail.cud.batch', $script->authtoken, $lid);
+
+    BAIL_OUT("Failed to create Lineitem Detail: $resp") if $U->is_event($resp);
+
+    return $$resp->purchase_order->id;
+}
+
+sub process_asn {
+    my $po_id = shift;
+
+    my $ASN = <<ASN;
+     UNA:+.?                                                                        
+     UNB+UNOC:3+7654321:31B+1234567:31B+211130:0825+99                              
+     UNG+DESADV+7654321:31B+1234567:31B+211130:0825+94+UN+D:96A:UN                  
+     UNH+193+DESADV:D:96A:UN                                                        
+     BGM+351+MOM9681366+9                                                           
+     DTM+137:20211130:102                                                           
+     DTM+11:20211130:102                                                            
+     DTM+132:20211207:102                                                           
+     RFF+BM:2036362399                                                              
+     NAD+SU+7654321::9                                                              
+     NAD+BY+1234567 0011::9                                                         
+     NAD+DP+1234567 0011::9                                                         
+     CPS+1                                                                          
+     PAC+1+5                                                                        
+     GIN+BJ+00016921002621109648                                                    
+     LIN+00001++9781643857701:EN                                                    
+     QTY+12:1                                                                       
+     RFF+ON:$po_id
+     CNT+2:1                                                                        
+     UNT+17+193                                                                     
+     UNE+1+94                                                                       
+     UNZ+1+99   
+ASN
+
 }
 
+main();