def main(inn,out): out.put({'BOTSID':'ST','ST01':'846','ST02':out.ta_info['reference'].zfill(4)}) out.put({'BOTSID':'ST'},{'BOTSID':'BIA', 'BIA01':'08', # Status 'BIA02':'MM', # Manufacturer/Manufacturer Inventory 'BIA03': '000000', # Unused 'BIA04': transform.datemask(inn.get({'BOTSID': 'inventory'}, {'BOTSID': 'header', 'date_msg': None}),'CCYY-MM-DD HH:mm:ss','CCYYMMDD'), # Date of transaction 'BIA05': transform.datemask(inn.get({'BOTSID': 'inventory'}, {'BOTSID': 'header', 'date_msg': None}),'CCYY-MM-DD HH:mm:ss','HHmmss'), # Time of transaction }) pinn = inn.getloop({'BOTSID': 'inventory'}, {'BOTSID': 'products'}) counter = 0 for product in pinn: counter += 1 pou = out.putloop({'BOTSID':'ST'},{'BOTSID':'LIN'}) pou.put({'BOTSID':'LIN', 'LIN01':counter, # Unique within transaction 'LIN02':'SK', # Stock Keeping Unit (SKU) 'LIN03':product.get({'BOTSID': 'products', 'product_sku': None}), # Product ID }) pou.put({'BOTSID':'LIN'},{'BOTSID':'QTY', 'QTY01':'RJ', # Quantity Available On Shelf 'QTY02':product.get({'BOTSID': 'products', 'quantity': None}), # Quantity 'QTY03':'EA', # Each }) out.put({'BOTSID':'ST'},{'BOTSID':'CTT', 'CTT01':counter, }) out.put({'BOTSID':'ST'},{'BOTSID':'SE', 'SE01':out.getcount()+1, #SE01: bots counts the segments produced in the X12 message. 'SE02':out.ta_info['reference'].zfill(4), })
def testdatemask(self): self.assertEqual( u'20121231', transform.datemask('12/31/2012', 'MM/DD/YYYY', 'YYYYMMDD'), 'test datemask') self.assertEqual( u'201231', transform.datemask('12/31/2012', 'MM/DD/YYYY', 'YYMMDD'), 'test datemask')
def testdatemask(self): self.assertEqual( "20121231", transform.datemask("12/31/2012", "MM/DD/YYYY", "YYYYMMDD"), "test datemask", ) self.assertEqual( "201231", transform.datemask("12/31/2012", "MM/DD/YYYY", "YYMMDD"), "test datemask", )
def main(inn,out): #sender, receiver is correct via QUERIES in grammar. out.put({'BOTSID':'ST','ST01':'810','ST02':out.ta_info['reference'].zfill(4)}) INV_REF = re.sub(r'[^a-zA-Z0-9 ]', r'', inn.get({'BOTSID':'invoice'},{'BOTSID':'invoices','ref':None}) or "") SALE_REF = inn.get({'BOTSID':'invoice'},{'BOTSID':'invoices','sale':None}) or "" DATE_INV = transform.datemask(inn.get({'BOTSID':'invoice'},{'BOTSID':'invoices','date':None}),'CCYY-MM-DD','CCYYMMDD') DATE_SALE = transform.datemask(inn.get({'BOTSID':'invoice'},{'BOTSID':'invoices','sale_date':None}),'CCYY-MM-DD HH:mm','CCYYMMDD') out.put({'BOTSID':'ST'},{'BOTSID':'BIG','BIG01': DATE_INV}) out.put({'BOTSID':'ST'},{'BOTSID':'BIG','BIG02': INV_REF}) out.put({'BOTSID':'ST'},{'BOTSID':'BIG','BIG03': DATE_SALE}) out.put({'BOTSID':'ST'},{'BOTSID':'BIG','BIG04': SALE_REF}) # DTM01:011 is "ship date" out.put({'BOTSID':'ST'},{'BOTSID':'DTM','DTM01':'011','DTM02': DATE_SALE}) # Partner pou = out.putloop({'BOTSID':'ST'},{'BOTSID':'N1'}) pou.put({'BOTSID':'N1','N101': 'ST'}) pou.put({'BOTSID':'N1','N102':inn.get({'BOTSID':'invoice'},{'BOTSID':'invoices'},{'BOTSID':'partner','name':None})}) #pou.put({'BOTSID':'N1'},{'BOTSID':'N2','N201':''}) # No name2 pou.put({'BOTSID':'N1'},{'BOTSID':'N3','N301':inn.get({'BOTSID':'invoice'},{'BOTSID':'invoices'},{'BOTSID':'partner','street1':None})}) pou.put({'BOTSID':'N1'},{'BOTSID':'N3','N302':inn.get({'BOTSID':'invoice'},{'BOTSID':'invoices'},{'BOTSID':'partner','street2':None})}) pou.put({'BOTSID':'N1'},{'BOTSID':'N4','N401':inn.get({'BOTSID':'invoice'},{'BOTSID':'invoices'},{'BOTSID':'partner','city':None})}) pou.put({'BOTSID':'N1'},{'BOTSID':'N4','N402':inn.get({'BOTSID':'invoice'},{'BOTSID':'invoices'},{'BOTSID':'partner','state':None})}) pou.put({'BOTSID':'N1'},{'BOTSID':'N4','N403':inn.get({'BOTSID':'invoice'},{'BOTSID':'invoices'},{'BOTSID':'partner','zip':None})}) pou.put({'BOTSID':'N1'},{'BOTSID':'N4','N404':inn.get({'BOTSID':'invoice'},{'BOTSID':'invoices'},{'BOTSID':'partner','country':None})}) #loop over lines*************************************** for lin in inn.getloop({'BOTSID':'invoice'},{'BOTSID':'invoices'},{'BOTSID':'lines'}): lou = out.putloop({'BOTSID':'ST'},{'BOTSID':'IT1'}) lou.put({'BOTSID':'IT1','IT101':lin.get({'BOTSID':'lines','seq':None})}) lou.put({'BOTSID':'IT1','IT103':'EA','IT102':lin.get({'BOTSID':'lines','product_qty':None})}) lou.put({'BOTSID':'IT1','IT104':lin.get({'BOTSID':'lines','total':None})}) lou.put({'BOTSID':'IT1','IT106':'SK','IT107':lin.get({'BOTSID':'lines','product_sku':None})}) lou.put({'BOTSID':'IT1','IT108':'SK','IT109':lin.get({'BOTSID':'lines','product_sku':None})}) lou.put({'BOTSID':'IT1','IT110':'SK','IT111':lin.get({'BOTSID':'lines','product_sku':None})}) out.put({'BOTSID':'ST'},{'BOTSID':'TDS','TDS01':inn.get({'BOTSID':'invoice'},{'BOTSID':'invoices','total':None})}) out.put({'BOTSID':'ST'},{'BOTSID':'ISS','ISS02':'EA','ISS01':out.getcountsum({'BOTSID':'ST'},{'BOTSID':'IT1','IT102':None}) }) #bots counts total Number of Units Shipped out.put({'BOTSID':'ST'},{'BOTSID':'CTT','CTT01':out.getcountoccurrences({'BOTSID':'ST'},{'BOTSID':'IT1'}) }) #bots counts number of line items/IT1 segments out.put({'BOTSID':'ST'},{'BOTSID':'SE','SE01':out.getcount()+1,'SE02':out.ta_info['reference'].zfill(4)}) #SE01: bots counts the segments produced in the X12 message.
def main(inn, out): # Set Constants D = 'urn:oasis:names:specification:ubl:schema:xsd:Order-2' S = 'urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2' B = 'urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2' E = 'urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2' UBLVersionID = "2.1" CustomizationID = "LDC" ProfileID_Content = "Basic-v1.0" ProfileID_Agency = "LDC" ProfileID_Identifier = "Profile" ProfileExecutionID = "Basic-Order" now = datetime.utcnow() out.put({'BOTSID': 'ROOT', '_D': D}) out.put({'BOTSID': 'ROOT', '_S': S}) out.put({'BOTSID': 'ROOT', '_B': B}) out.put({'BOTSID': 'ROOT', '_E': E}) out.put({'BOTSID': 'ROOT'}, {'BOTSID': 'Order'}, { 'BOTSID': 'UBLVersionID', 'IdentifierContent': UBLVersionID }) out.put({'BOTSID': 'ROOT'}, {'BOTSID': 'Order'}, { 'BOTSID': 'CustomizationID', 'IdentifierContent': CustomizationID }) out.put({'BOTSID': 'ROOT'}, {'BOTSID': 'Order'}, { 'BOTSID': 'ProfileID', 'IdentifierContent': ProfileID_Content }) out.put({'BOTSID': 'ROOT'}, {'BOTSID': 'Order'}, { 'BOTSID': 'ProfileID', 'IdentificationSchemeAgencyIdentifier': ProfileID_Agency }) out.put({'BOTSID': 'ROOT'}, {'BOTSID': 'Order'}, { 'BOTSID': 'ProfileID', 'IdentificationSchemeIdentifier': ProfileID_Identifier }) out.put({'BOTSID': 'ROOT'}, {'BOTSID': 'Order'}, { 'BOTSID': 'ProfileExecutionID', 'IdentifierContent': ProfileExecutionID }) UBLExtensionLoop1 = out.putloop({'BOTSID': 'ROOT'}, {'BOTSID': 'Order'}, {'BOTSID': 'UBLExtensions'}, {'BOTSID': 'UBLExtension'}) UBLExtensionLoop2 = out.putloop({'BOTSID': 'ROOT'}, {'BOTSID': 'Order'}, {'BOTSID': 'UBLExtensions'}, {'BOTSID': 'UBLExtension'}) UBLExtensionLoop1.put({'BOTSID': 'UBLExtension'}, { 'BOTSID': 'Name', 'TextContent': "Loren Data Transport" }) UBLExtensionLoop1.put({'BOTSID': 'UBLExtension'}, { 'BOTSID': 'ExtensionReason', 'TextContent': "Aggregate extension component containing information for the Loren Data transport values." }) UBLExtensionLoop1.put({'BOTSID': 'UBLExtension'}, {'BOTSID': 'ExtensionContent'}, {'BOTSID': 'LorenDataTransport'}, { 'BOTSID': 'ParcelID', 'IdentifierContent': "" }) UBLExtensionLoop1.put({'BOTSID': 'UBLExtension'}, {'BOTSID': 'ExtensionContent'}, {'BOTSID': 'LorenDataTransport'}, { 'BOTSID': 'NetworkIDFrom', 'IdentifierContent': "" }) UBLExtensionLoop1.put({'BOTSID': 'UBLExtension'}, {'BOTSID': 'ExtensionContent'}, {'BOTSID': 'LorenDataTransport'}, { 'BOTSID': 'NetworkIDFrom', 'IdentificationSchemeNameText': "" }) UBLExtensionLoop1.put({'BOTSID': 'UBLExtension'}, {'BOTSID': 'ExtensionContent'}, {'BOTSID': 'LorenDataTransport'}, { 'BOTSID': 'NetworkIDTo', 'IdentifierContent': "" }) UBLExtensionLoop1.put({'BOTSID': 'UBLExtension'}, {'BOTSID': 'ExtensionContent'}, {'BOTSID': 'LorenDataTransport'}, { 'BOTSID': 'NetworkIDTo', 'IdentificationSchemeNameText': "" }) UBLExtensionLoop1.put({'BOTSID': 'UBLExtension'}, {'BOTSID': 'ExtensionContent'}, {'BOTSID': 'LorenDataTransport'}, { 'BOTSID': 'MailboxIDFrom', 'IdentifierContent': "" }) UBLExtensionLoop1.put({'BOTSID': 'UBLExtension'}, {'BOTSID': 'ExtensionContent'}, {'BOTSID': 'LorenDataTransport'}, { 'BOTSID': 'MailboxIDFrom', 'IdentificationSchemeNameText': "" }) UBLExtensionLoop1.put({'BOTSID': 'UBLExtension'}, {'BOTSID': 'ExtensionContent'}, {'BOTSID': 'LorenDataTransport'}, { 'BOTSID': 'MailboxIDTo', 'IdentifierContent': "" }) UBLExtensionLoop1.put({'BOTSID': 'UBLExtension'}, {'BOTSID': 'ExtensionContent'}, {'BOTSID': 'LorenDataTransport'}, { 'BOTSID': 'MailboxIDTo', 'IdentificationSchemeNameText': "" }) UBLExtensionLoop1.put({'BOTSID': 'UBLExtension'}, {'BOTSID': 'ExtensionContent'}, {'BOTSID': 'LorenDataTransport'}, { 'BOTSID': 'ECGridIDFrom', 'IdentifierContent': "" }) UBLExtensionLoop1.put({'BOTSID': 'UBLExtension'}, {'BOTSID': 'ExtensionContent'}, {'BOTSID': 'LorenDataTransport'}, { 'BOTSID': 'ECGridIDFrom', 'IdentificationSchemeNameText': "" }) UBLExtensionLoop1.put({'BOTSID': 'UBLExtension'}, {'BOTSID': 'ExtensionContent'}, {'BOTSID': 'LorenDataTransport'}, { 'BOTSID': 'ECGridIDTo', 'IdentifierContent': "" }) UBLExtensionLoop1.put({'BOTSID': 'UBLExtension'}, {'BOTSID': 'ExtensionContent'}, {'BOTSID': 'LorenDataTransport'}, { 'BOTSID': 'ECGridIDTo', 'IdentificationSchemeNameText': "" }) UBLExtensionLoop1.put({'BOTSID': 'UBLExtension'}, {'BOTSID': 'ExtensionContent'}, {'BOTSID': 'LorenDataTransport'}, { 'BOTSID': 'ElectronicMailFrom', 'TextContent': "" }) UBLExtensionLoop1.put({'BOTSID': 'UBLExtension'}, {'BOTSID': 'ExtensionContent'}, {'BOTSID': 'LorenDataTransport'}, { 'BOTSID': 'ElectronicMailTo', 'TextContent': "" }) UBLExtensionLoop2.put({'BOTSID': 'UBLExtension'}, { 'BOTSID': 'Name', 'TextContent': "Document Envelope" }) UBLExtensionLoop2.put({'BOTSID': 'UBLExtension'}, { 'BOTSID': 'ExtensionReason', 'TextContent': "Aggregate extention component containing information for the document envelope used for translation." }) UBLExtensionLoop2.put({'BOTSID': 'UBLExtension'}, {'BOTSID': 'ExtensionContent'}, {'BOTSID': 'DocumentEnvelope'}, { 'BOTSID': 'ID', 'IdentifierContent': inn.ta_info['ISA13'] }) UBLExtensionLoop2.put({'BOTSID': 'UBLExtension'}, {'BOTSID': 'ExtensionContent'}, {'BOTSID': 'DocumentEnvelope'}, { 'BOTSID': 'ID', 'IdentificationSchemeNameText': "ISA" }) UBLExtensionLoop2.put({'BOTSID': 'UBLExtension'}, {'BOTSID': 'ExtensionContent'}, {'BOTSID': 'DocumentEnvelope'}, { 'BOTSID': 'CopyIndicator', 'IdentifierContent': inn.ta_info['ISA15'] }) UBLExtensionLoop2.put({'BOTSID': 'UBLExtension'}, {'BOTSID': 'ExtensionContent'}, {'BOTSID': 'DocumentEnvelope'}, { 'BOTSID': 'UUID', 'IdentifierContent': "" }) UBLExtensionLoop2.put({'BOTSID': 'UBLExtension'}, {'BOTSID': 'ExtensionContent'}, {'BOTSID': 'DocumentEnvelope'}, {'BOTSID': 'SenderParty'}, {'BOTSID': 'PartyIdentification'}, { 'BOTSID': 'ID', 'IdentifierContent': inn.ta_info['frompartner'] }) UBLExtensionLoop2.put( {'BOTSID': 'UBLExtension'}, {'BOTSID': 'ExtensionContent'}, {'BOTSID': 'DocumentEnvelope'}, {'BOTSID': 'SenderParty'}, {'BOTSID': 'PartyIdentification'}, { 'BOTSID': 'ID', 'IdentificationSchemeNameText': inn.ta_info['ISA05'] }) UBLExtensionLoop2.put({'BOTSID': 'UBLExtension'}, {'BOTSID': 'ExtensionContent'}, {'BOTSID': 'DocumentEnvelope'}, {'BOTSID': 'ReceiverParty'}, {'BOTSID': 'PartyIdentification'}, { 'BOTSID': 'ID', 'IdentifierContent': inn.ta_info['topartner'] }) UBLExtensionLoop2.put( {'BOTSID': 'UBLExtension'}, {'BOTSID': 'ExtensionContent'}, {'BOTSID': 'DocumentEnvelope'}, {'BOTSID': 'ReceiverParty'}, {'BOTSID': 'PartyIdentification'}, { 'BOTSID': 'ID', 'IdentificationSchemeNameText': inn.ta_info['ISA07'] }) UBLExtensionLoop2.put( {'BOTSID': 'UBLExtension'}, {'BOTSID': 'ExtensionContent'}, {'BOTSID': 'DocumentEnvelope'}, { 'BOTSID': 'IssueDate', 'DateContent': now.strftime('%Y') + transform.datemask(inn.ta_info['ISA09'], "YYmmDD", "-mm-DD") }) UBLExtensionLoop2.put( {'BOTSID': 'UBLExtension'}, {'BOTSID': 'ExtensionContent'}, {'BOTSID': 'DocumentEnvelope'}, { 'BOTSID': 'IssueTime', 'TimeContent': transform.datemask(inn.ta_info['ISA10'], "0000", "00:00") }) UBLExtensionLoop2.put({'BOTSID': 'UBLExtension'}, {'BOTSID': 'ExtensionContent'}, {'BOTSID': 'DocumentEnvelope'}, { 'BOTSID': 'SpecificationID', 'IdentifierContent': inn.ta_info['GS06'] }) UBLExtensionLoop2.put({'BOTSID': 'UBLExtension'}, {'BOTSID': 'ExtensionContent'}, {'BOTSID': 'DocumentEnvelope'}, { 'BOTSID': 'SpecificationID', 'IdentificationSchemeNameText': "GS" }) UBLExtensionLoop2.put({'BOTSID': 'UBLExtension'}, {'BOTSID': 'ExtensionContent'}, {'BOTSID': 'DocumentEnvelope'}, { 'BOTSID': 'AgencyID', 'IdentifierContent': inn.ta_info['GS07'] }) UBLExtensionLoop2.put({'BOTSID': 'UBLExtension'}, {'BOTSID': 'ExtensionContent'}, {'BOTSID': 'DocumentEnvelope'}, { 'BOTSID': 'VersionID', 'IdentifierContent': inn.ta_info['version'] }) UBLExtensionLoop2.put({'BOTSID': 'UBLExtension'}, {'BOTSID': 'ExtensionContent'}, {'BOTSID': 'DocumentEnvelope'}, { 'BOTSID': 'DocumentType', 'TextContent': inn.ta_info['ST01'] }) UBLExtensionLoop2.put({'BOTSID': 'UBLExtension'}, {'BOTSID': 'ExtensionContent'}, {'BOTSID': 'DocumentEnvelope'}, { 'BOTSID': 'SequenceNumberID', 'IdentifierContent': inn.ta_info['reference'] }) UBLExtensionLoop2.put({'BOTSID': 'UBLExtension'}, {'BOTSID': 'ExtensionContent'}, {'BOTSID': 'DocumentEnvelope'}, { 'BOTSID': 'SequenceNumberID', 'IdentificationSchemeNameText': "ST" }) UBLExtensionLoop2.put({'BOTSID': 'UBLExtension'}, {'BOTSID': 'ExtensionContent'}, {'BOTSID': 'DocumentEnvelope'}, {'BOTSID': 'Status'}, { 'BOTSID': 'TextConent', 'TextContent': "New" }) UBLExtensionLoop2.put({'BOTSID': 'UBLExtension'}, {'BOTSID': 'ExtensionContent'}, {'BOTSID': 'DocumentEnvelope'}, {'BOTSID': 'Status'}, { 'BOTSID': 'ReferenceDate', 'DateContent': now.strftime('%Y-%m-%d') }) UBLExtensionLoop2.put({'BOTSID': 'UBLExtension'}, {'BOTSID': 'ExtensionContent'}, {'BOTSID': 'DocumentEnvelope'}, {'BOTSID': 'Status'}, { 'BOTSID': 'ReferenceTime', 'TimeContent': now.strftime('%H:%M:%S') }) # BEG Segment purpose_code = inn.get({'BOTSID': 'ST'}, {'BOTSID': 'BEG', 'BEG01': None}) purpose_code_text = transform.ccode('X12_ELEM_353_TO_TEXT', purpose_code) ordertype_code = inn.get({'BOTSID': 'ST'}, { 'BOTSID': 'BEG', 'BEG02': None }) ordertype_code_text = transform.ccode('X12_ELEM_92_TO_TEXT', ordertype_code) order_number = inn.get({'BOTSID': 'ST'}, {'BOTSID': 'BEG', 'BEG03': None}) out.ta_info['botskey'] = order_number order_date = inn.get({'BOTSID': 'ST'}, {'BOTSID': 'BEG', 'BEG05': None}) contract_number = inn.get({'BOTSID': 'ST'}, { 'BOTSID': 'BEG', 'BEG06': None }) out.put({'BOTSID': 'ROOT'}, {'BOTSID': 'Order'}, { 'BOTSID': 'PurposeCode', 'CodeContent': purpose_code }) out.put({'BOTSID': 'ROOT'}, {'BOTSID': 'Order'}, { 'BOTSID': 'PurposeCode', 'CodeNameText': purpose_code_text }) out.put({'BOTSID': 'ROOT'}, {'BOTSID': 'Order'}, { 'BOTSID': 'OrderTypeCode', 'CodeContent': ordertype_code }) out.put({'BOTSID': 'ROOT'}, {'BOTSID': 'Order'}, { 'BOTSID': 'OrderTypeCode', 'CodeNameText': ordertype_code_text }) out.put({'BOTSID': 'ROOT'}, {'BOTSID': 'Order'}, { 'BOTSID': 'ID', 'IdentifierContent': order_number }) out.put( {'BOTSID': 'ROOT'}, {'BOTSID': 'Order'}, { 'BOTSID': 'IssueDate', 'DateContent': transform.datemask(order_date, 'YYYYmmDD', 'mm/DD/YYYY') }) out.put({'BOTSID': 'ROOT'}, {'BOTSID': 'Order'}, {'BOTSID': 'Contract'}, { 'BOTSID': 'ID', 'IdentifierContent': contract_number }) # REF Segment EstimatedDeliveryDateQual = inn.get({'BOTSID': 'ST'}, { 'BOTSID': 'DTM', 'DTM01': None }) EstimatedDeliveryDate = inn.get({'BOTSID': 'ST'}, { 'BOTSID': 'DTM', 'DTM01': '017', 'DTM02': None }) if EstimatedDeliveryDateQual != '': out.put({'BOTSID': 'ROOT'}, {'BOTSID': 'Order'}, {'BOTSID': 'Delivery'}, {'BOTSID': 'RequestedDeliveryPeriod'}, { 'BOTSID': 'StartDate', 'DateContent': transform.datemask(EstimatedDeliveryDate, 'YYYYmmDD', 'mm/DD/YYYY') }) out.put({'BOTSID': 'ROOT'}, {'BOTSID': 'Order'}, {'BOTSID': 'Delivery'}, {'BOTSID': 'RequestedDeliveryPeriod'}, { 'BOTSID': 'DescriptionCode', 'CodeContent': '017' }) out.put({'BOTSID': 'ROOT'}, {'BOTSID': 'Order'}, {'BOTSID': 'Delivery'}, {'BOTSID': 'RequestedDeliveryPeriod'}, { 'BOTSID': 'DescriptionCode', 'CodeNameText': 'Estimated Delivery Date' }) # TD5 Segment SCAC = inn.get({'BOTSID': 'ST'}, { 'BOTSID': 'TD5', 'TD502': '2', 'TD503': None }) CarrierName = inn.get({'BOTSID': 'ST'}, {'BOTSID': 'TD5', 'TD505': None}) out.put({'BOTSID': 'ROOT'}, {'BOTSID': 'Order'}, {'BOTSID': 'Delivery'}, {'BOTSID': 'CarrierParty'}, {'BOTSID': 'PartyIdentification'}, { 'BOTSID': 'ID', 'IdentifierContent': SCAC }) out.put({'BOTSID': 'ROOT'}, {'BOTSID': 'Order'}, {'BOTSID': 'Delivery'}, {'BOTSID': 'CarrierParty'}, {'BOTSID': 'PartyName'}, { 'BOTSID': 'Name', 'TextContent': CarrierName }) # N1 Loops for party in inn.getloop({'BOTSID': 'ST'}, {'BOTSID': 'N1'}): PartyQual = party.get({'BOTSID': 'N1', 'N101': None}) PartyName = party.get({'BOTSID': 'N1', 'N102': None}) PartyAgency = party.get({'BOTSID': 'N1', 'N103': None}) PartyNumber = party.get({'BOTSID': 'N1', 'N104': None}) PartyAddress1 = party.get({'BOTSID': 'N1'}, { 'BOTSID': 'N3', 'N301': None }) PartyAddress2 = party.get({'BOTSID': 'N1'}, { 'BOTSID': 'N3', 'N302': None }) PartyCity = party.get({'BOTSID': 'N1'}, {'BOTSID': 'N4', 'N401': None}) PartyCountrySubentity = party.get({'BOTSID': 'N1'}, { 'BOTSID': 'N4', 'N402': None }) PartyPostal = party.get({'BOTSID': 'N1'}, { 'BOTSID': 'N4', 'N403': None }) PartyCountry = party.get({'BOTSID': 'N1'}, { 'BOTSID': 'N4', 'N404': None }) if PartyQual == 'BT': out.put({'BOTSID': 'ROOT'}, {'BOTSID': 'Order'}, {'BOTSID': 'BuyerCustomerParty'}, {'BOTSID': 'Party'}, { 'BOTSID': 'PartyIdentification', 'IdentifierContent': PartyNumber }) out.put({'BOTSID': 'ROOT'}, {'BOTSID': 'Order'}, {'BOTSID': 'BuyerCustomerParty'}, {'BOTSID': 'Party'}, { 'BOTSID': 'PartyIdentification', 'IdentificationSchemeIdentifier': PartyQual }) out.put({'BOTSID': 'ROOT'}, {'BOTSID': 'Order'}, {'BOTSID': 'BuyerCustomerParty'}, {'BOTSID': 'Party'}, { 'BOTSID': 'PartyIdentification', 'IdentificationSchemeAgencyIdentifier': PartyAgency }) out.put({'BOTSID': 'ROOT'}, {'BOTSID': 'Order'}, {'BOTSID': 'BuyerCustomerParty'}, {'BOTSID': 'Party'}, {'BOTSID': 'PartyName'}, { 'BOTSID': 'Name', 'TextContent': PartyName }) out.put({'BOTSID': 'ROOT'}, {'BOTSID': 'Order'}, {'BOTSID': 'BuyerCustomerParty'}, {'BOTSID': 'Party'}, {'BOTSID': 'PostalAddress'}, { 'BOTSID': 'StreetName', 'TextContent': PartyAddress1 }) out.put({'BOTSID': 'ROOT'}, {'BOTSID': 'Order'}, {'BOTSID': 'BuyerCustomerParty'}, {'BOTSID': 'Party'}, {'BOTSID': 'PostalAddress'}, { 'BOTSID': 'AdditionalStreetName', 'TextContent': PartyAddress2 }) out.put({'BOTSID': 'ROOT'}, {'BOTSID': 'Order'}, {'BOTSID': 'BuyerCustomerParty'}, {'BOTSID': 'Party'}, {'BOTSID': 'PostalAddress'}, { 'BOTSID': 'CityName', 'TextContent': PartyCity }) out.put({'BOTSID': 'ROOT'}, {'BOTSID': 'Order'}, {'BOTSID': 'BuyerCustomerParty'}, {'BOTSID': 'Party'}, {'BOTSID': 'PostalAddress'}, { 'BOTSID': 'PostalZone', 'TextContent': PartyPostal }) out.put({'BOTSID': 'ROOT'}, {'BOTSID': 'Order'}, {'BOTSID': 'BuyerCustomerParty'}, {'BOTSID': 'Party'}, {'BOTSID': 'PostalAddress'}, { 'BOTSID': 'CountrySubentity', 'TextContent': PartyCountrySubentity }) out.put({'BOTSID': 'ROOT'}, {'BOTSID': 'Order'}, {'BOTSID': 'BuyerCustomerParty'}, {'BOTSID': 'Party'}, {'BOTSID': 'PostalAddress'}, {'BOTSID': 'Country'}, { 'BOTSID': 'IdentificationCode', 'CodeContent': PartyCountry[:-1] }) elif PartyQual == 'ST': out.put({'BOTSID': 'ROOT'}, {'BOTSID': 'Order'}, {'BOTSID': 'Delivery'}, {'BOTSID': 'DeliveryAddress'}, { 'BOTSID': 'ID', 'IdentifierContent': PartyNumber }) out.put({'BOTSID': 'ROOT'}, {'BOTSID': 'Order'}, {'BOTSID': 'Delivery'}, {'BOTSID': 'DeliveryAddress'}, { 'BOTSID': 'ID', 'IdentificationSchemeIdentifier': PartyQual }) out.put({'BOTSID': 'ROOT'}, {'BOTSID': 'Order'}, {'BOTSID': 'Delivery'}, {'BOTSID': 'DeliveryAddress'}, { 'BOTSID': 'ID', 'IdentificationSchemeAgencyIdentifier': PartyAgency }) out.put({'BOTSID': 'ROOT'}, {'BOTSID': 'Order'}, {'BOTSID': 'Delivery'}, {'BOTSID': 'DeliveryAddress'}, { 'BOTSID': 'BuildingName', 'TextContent': PartyName }) out.put({'BOTSID': 'ROOT'}, {'BOTSID': 'Order'}, {'BOTSID': 'Delivery'}, {'BOTSID': 'DeliveryAddress'}, { 'BOTSID': 'StreetName', 'TextContent': PartyAddress1 }) out.put({'BOTSID': 'ROOT'}, {'BOTSID': 'Order'}, {'BOTSID': 'Delivery'}, {'BOTSID': 'DeliveryAddress'}, { 'BOTSID': 'AdditionalStreetName', 'TextContent': PartyAddress2 }) out.put({'BOTSID': 'ROOT'}, {'BOTSID': 'Order'}, {'BOTSID': 'Delivery'}, {'BOTSID': 'DeliveryAddress'}, { 'BOTSID': 'CityName', 'TextContent': PartyCity }) out.put({'BOTSID': 'ROOT'}, {'BOTSID': 'Order'}, {'BOTSID': 'Delivery'}, {'BOTSID': 'DeliveryAddress'}, { 'BOTSID': 'PostalZone', 'TextContent': PartyPostal }) out.put({'BOTSID': 'ROOT'}, {'BOTSID': 'Order'}, {'BOTSID': 'Delivery'}, {'BOTSID': 'DeliveryAddress'}, { 'BOTSID': 'CountrySubentity', 'TextContent': PartyCountrySubentity }) out.put({'BOTSID': 'ROOT'}, {'BOTSID': 'Order'}, {'BOTSID': 'Delivery'}, {'BOTSID': 'DeliveryAddress'}, {'BOTSID': 'Country'}, { 'BOTSID': 'IdentificationCode', 'CodeContent': PartyCountry[:-1] }) # PO1 Loops for po1 in inn.getloop({'BOTSID': 'ST'}, {'BOTSID': 'PO1'}): # Out Object Array orderLineOut = out.putloop({'BOTSID': 'ROOT'}, {'BOTSID': 'Order'}, {'BOTSID': 'OrderLine'}) # Get Values LineNumber = po1.get({'BOTSID': 'PO1', 'PO101': None}) # Get UOM, if empty use 'EA' X12_UOM = transform.useoneof(po1.get({ 'BOTSID': 'PO1', 'PO103': None }), 'EA') ISO_UOM = transform.ccode('X12_ELEM_355_TO_ISO_UOM', X12_UOM) QuantityOrdered = po1.get({'BOTSID': 'PO1', 'PO102': None}) X12_PriceCode = transform.useoneof( po1.get({ 'BOTSID': 'PO1', 'PO105': None }), 'PE') ISO_PriceCode = transform.ccode('X12_ELEM_639_TO_ISO_PRICETYPE', X12_PriceCode) ISO_PriceCode_Text = transform.ccode('ISO_PRICETYPE_TO_TEXT', ISO_PriceCode) UnitPrice = po1.get({'BOTSID': 'PO1', 'PO104': None}) # Get Item Values by Qualifier BuyerItem = get_item_number_by_qual(po1, 'SK') SellerItem = get_item_number_by_qual(po1, 'CB') UPC = get_item_number_by_qual(po1, 'UP') Description = po1.get({'BOTSID': 'PO1'}, { 'BOTSID': 'PID', 'PID01': 'F', 'PID05': None }) # Write output orderLineOut.put({'BOTSID': 'OrderLine'}, {'BOTSID': 'LineItem'}, { 'BOTSID': 'ID', 'IdentifierContent': LineNumber }) orderLineOut.put({'BOTSID': 'OrderLine'}, {'BOTSID': 'LineItem'}, { 'BOTSID': 'Quantity', 'QuantityContent': QuantityOrdered }) orderLineOut.put({'BOTSID': 'OrderLine'}, {'BOTSID': 'LineItem'}, { 'BOTSID': 'Quantity', 'QuantityUnitCode': ISO_UOM }) orderLineOut.put({'BOTSID': 'OrderLine'}, {'BOTSID': 'LineItem'}, {'BOTSID': 'Price'}, { 'BOTSID': 'PriceAmount', 'AmountContent': UnitPrice }) orderLineOut.put({'BOTSID': 'OrderLine'}, {'BOTSID': 'LineItem'}, {'BOTSID': 'Price'}, { 'BOTSID': 'PriceTypeCode', 'CodeContent': ISO_PriceCode }) orderLineOut.put({'BOTSID': 'OrderLine'}, {'BOTSID': 'LineItem'}, {'BOTSID': 'Price'}, { 'BOTSID': 'PriceTypeCode', 'CodeNameText': ISO_PriceCode_Text }) orderLineOut.put( {'BOTSID': 'OrderLine'}, {'BOTSID': 'LineItem'}, { 'BOTSID': 'LineExtensionAmount', 'AmountContent': Decimal(UnitPrice) * Decimal(QuantityOrdered) }) orderLineOut.put({'BOTSID': 'OrderLine'}, {'BOTSID': 'LineItem'}, {'BOTSID': 'Item'}, {'BOTSID': 'BuyersItemIdentification'}, { 'BOTSID': 'ID', 'IdentifierContent': BuyerItem }) orderLineOut.put({'BOTSID': 'OrderLine'}, {'BOTSID': 'LineItem'}, {'BOTSID': 'Item'}, {'BOTSID': 'BuyersItemIdentification'}, { 'BOTSID': 'ID', 'IdentificationSchemeIdentifier': '' }) orderLineOut.put({'BOTSID': 'OrderLine'}, {'BOTSID': 'LineItem'}, {'BOTSID': 'Item'}, {'BOTSID': 'SellersItemIdentification'}, { 'BOTSID': 'ID', 'IdentifierContent': SellerItem }) orderLineOut.put({'BOTSID': 'OrderLine'}, {'BOTSID': 'LineItem'}, {'BOTSID': 'Item'}, {'BOTSID': 'StandardItemIdentification'}, { 'BOTSID': 'ID', 'IdentifierContent': UPC }) orderLineOut.put({'BOTSID': 'OrderLine'}, {'BOTSID': 'LineItem'}, {'BOTSID': 'Item'}, {'BOTSID': 'StandardItemIdentification'}, { 'BOTSID': 'ID', 'IdentificationSchemeIdentifier': 'UPC' }) orderLineOut.put({'BOTSID': 'OrderLine'}, {'BOTSID': 'LineItem'}, {'BOTSID': 'Item'}, { 'BOTSID': 'Description', 'TextContent': Description }) # CTT Segment CTT = inn.get({'BOTSID': 'ST'}, {'BOTSID': 'CTT', 'CTT01': None}) out.put({'BOTSID': 'ROOT'}, {'BOTSID': 'Order'}, { 'BOTSID': 'LineCountNumeric', 'NumericContent': CTT })
def main(inn, out): #pick up some values from ISA envelope out.put({'BOTSID': 'message', 'sender': inn.ta_info['frompartner']}) out.put({'BOTSID': 'message', 'receiver': inn.ta_info['topartner']}) out.put({ 'BOTSID': 'message', 'testindicator': inn.ta_info['testindicator'] }) out.put({ 'BOTSID': 'message', 'docdtm': transform.datemask( inn.get({'BOTSID': 'ST'}, { 'BOTSID': 'BIG', 'BIG01': None }), 'CCYYMMDD', 'CCYY-MM-DD') }) out.put({ 'BOTSID': 'message', 'docnum': inn.get({'BOTSID': 'ST'}, { 'BOTSID': 'BIG', 'BIG02': None }) }) out.put({ 'BOTSID': 'message', 'ordernumber': inn.get({'BOTSID': 'ST'}, { 'BOTSID': 'BIG', 'BIG04': None }) }) #~ out.put({'BOTSID':'ST'},{'BOTSID':'BIG','BIG07':'DR'}) #credit or debit out.put({ 'BOTSID': 'message', 'deldtm': transform.datemask( inn.get({'BOTSID': 'ST'}, { 'BOTSID': 'DTM', 'DTM01': '999', 'DTM02': None }), 'CCYYMMDD', 'CCYY-MM-DD') }) out.put({ 'BOTSID': 'message', 'VendorID': inn.get({'BOTSID': 'ST'}, { 'BOTSID': 'REF', 'REF01': 'VR', 'REF02': None }) }) out.put({ 'BOTSID': 'message', 'termsdiscountpercent': inn.get({'BOTSID': 'ST'}, { 'BOTSID': 'ITD', 'ITD03': None }) }) out.put({ 'BOTSID': 'message', 'termsdiscountdaysdue': inn.get({'BOTSID': 'ST'}, { 'BOTSID': 'ITD', 'ITD05': None }) }) out.put({ 'BOTSID': 'message', 'termsnetdays': inn.get({'BOTSID': 'ST'}, { 'BOTSID': 'ITD', 'ITD07': None }) }) out.put({ 'BOTSID': 'message', 'totaltermsdiscount': inn.get({'BOTSID': 'ST'}, { 'BOTSID': 'ITD', 'ITD08': None }) }) #loop over partys for party in inn.getloop({'BOTSID': 'ST'}, {'BOTSID': 'N1'}): pou = out.putloop({'BOTSID': 'message'}, {'BOTSID': 'partys'}, {'BOTSID': 'party'}) pou.put({ 'BOTSID': 'party', 'qual': party.get({ 'BOTSID': 'N1', 'N101': None }) }) pou.put({ 'BOTSID': 'party', 'gln': party.get({ 'BOTSID': 'N1', 'N103': 'UL', 'N104': None }) }) #get DUNS number. 2 qualifiers are used; helper function transform.useoneof checks both pou.put({ 'BOTSID': 'party', 'DUNS': transform.useoneof( party.get({ 'BOTSID': 'N1', 'N103': '1', 'N104': None }), party.get({ 'BOTSID': 'N1', 'N103': '9', 'N104': None })) }) pou.put({ 'BOTSID': 'party', 'externalID': party.get({ 'BOTSID': 'N1', 'N103': '92', 'N104': None }) }) pou.put({ 'BOTSID': 'party', 'internalID': party.get({ 'BOTSID': 'N1', 'N103': '91', 'N104': None }) }) pou.put({ 'BOTSID': 'party', 'name1': party.get({ 'BOTSID': 'N1', 'N102': None }) }) pou.put({ 'BOTSID': 'party', 'name2': party.get({'BOTSID': 'N1'}, { 'BOTSID': 'N2', 'N201': None }) }) pou.put({ 'BOTSID': 'party', 'address1': party.get({'BOTSID': 'N1'}, { 'BOTSID': 'N3', 'N301': None }) }) pou.put({ 'BOTSID': 'party', 'address2': party.get({'BOTSID': 'N1'}, { 'BOTSID': 'N3', 'N302': None }) }) pou.put({ 'BOTSID': 'party', 'city': party.get({'BOTSID': 'N1'}, { 'BOTSID': 'N4', 'N401': None }) }) pou.put({ 'BOTSID': 'party', 'state': party.get({'BOTSID': 'N1'}, { 'BOTSID': 'N4', 'N402': None }) }) pou.put({ 'BOTSID': 'party', 'pcode': party.get({'BOTSID': 'N1'}, { 'BOTSID': 'N4', 'N403': None }) }) pou.put({ 'BOTSID': 'party', 'country': party.get({'BOTSID': 'N1'}, { 'BOTSID': 'N4', 'N404': None }) }) #loop over lines*************************************** for lin in inn.getloop({'BOTSID': 'ST'}, {'BOTSID': 'IT1'}): lou = out.putloop({'BOTSID': 'message'}, {'BOTSID': 'lines'}, {'BOTSID': 'line'}) lou.put({ 'BOTSID': 'line', 'linenum': lin.get({ 'BOTSID': 'IT1', 'IT101': None }) }) lou.put({ 'BOTSID': 'line', 'invqua': lin.get({ 'BOTSID': 'IT1', 'IT102': None }) }) lou.put({ 'BOTSID': 'line', 'ordunit': transform.useoneof(lin.get({ 'BOTSID': 'IT1', 'IT103': None }), 'EA') }) lou.put({ 'BOTSID': 'line', 'price': lin.get({ 'BOTSID': 'IT1', 'IT104': None }) }) lou.put({'BOTSID': 'line', 'gtin': get_art_num(lin, 'UP')}) lou.put({'BOTSID': 'line', 'suart': get_art_num(lin, 'VN')}) #get buyers article number; 1 different qualifiers are used; helper function transform.useoneof checks both lou.put({ 'BOTSID': 'line', 'byart': transform.useoneof(get_art_num(lin, 'IN'), get_art_num(lin, 'BP')) }) lou.put({ 'BOTSID': 'line', 'desc': lin.get({'BOTSID': 'IT1'}, { 'BOTSID': 'PID', 'PID01': 'F', 'PID05': None }) }) out.put({ 'BOTSID': 'message', 'totalinvoiceamount': inn.get({'BOTSID': 'ST'}, { 'BOTSID': 'TDS', 'TDS01': None }) })
def main(inn,out): #pick up some values from ISA envelope # Expected values for current implementation: # * BEG02: NE: New Order # * CUR02: USD: US Dollar # * N101: BS: Bill and ship to # * PO103: EA: each # * PO105: PE: Price Per Each out.put({'BOTSID':'sale'},{'BOTSID':'header','partner_from':inn.ta_info['frompartner']}) out.put({'BOTSID':'sale'},{'BOTSID':'header','partner_to':inn.ta_info['topartner']}) out.put({'BOTSID':'sale'},{'BOTSID':'header','test':inn.ta_info['testindicator']}) #pick up document number. is used in bots to give 'document-view' docnum = inn.get({'BOTSID':'ST'},{'BOTSID':'BEG','BEG03':None}) out.put({'BOTSID':'sale'},{'BOTSID':'header','docnum':docnum}) inn.ta_info['botskey']=docnum out.ta_info['botskey']=docnum order_date = inn.get({'BOTSID':'ST'},{'BOTSID':'BEG','BEG05':None}) order_date = transform.datemask(order_date,'CCYYMMDD','CCYY-MM-DD') out.put({'BOTSID':'sale'},{'BOTSID':'header','date_msg':order_date}) # Sale order date order_number = inn.get({'BOTSID':'ST'},{'BOTSID':'REF','REF01':'PO','REF02':None}) order_currency = inn.get({'BOTSID':'ST'},{'BOTSID':'CUR','CUR02':None}) or 'USD' customer_email = inn.get({'BOTSID':'ST'},{'BOTSID':'REF','REF01':'EM','REF02':None}) customer_name = inn.get({'BOTSID':'ST'},{'BOTSID':'REF','REF01':'NM','REF02':None}) program_ref = inn.get({'BOTSID':'ST'},{'BOTSID':'REF','REF01':'PID','REF02':None}) # Only a single sale per message oout = out.putloop({'BOTSID': 'sale'}, {'BOTSID':'sales'}) # Order number oout.put({'BOTSID':'sales','id': order_number}) oout.put({'BOTSID':'sales','name': order_number}) oout.put({'BOTSID':'sales','order': order_number}) # Dates oout.put({'BOTSID':'sales','order_date': order_date}) # Order Date # Cancel after date # Not really used, ignoring # oout.put({'BOTSID':'sales','cancel_after_date':transform.datemask(inn.get({'BOTSID':'ST'},{'BOTSID':'DTM','DTM01':'001','DTM02':None}),'CCYYMMDD','CCYY-MM-DD')}) # Requested ship date oout.put({'BOTSID':'sales','ship_date':transform.datemask(inn.get({'BOTSID':'ST'},{'BOTSID':'DTM','DTM01':'010','DTM02':None}),'CCYYMMDD','CCYY-MM-DD')}) oout.put({'BOTSID':'sales','client_order_ref': program_ref}) # Program as reference oout.put({'BOTSID':'sales','currency': order_currency}) # Currency oout.put({'BOTSID':'sales','partner_name': customer_name}) # Currency oout.put({'BOTSID':'sales','partner_email': customer_email}) # Currency #loop over partys for partner in inn.getloop({'BOTSID':'ST'},{'BOTSID':'N1'}): pou = oout.putloop({'BOTSID':'sales'},{'BOTSID':'partner'}) type = partner.get({'BOTSID':'N1','N101':None}) if type == 'FP': openerp_type = 'invoice' elif type == 'ST': openerp_type = 'delivery' elif type == 'BT': openerp_type = 'invoice' else: openerp_type = 'other' pou.put({'BOTSID':'partner','type':openerp_type}) pou.put({'BOTSID':'partner','name1':partner.get({'BOTSID':'N1','N102':None})}) pou.put({'BOTSID':'partner','name2':partner.get({'BOTSID':'N1'},{'BOTSID':'N2','N201':None})}) pou.put({'BOTSID':'partner','address1':partner.get({'BOTSID':'N1'},{'BOTSID':'N3','N301':None})}) pou.put({'BOTSID':'partner','address2':partner.get({'BOTSID':'N1'},{'BOTSID':'N3','N302':None})}) pou.put({'BOTSID':'partner','city':partner.get({'BOTSID':'N1'},{'BOTSID':'N4','N401':None})}) pou.put({'BOTSID':'partner','state':partner.get({'BOTSID':'N1'},{'BOTSID':'N4','N402':None})}) pou.put({'BOTSID':'partner','zip':partner.get({'BOTSID':'N1'},{'BOTSID':'N4','N403':None})}) pou.put({'BOTSID':'partner','country':partner.get({'BOTSID':'N1'},{'BOTSID':'N4','N404':None})}) #loop over lines for po1 in inn.getloop({'BOTSID':'ST'},{'BOTSID':'PO1'}): lou = oout.putloop({'BOTSID':'sales'},{'BOTSID':'line'}) lou.put({'BOTSID':'line','seq':po1.get({'BOTSID':'PO1','PO101':None})}) lou.put({'BOTSID':'line','qty':po1.get({'BOTSID':'PO1','PO102':None})}) lou.put({'BOTSID':'line','price':po1.get({'BOTSID':'PO1','PO104':None})}) lou.put({'BOTSID':'line','product_sku':get_art_num(po1,'SK')}) # Product stock keeping unit (SKU) #loop over transaction totals for tots in inn.getloop({'BOTSID':'ST'},{'BOTSID':'CTT'},{'BOTSID':'AMT'}): qualifier = tots.get({'BOTSID':'AMT','AMT01':None}) value = tots.get({'BOTSID':'AMT','AMT02':None}) oout.put({'BOTSID':'sales'},{'BOTSID':'total',TOTALS_MAPPING[qualifier]:value})
def main(inn, out): #sender, receiver is correct via QUERIES in grammar. out.put({ 'BOTSID': 'ST', 'ST01': '856', 'ST02': out.ta_info['reference'].zfill(4) }) out.put({'BOTSID': 'ST'}, {'BOTSID': 'BSN', 'BSN01': '00'}) out.put({'BOTSID': 'ST'}, { 'BOTSID': 'BSN', 'BSN02': inn.get({ 'BOTSID': 'message', 'docnum': None }) }) out.put({'BOTSID': 'ST'}, { 'BOTSID': 'BSN', 'BSN03': transform.datemask(inn.get({ 'BOTSID': 'message', 'docdtm': None }), 'CCYY-MM-DD HH:mm', 'CCYYMMDD') }) out.put({'BOTSID': 'ST'}, { 'BOTSID': 'BSN', 'BSN04': transform.useoneof(inn.get({ 'BOTSID': 'message', 'doctime': None }), '0000') }) out.put({'BOTSID': 'ST'}, { 'BOTSID': 'BSN', 'BSN05': '0002' }) #0001: Shipment, Order, Item (pfff, just making this up) #*********************************************************************************************** #shipment level********************************************************************************* hlcounter = 1 #HL segments have sequentail count shipment = out.putloop({'BOTSID': 'ST'}, { 'BOTSID': 'HL', 'HL01': hlcounter, 'HL03': 'S' }) currentshipment = hlcounter #remember the current counter, as child-HL segments have to point to this shipment hlcounter += 1 shipment.put({'BOTSID': 'HL'}, { 'BOTSID': 'TD5', 'TD501': 'O', 'TD502': '2', 'TD503': inn.get({ 'BOTSID': 'message', 'scac': None }) }) shipment.put({'BOTSID': 'HL'}, { 'BOTSID': 'REF', 'REF01': 'BM', 'REF02': inn.get({ 'BOTSID': 'message', 'bol': None }) }) shipment.put( {'BOTSID': 'HL'}, { 'BOTSID': 'REF', 'REF01': 'CN', 'REF02': inn.get({ 'BOTSID': 'message', 'carrierreferencenumber': None }) }) shipment.put({'BOTSID': 'HL'}, { 'BOTSID': 'DTM', 'DTM01': '011', 'DTM02': transform.datemask(inn.get({ 'BOTSID': 'message', 'shipdtm': None }), 'CCYY-MM-DD HH:mm', 'CCYYMMDD') }) shipment.put({'BOTSID': 'HL'}, { 'BOTSID': 'DTM', 'DTM01': '017', 'DTM02': transform.datemask(inn.get({ 'BOTSID': 'message', 'deldtm': None }), 'CCYY-MM-DD HH:mm', 'CCYYMMDD') }) #mapping for partners is in default 856 mapping asn_xml2x12_default.party_mapping(inn, shipment) #******************************************************************************************** #order level********************************************************************************* for order in inn.getloop({'BOTSID': 'message'}, {'BOTSID': 'orders'}, {'BOTSID': 'order'}): ordernode = out.putloop({'BOTSID': 'ST'}, { 'BOTSID': 'HL', 'HL01': hlcounter, 'HL02': currentshipment, 'HL03': 'O' }) currentorder = hlcounter hlcounter += 1 ordernode.put( {'BOTSID': 'HL'}, { 'BOTSID': 'PRF', 'PRF01': order.get({ 'BOTSID': 'order', 'ordernumber': None }) }) ordernode.put({'BOTSID': 'HL'}, { 'BOTSID': 'PRF', 'PRF04': transform.datemask( order.get({ 'BOTSID': 'order', 'orderdtm': None }), 'CCYY-MM-DD HH:mm', 'CCYYMMDD') }) #*************************************************************************************************** #line/article level********************************************************************************* for lin in order.getloop({'BOTSID': 'order'}, {'BOTSID': 'lines'}, {'BOTSID': 'line'}): itemnode = out.putloop({'BOTSID': 'ST'}, { 'BOTSID': 'HL', 'HL01': hlcounter, 'HL02': currentorder, 'HL03': 'I' }) hlcounter += 1 itemnode.put({'BOTSID': 'HL'}, { 'BOTSID': 'LIN', 'LIN01': lin.get({ 'BOTSID': 'line', 'linenum': None }) }) itemnode.put({'BOTSID': 'HL'}, { 'BOTSID': 'LIN', 'LIN02': 'UP', 'LIN03': lin.get({ 'BOTSID': 'line', 'gtin': None }) }) itemnode.put({'BOTSID': 'HL'}, { 'BOTSID': 'LIN', 'LIN04': 'VN', 'LIN05': lin.get({ 'BOTSID': 'line', 'suart': None }) }) itemnode.put({'BOTSID': 'HL'}, { 'BOTSID': 'LIN', 'LIN06': 'BP', 'LIN07': lin.get({ 'BOTSID': 'line', 'byart': None }) }) itemnode.put({'BOTSID': 'HL'}, { 'BOTSID': 'SN1', 'SN103': 'EA', 'SN102': lin.get({ 'BOTSID': 'line', 'delqua': None }) }) itemnode.put({'BOTSID': 'HL'}, { 'BOTSID': 'SN1', 'SN106': 'EA', 'SN105': lin.get({ 'BOTSID': 'line', 'ordqua': None }) }) itemnode.put({'BOTSID': 'HL'}, { 'BOTSID': 'PID', 'PID01': 'F', 'PID02': '08', 'PID05': lin.get({ 'BOTSID': 'line', 'desc': None }) }) out.put({'BOTSID': 'ST'}, { 'BOTSID': 'CTT', 'CTT01': out.getcountoccurrences({'BOTSID': 'ST'}, {'BOTSID': 'HL'}, {'BOTSID': 'LIN'}) }) #bots counts line items out.put({'BOTSID': 'ST'}, { 'BOTSID': 'SE', 'SE01': out.getcount() + 1, 'SE02': out.ta_info['reference'].zfill(4) }) #SE01: bots counts the segments produced in the X12 message.
def main(inn, out): # process the lines in a loop headerwritten = False for line in inn.getloop({'BOTSID': 'HEA'}): if not headerwritten: out.ta_info['frompartner'] = line.get({ 'BOTSID': 'HEA', 'SENDER': None }) out.ta_info['topartner'] = line.get({ 'BOTSID': 'HEA', 'RECEIVER': None }) out.ta_info['testindicator'] = line.get({ 'BOTSID': 'HEA', 'TEST': None }) inn.ta_info['testindicator'] = line.get({ 'BOTSID': 'HEA', 'TEST': None }) # ST Segment out.put({'BOTSID': 'ST', 'ST01': '850'}) out.put({ 'BOTSID': 'ST', 'ST02': out.ta_info['reference'].zfill(4) }) # BEG purpose_code = '00' ordertype_code = line.get({'BOTSID': 'HEA', 'ORDERTYPE': None}) order_number = line.get({'BOTSID': 'HEA', 'ORDERNUMBER': None}) inn.ta_info['botskey'] = order_number out.ta_info['botskey'] = order_number order_date = transform.datemask( line.get({ 'BOTSID': 'HEA', 'ORDERDATE': None }), 'YYYY-mm-DDT', 'YYYYmmDD') out.put({'BOTSID': 'ST'}, {'BOTSID': 'BEG', 'BEG01': purpose_code}) out.put({'BOTSID': 'ST'}, { 'BOTSID': 'BEG', 'BEG02': ordertype_code }) out.put({'BOTSID': 'ST'}, {'BOTSID': 'BEG', 'BEG03': order_number}) out.put({'BOTSID': 'ST'}, {'BOTSID': 'BEG', 'BEG05': order_date}) # DTM deldate = transform.datemask( line.get({ 'BOTSID': 'HEA', 'DELIVERYDATE': None }), 'YYYY-mm-DDT', 'YYYYmmDD') notbeforedate = transform.datemask( line.get({ 'BOTSID': 'HEA', 'NODELBEFORE': None }), 'YYYY-mm-DDT', 'YYYYmmDD') notafterdate = transform.datemask( line.get({ 'BOTSID': 'HEA', 'NODELAFTER': None }), 'YYYY-mm-DDT', 'YYYYmmDD') out.put({'BOTSID': 'ST'}, { 'BOTSID': 'DTM', 'DTM01': '002', 'DTM02': deldate }) out.put({'BOTSID': 'ST'}, { 'BOTSID': 'DTM', 'DTM01': '064', 'DTM02': notafterdate }) out.put({'BOTSID': 'ST'}, { 'BOTSID': 'DTM', 'DTM01': '063', 'DTM02': notbeforedate }) # N1 puchaser = line.get({'BOTSID': 'HEA', 'PURCHASER': None}) out.put({'BOTSID': 'ST'}, { 'BOTSID': 'N1', 'N101': 'BY', 'N103': '92', 'N104': puchaser }) supplier = line.get({'BOTSID': 'HEA', 'SUPPLIER': None}) out.put({'BOTSID': 'ST'}, { 'BOTSID': 'N1', 'N101': 'SE', 'N103': '92', 'N104': supplier }) delivery = line.get({'BOTSID': 'HEA', 'DESTINATION': None}) out.put({'BOTSID': 'ST'}, { 'BOTSID': 'N1', 'N101': 'ST', 'N103': '92', 'N104': delivery }) headerwritten = True # process the line items lineout = out.putloop({'BOTSID': 'ST'}, {'BOTSID': 'PO1'}) linenum = int(float(line.get({'BOTSID': 'HEA', 'LINE': None}))) itemnum = line.get({'BOTSID': 'HEA', 'ITEM': None}) quantity = int(float(line.get({'BOTSID': 'HEA', 'QUANTITY': None}))) price = line.get({'BOTSID': 'HEA', 'PRICE': None}) DECIMALPLACES = decimal.Decimal(10)**-2 price = decimal.Decimal(price).quantize(DECIMALPLACES) description = line.get({'BOTSID': 'HEA', 'DESCRIPTION': None}) lineout.put({'BOTSID': 'PO1', 'PO101': linenum}) lineout.put({'BOTSID': 'PO1', 'PO102': int(quantity), 'PO103': 'EA'}) lineout.put({'BOTSID': 'PO1', 'PO104': price}) lineout.put({'BOTSID': 'PO1', 'PO106': 'UP', 'PO107': itemnum}) lineout.put({'BOTSID': 'PO1'}, { 'BOTSID': 'PID', 'PID01': 'F', 'PID02': '08', 'PID05': description }) # bots counts line items out.put( {'BOTSID': 'ST'}, { 'BOTSID': 'CTT', 'CTT01': out.getcountoccurrences({'BOTSID': 'ST'}, {'BOTSID': 'PO1'}) }) # SE01: bots counts the segments produced in the X12 message. out.put({'BOTSID': 'ST'}, { 'BOTSID': 'SE', 'SE01': out.getcount() + 1, 'SE02': out.ta_info['reference'].zfill(4) })
def main(inn, out): out.put({'BOTSID': 'ST', 'ST01': '857', 'ST02': out.ta_info['reference'].zfill(4) }) out.put({'BOTSID': 'ST'}, {'BOTSID': 'BHT', 'BHT01': '0001', 'BHT02': '00', 'BHT03': inn.ta_info['botskey'], 'BHT06': 'AB' }) doc_date = inn.get({'BOTSID': 'Invoice', 'actual_ship_date': None}) out.put({'BOTSID': 'ST'}, {'BOTSID': 'BHT', 'BHT04': transform.datemask(doc_date, 'CCYY-MM-DD', 'YYMMDD') }) ship_hl = out.putloop({'BOTSID': 'ST'}, {'BOTSID': 'HL'}) ship_hl.put({'BOTSID': 'HL', 'HL01': '1', 'HL03': 'S', 'HL04': '1'}) ship_hl.put({'BOTSID': 'HL'}, {'BOTSID': 'G05', 'G0501': inn.get({'BOTSID': 'Invoice', 'boxes': None}), 'G0502': 'BX', 'G0503': inn.get({'BOTSID': 'Invoice', 'weight': None}), 'G0504': '01', 'G0505': '1', 'G0506': 'PL' }) ship_hl.put({'BOTSID': 'HL'}, {'BOTSID': 'G05'}, {'BOTSID': 'FOB', 'FOB01': 'PS', 'FOB09': inn.get({'BOTSID': 'Invoice', 'shipping_cost': None}) }) ship_hl.put({'BOTSID': 'HL'}, {'BOTSID': 'G05'}, {'BOTSID': 'DTM', 'DTM01': '011', 'DTM02': transform.datemask(doc_date, 'CCYY-MM-DD', 'YYMMDD'), 'DTM05': transform.datemask(doc_date, 'CCYY-MM-DD', 'CC') }) ship_hl.put({'BOTSID': 'HL'}, {'BOTSID': 'G05'}, {'BOTSID': 'N9', 'N901': 'FR', 'N902': inn.get({'BOTSID': 'Invoice', 'tracking_number': None}) }) ship_hl.put({'BOTSID': 'HL'}, {'BOTSID': 'G05'}, {'BOTSID': 'N1', 'N101': 'ST', 'N102': inn.get({'BOTSID': 'Invoice', 'isd_name': None}), 'N103': '76', 'N104': inn.get({'BOTSID': 'Invoice', 'isd_code': None}) }) ship_hl.put({'BOTSID': 'HL'}, {'BOTSID': 'G05'}, {'BOTSID': 'N1', 'N101': 'CA', 'N102': inn.get({'BOTSID': 'Invoice', 'carrier_name': None}), 'N103': '75', 'N104': inn.get({'BOTSID': 'Invoice', 'carrier_code': None}) }) order_hl = out.putloop({'BOTSID': 'ST'}, {'BOTSID': 'HL'}) order_hl.put({'BOTSID': 'HL', 'HL01': '2', 'HL03': 'O', 'HL04': '1'}) order_hl.put({'BOTSID': 'HL'}, {'BOTSID': 'TDS', 'TDS01': inn.getdecimal( {'BOTSID': 'Invoice', 'total_amount': None}) / 100 }) ord_date = inn.get({'BOTSID': 'Invoice', 'purchase_order_date': None}) order_hl.put({'BOTSID': 'HL'}, {'BOTSID': 'TDS'}, {'BOTSID': 'PRF', 'PRF01': inn.get( {'BOTSID': 'Invoice', 'purchase_order': None}), 'PRF03': '0', 'PRF04': transform.datemask(ord_date, 'CCYY-MM-DD', 'YYMMDD'), 'PRF05': inn.get({'BOTSID': 'Invoice', 'isd_code': None}), 'PRF06': inn.get({'BOTSID': 'Invoice', 'contract': None}) }) order_hl.put({'BOTSID': 'HL'}, {'BOTSID': 'TDS'}, {'BOTSID': 'N9', 'N901': 'IK', 'N902': inn.ta_info['botskey']}) hl_count = 3 for line in inn.getloop({'BOTSID': 'Invoice'}, {'BOTSID': 'Lines'}): line_hl = out.putloop({'BOTSID': 'ST'}, {'BOTSID': 'HL'}) line_hl.put({'BOTSID': 'HL', 'HL01': hl_count, 'HL03': 'I', 'HL04': '0'}) line_hl.put({'BOTSID': 'HL'}, {'BOTSID': 'IT1', 'IT101': line.get({'BOTSID': 'Lines', 'sequence': None}) }) line_hl.put({'BOTSID': 'HL'}, {'BOTSID': 'IT1', 'IT103': 'UN', 'IT102': line.get({'BOTSID': 'Lines', 'quantity': None}) }) line_hl.put({'BOTSID': 'HL'}, {'BOTSID': 'IT1', 'IT105': '03', 'IT104': line.get({'BOTSID': 'Lines', 'unit_price': None}) }) line_hl.put({'BOTSID': 'HL'}, {'BOTSID': 'IT1', 'IT106': 'IB', 'IT107': line.get({'BOTSID': 'Lines', 'isbn': None}) }) line_hl.put({'BOTSID': 'HL'}, {'BOTSID': 'IT1', 'IT108': 'SE', 'IT109': line.get({'BOTSID': 'Lines', 'student_edition': None}) }) line_hl.put({'BOTSID': 'HL'}, {'BOTSID': 'IT1', 'IT110': 'SC', 'IT111': line.get({'BOTSID': 'Lines', 'student_edition_cost': None}) }) line_hl.put({'BOTSID': 'HL'}, {'BOTSID': 'IT1'}, {'BOTSID': 'IT3', 'IT301': line.get({'BOTSID': 'Lines', 'quantity': None}), 'IT302': line.get( {'BOTSID': 'Lines', 'quantity_uom': None}), 'IT303': 'SH', 'IT304': '0' }) ship_date = line.get({'BOTSID': 'Lines', 'actual_ship_date': None}) line_hl.put({'BOTSID': 'HL'}, {'BOTSID': 'IT1'}, {'BOTSID': 'DTM', 'DTM01': '011', 'DTM02': transform.datemask(ship_date, 'CCYY-MM-DD', 'YYMMDD'), 'DTM05': transform.datemask(ship_date, 'CCYY-MM-DD', 'CC') }) line_hl.put({'BOTSID': 'HL'}, {'BOTSID': 'IT1'}, {'BOTSID': 'SAC', 'SAC01': 'C', 'SAC02': 'ZZZZ', 'SAC05': line.get( {'BOTSID': 'Lines', 'total_amount': None}), }) hl_count += 1 out.put({'BOTSID': 'ST'}, {'BOTSID': 'SE', 'SE01': out.getcount()+1, 'SE02': out.ta_info['reference'].zfill(4) })
def main(inn, out): out.put({ 'BOTSID': 'ST', 'ST01': '846', 'ST02': out.ta_info['reference'].zfill(4) }) out.put( {'BOTSID': 'ST'}, { 'BOTSID': 'BIA', 'BIA01': '08', # Status 'BIA02': 'MM', # Manufacturer/Manufacturer Inventory 'BIA03': '000000', # Unused 'BIA04': transform.datemask( inn.get({'BOTSID': 'inventory'}, { 'BOTSID': 'header', 'date_msg': None }), 'CCYY-MM-DD HH:mm:ss', 'CCYYMMDD'), # Date of transaction 'BIA05': transform.datemask( inn.get({'BOTSID': 'inventory'}, { 'BOTSID': 'header', 'date_msg': None }), 'CCYY-MM-DD HH:mm:ss', 'HHmmss'), # Time of transaction }) pinn = inn.getloop({'BOTSID': 'inventory'}, {'BOTSID': 'products'}) counter = 0 for product in pinn: counter += 1 pou = out.putloop({'BOTSID': 'ST'}, {'BOTSID': 'LIN'}) pou.put({ 'BOTSID': 'LIN', 'LIN01': counter, # Unique within transaction 'LIN02': 'SK', # Stock Keeping Unit (SKU) 'LIN03': product.get({ 'BOTSID': 'products', 'product_sku': None }), # Product ID }) pou.put( {'BOTSID': 'LIN'}, { 'BOTSID': 'QTY', 'QTY01': 'RJ', # Quantity Available On Shelf 'QTY02': product.get({ 'BOTSID': 'products', 'quantity': None }), # Quantity 'QTY03': 'EA', # Each }) out.put({'BOTSID': 'ST'}, { 'BOTSID': 'CTT', 'CTT01': counter, }) out.put( {'BOTSID': 'ST'}, { 'BOTSID': 'SE', 'SE01': out.getcount() + 1, #SE01: bots counts the segments produced in the X12 message. 'SE02': out.ta_info['reference'].zfill(4), })
def testdatemask(self): self.assertEqual(u'20121231',transform.datemask('12/31/2012','MM/DD/YYYY','YYYYMMDD'),'test datemask') self.assertEqual(u'201231',transform.datemask('12/31/2012','MM/DD/YYYY','YYMMDD'),'test datemask')
def main(inn,out): #sender, receiver is correct via QUERIES in grammar. out.put({'BOTSID':'ST','ST01':'856','ST02':out.ta_info['reference'].zfill(4)}) out.put({'BOTSID':'ST'},{'BOTSID':'BSN','BSN01':'00'}) out.put({'BOTSID':'ST'},{'BOTSID':'BSN','BSN02':inn.get({'BOTSID':'message','docnum':None})}) out.put({'BOTSID':'ST'},{'BOTSID':'BSN','BSN03':transform.datemask(inn.get({'BOTSID':'message','docdtm':None}),'CCYY-MM-DD HH:mm','CCYYMMDD')}) out.put({'BOTSID':'ST'},{'BOTSID':'BSN','BSN04':transform.useoneof(inn.get({'BOTSID':'message','doctime':None}),'0000')}) out.put({'BOTSID':'ST'},{'BOTSID':'BSN','BSN05':'0002'}) #0001: Shipment, Order, Item (pfff, just making this up) #*********************************************************************************************** #shipment level********************************************************************************* hlcounter = 1 #HL segments have sequentail count shipment = out.putloop({'BOTSID':'ST'},{'BOTSID':'HL','HL01':hlcounter,'HL03':'S'}) currentshipment = hlcounter #remember the current counter, as child-HL segments have to point to this shipment hlcounter += 1 shipment.put({'BOTSID':'HL'},{'BOTSID':'TD5','TD501':'O','TD502':'2','TD503':inn.get({'BOTSID':'message','scac':None})}) shipment.put({'BOTSID':'HL'},{'BOTSID':'REF','REF01':'BM','REF02':inn.get({'BOTSID':'message','bol':None})}) shipment.put({'BOTSID':'HL'},{'BOTSID':'REF','REF01':'CN','REF02':inn.get({'BOTSID':'message','carrierreferencenumber':None})}) shipment.put({'BOTSID':'HL'},{'BOTSID':'DTM','DTM01':'011','DTM02':transform.datemask(inn.get({'BOTSID':'message','shipdtm':None}),'CCYY-MM-DD HH:mm','CCYYMMDD')}) shipment.put({'BOTSID':'HL'},{'BOTSID':'DTM','DTM01':'017','DTM02':transform.datemask(inn.get({'BOTSID':'message','deldtm':None}),'CCYY-MM-DD HH:mm','CCYYMMDD')}) #loop over partys (all on shipment level for simplicity ;-) for party in inn.getloop({'BOTSID':'message'},{'BOTSID':'partys'},{'BOTSID':'party'}): pou = shipment.putloop({'BOTSID':'HL'},{'BOTSID':'N1'}) pou.put({'BOTSID':'N1','N101':party.get({'BOTSID':'party','qual':None})}) #write partyID: if gln write it, else DUNS etc #this uses the fact the out.put returns True if succeeded. if pou.put({'BOTSID':'N1','N103':'UL','N104':party.get({'BOTSID':'party','gln':None})}): pass elif pou.put({'BOTSID':'N1','N103':'1','N104':party.get({'BOTSID':'party','DUNS':None})}): pass elif pou.put({'BOTSID':'N1','N103':'92','N104':party.get({'BOTSID':'party','externalID':None})}): pass else: pou.put({'BOTSID':'N1','N103':'91','N104':party.get({'BOTSID':'party','internalID':None})}) pou.put({'BOTSID':'N1','N102':party.get({'BOTSID':'party','name1':None})}) pou.put({'BOTSID':'N1'},{'BOTSID':'N2','N201':party.get({'BOTSID':'party','name2':None})}) pou.put({'BOTSID':'N1'},{'BOTSID':'N3','N301':party.get({'BOTSID':'party','address1':None})}) pou.put({'BOTSID':'N1'},{'BOTSID':'N3','N302':party.get({'BOTSID':'party','address2':None})}) pou.put({'BOTSID':'N1'},{'BOTSID':'N4','N401':party.get({'BOTSID':'party','city':None})}) pou.put({'BOTSID':'N1'},{'BOTSID':'N4','N402':party.get({'BOTSID':'party','state':None})}) pou.put({'BOTSID':'N1'},{'BOTSID':'N4','N403':party.get({'BOTSID':'party','pcode':None})}) pou.put({'BOTSID':'N1'},{'BOTSID':'N4','N404':party.get({'BOTSID':'party','country':None})}) #******************************************************************************************** #order level********************************************************************************* for order in inn.getloop({'BOTSID':'message'},{'BOTSID':'orders'},{'BOTSID':'order'}): ordernode = out.putloop({'BOTSID':'ST'},{'BOTSID':'HL','HL01':hlcounter,'HL02':currentshipment,'HL03':'O'}) currentorder = hlcounter hlcounter += 1 ordernode.put({'BOTSID':'HL'},{'BOTSID':'PRF','PRF01':order.get({'BOTSID':'order','ordernumber':None})}) ordernode.put({'BOTSID':'HL'},{'BOTSID':'PRF','PRF04':transform.datemask(order.get({'BOTSID':'order','orderdtm':None}),'CCYY-MM-DD HH:mm','CCYYMMDD')}) #*************************************************************************************************** #line/article level********************************************************************************* for lin in order.getloop({'BOTSID':'order'},{'BOTSID':'lines'},{'BOTSID':'line'}): itemnode = out.putloop({'BOTSID':'ST'},{'BOTSID':'HL','HL01':hlcounter,'HL02':currentorder,'HL03':'I'}) hlcounter += 1 itemnode.put({'BOTSID':'HL'},{'BOTSID':'LIN','LIN01':lin.get({'BOTSID':'line','linenum':None})}) itemnode.put({'BOTSID':'HL'},{'BOTSID':'LIN','LIN02':'UP','LIN03':lin.get({'BOTSID':'line','gtin':None})}) itemnode.put({'BOTSID':'HL'},{'BOTSID':'LIN','LIN04':'VN','LIN05':lin.get({'BOTSID':'line','suart':None})}) itemnode.put({'BOTSID':'HL'},{'BOTSID':'LIN','LIN06':'BP','LIN07':lin.get({'BOTSID':'line','byart':None})}) itemnode.put({'BOTSID':'HL'},{'BOTSID':'SN1','SN103':'EA','SN102':lin.get({'BOTSID':'line','delqua':None})}) itemnode.put({'BOTSID':'HL'},{'BOTSID':'SN1','SN106':'EA','SN105':lin.get({'BOTSID':'line','ordqua':None})}) itemnode.put({'BOTSID':'HL'},{'BOTSID':'PID','PID01':'F','PID02':'08','PID05':lin.get({'BOTSID':'line','desc':None})}) out.put({'BOTSID':'ST'},{'BOTSID':'CTT','CTT01':out.getcountoccurrences({'BOTSID':'ST'},{'BOTSID':'HL'},{'BOTSID':'LIN'}) }) #bots counts line items out.put({'BOTSID':'ST'},{'BOTSID':'SE','SE01':out.getcount()+1,'SE02':out.ta_info['reference'].zfill(4)}) #SE01: bots counts the segments produced in the X12 message.
def main(inn, out): # Get Header and Partner Information test_indicator = inn.get({'BOTSID': 'Order'}, {'BOTSID': 'UBLExtensions'}, {'BOTSID': 'UBLExtension'}, {'BOTSID': 'ExtensionContent'}, {'BOTSID': 'DocumentEnvelope'}, { 'BOTSID': 'CopyIndicator', 'IdentifierContent': None }) inn.ta_info['testindicator'] = test_indicator out.ta_info['ISA15'] = test_indicator out.ta_info['testindicator'] = test_indicator from_partner = inn.get({'BOTSID': 'Order'}, {'BOTSID': 'UBLExtensions'}, {'BOTSID': 'UBLExtension'}, {'BOTSID': 'ExtensionContent'}, {'BOTSID': 'DocumentEnvelope'}, {'BOTSID': 'SenderParty'}, {'BOTSID': 'PartyIdentification'}, { 'BOTSID': 'ID', 'IdentifierContent': None }) inn.ta_info['frompartner'] = from_partner out.ta_info['frompartner'] = from_partner from_partner_qual = inn.get( {'BOTSID': 'Order'}, {'BOTSID': 'UBLExtensions'}, {'BOTSID': 'UBLExtension'}, {'BOTSID': 'ExtensionContent'}, {'BOTSID': 'DocumentEnvelope'}, {'BOTSID': 'SenderParty'}, {'BOTSID': 'PartyIdentification'}, { 'BOTSID': 'ID', 'IdentificationSchemeNameText': None }) inn.ta_info['ISA05'] = from_partner_qual out.ta_info['ISA05'] = from_partner_qual to_partner = inn.get({'BOTSID': 'Order'}, {'BOTSID': 'UBLExtensions'}, {'BOTSID': 'UBLExtension'}, {'BOTSID': 'ExtensionContent'}, {'BOTSID': 'DocumentEnvelope'}, {'BOTSID': 'ReceiverParty'}, {'BOTSID': 'PartyIdentification'}, { 'BOTSID': 'ID', 'IdentifierContent': None }) inn.ta_info['topartner'] = to_partner out.ta_info['topartner'] = to_partner to_partner_qual = inn.get({'BOTSID': 'Order'}, {'BOTSID': 'UBLExtensions'}, {'BOTSID': 'UBLExtension'}, {'BOTSID': 'ExtensionContent'}, {'BOTSID': 'DocumentEnvelope'}, {'BOTSID': 'ReceiverParty'}, {'BOTSID': 'PartyIdentification'}, { 'BOTSID': 'ID', 'IdentificationSchemeNameText': None }) inn.ta_info['ISA07'] = to_partner_qual out.ta_info['ISA07'] = to_partner_qual isa_date = inn.get({'BOTSID': 'Order'}, {'BOTSID': 'UBLExtensions'}, {'BOTSID': 'UBLExtension'}, {'BOTSID': 'ExtensionContent'}, {'BOTSID': 'DocumentEnvelope'}, { 'BOTSID': 'IssueDate', 'DateContent': None }) isa_date = transform.datemask(isa_date, 'YYYY-mm-DD', 'YYmmDD') out.ta_info['ISA09'] = isa_date isa_Time = inn.get({'BOTSID': 'Order'}, {'BOTSID': 'UBLExtensions'}, {'BOTSID': 'UBLExtension'}, {'BOTSID': 'ExtensionContent'}, {'BOTSID': 'DocumentEnvelope'}, { 'BOTSID': 'IssueTime', 'TimeContent': None }) isa_Time = transform.datemask(isa_Time, "00:00", "0000") out.ta_info['ISA10'] = isa_Time version = inn.get({'BOTSID': 'Order'}, {'BOTSID': 'UBLExtensions'}, {'BOTSID': 'UBLExtension'}, {'BOTSID': 'ExtensionContent'}, {'BOTSID': 'DocumentEnvelope'}, { 'BOTSID': 'VersionID', 'IdentifierContent': None }) out.ta_info['version'] = version # ST Segment out.put({'BOTSID': 'ST', 'ST01': '850'}) out.put({'BOTSID': 'ST', 'ST02': out.ta_info['reference'].zfill(4)}) # BEG Segemnt purpose_code = inn.get({'BOTSID': 'Order'}, { 'BOTSID': 'PurposeCode', 'CodeContent': None }) ordertype_code = inn.get({'BOTSID': 'Order'}, { 'BOTSID': 'OrderTypeCode', 'CodeContent': None }) order_number = inn.get({'BOTSID': 'Order'}, { 'BOTSID': 'ID', 'IdentifierContent': None }) inn.ta_info['botskey'] = order_number out.ta_info['botskey'] = order_number order_date = inn.get({'BOTSID': 'Order'}, { 'BOTSID': 'IssueDate', 'DateContent': None }) order_date = transform.datemask(order_date, 'mm/DD/YYYY', 'YYYYmmDD') contract_number = inn.get({'BOTSID': 'Order'}, {'BOTSID': 'Contract'}, { 'BOTSID': 'ID', 'IdentifierContent': None }) out.put({'BOTSID': 'ST'}, {'BOTSID': 'BEG', 'BEG01': purpose_code}) out.put({'BOTSID': 'ST'}, {'BOTSID': 'BEG', 'BEG02': ordertype_code}) out.put({'BOTSID': 'ST'}, {'BOTSID': 'BEG', 'BEG03': order_number}) out.put({'BOTSID': 'ST'}, {'BOTSID': 'BEG', 'BEG05': order_date}) out.put({'BOTSID': 'ST'}, {'BOTSID': 'BEG', 'BEG06': contract_number}) # DTM Segment EstimatedDeliveryDateQual = inn.get({'BOTSID': 'Order'}, {'BOTSID': 'Delivery'}, {'BOTSID': 'RequestedDeliveryPeriod'}, { 'BOTSID': 'DescriptionCode', 'CodeContent': None }) EstimatedDeliveryDate = inn.get({'BOTSID': 'Order'}, {'BOTSID': 'Delivery'}, {'BOTSID': 'RequestedDeliveryPeriod'}, { 'BOTSID': 'StartDate', 'DateContent': None }) EstimatedDeliveryDate = transform.datemask(EstimatedDeliveryDate, 'mm/DD/YYYY', 'YYYYmmDD') if EstimatedDeliveryDateQual == '017': out.put({'BOTSID': 'ST'}, { 'BOTSID': 'DTM', 'DTM01': EstimatedDeliveryDateQual }) out.put({'BOTSID': 'ST'}, { 'BOTSID': 'DTM', 'DTM02': EstimatedDeliveryDate }) # TD5 Segment SCAC = inn.get({'BOTSID': 'Order'}, {'BOTSID': 'Delivery'}, {'BOTSID': 'CarrierParty'}, {'BOTSID': 'PartyIdentification'}, { 'BOTSID': 'ID', 'IdentifierContent': None }) CarrierName = inn.get({'BOTSID': 'Order'}, {'BOTSID': 'Delivery'}, {'BOTSID': 'CarrierParty'}, {'BOTSID': 'PartyName'}, { 'BOTSID': 'Name', 'TextContent': None }) out.put({'BOTSID': 'ST'}, {'BOTSID': 'TD5', 'TD502': '2'}) out.put({'BOTSID': 'ST'}, {'BOTSID': 'TD5', 'TD503': SCAC}) out.put({'BOTSID': 'ST'}, {'BOTSID': 'TD5', 'TD505': CarrierName}) # N1 - BT PartyQual = inn.get({'BOTSID': 'Order'}, {'BOTSID': 'BuyerCustomerParty'}, {'BOTSID': 'Party'}, { 'BOTSID': 'PartyIdentification', 'IdentificationSchemeIdentifier': None }) PartyName = inn.get({'BOTSID': 'Order'}, {'BOTSID': 'BuyerCustomerParty'}, {'BOTSID': 'Party'}, {'BOTSID': 'PartyName'}, { 'BOTSID': 'Name', 'TextContent': None }) PartyAgency = inn.get({'BOTSID': 'Order'}, {'BOTSID': 'BuyerCustomerParty'}, {'BOTSID': 'Party'}, { 'BOTSID': 'PartyIdentification', 'IdentificationSchemeAgencyIdentifier': None }) PartyNumber = inn.get({'BOTSID': 'Order'}, {'BOTSID': 'BuyerCustomerParty'}, {'BOTSID': 'Party'}, { 'BOTSID': 'PartyIdentification', 'IdentifierContent': None }) if PartyQual == 'BT': out.put({'BOTSID': 'ST'}, {'BOTSID': 'N1', 'N101': PartyQual}) out.put({'BOTSID': 'ST'}, {'BOTSID': 'N1', 'N102': PartyName}) out.put({'BOTSID': 'ST'}, {'BOTSID': 'N1', 'N103': PartyAgency}) out.put({'BOTSID': 'ST'}, {'BOTSID': 'N1', 'N104': PartyNumber}) PartyAddress1 = inn.get({'BOTSID': 'Order'}, {'BOTSID': 'BuyerCustomerParty'}, {'BOTSID': 'Party'}, {'BOTSID': 'PostalAddress'}, { 'BOTSID': 'StreetName', 'TextContent': None }) PartyAddress2 = inn.get({'BOTSID': 'Order'}, {'BOTSID': 'BuyerCustomerParty'}, {'BOTSID': 'Party'}, {'BOTSID': 'PostalAddress'}, { 'BOTSID': 'AdditionalStreetName', 'TextContent': None }) PartyCity = inn.get({'BOTSID': 'Order'}, {'BOTSID': 'BuyerCustomerParty'}, {'BOTSID': 'Party'}, {'BOTSID': 'PostalAddress'}, { 'BOTSID': 'CityName', 'TextContent': None }) PartyCountrySubentity = inn.get({'BOTSID': 'Order'}, {'BOTSID': 'BuyerCustomerParty'}, {'BOTSID': 'Party'}, {'BOTSID': 'PostalAddress'}, { 'BOTSID': 'CountrySubentity', 'TextContent': None }) PartyPostal = inn.get({'BOTSID': 'Order'}, {'BOTSID': 'BuyerCustomerParty'}, {'BOTSID': 'Party'}, {'BOTSID': 'PostalAddress'}, { 'BOTSID': 'PostalZone', 'TextContent': None }) PartyCountry = inn.get({'BOTSID': 'Order'}, {'BOTSID': 'BuyerCustomerParty'}, {'BOTSID': 'Party'}, {'BOTSID': 'PostalAddress'}, {'BOTSID': 'Country'}, { 'BOTSID': 'IdentificationCode', 'CodeContent': None }) out.put({'BOTSID': 'ST'}, { 'BOTSID': 'N1', 'N101': 'BT', }, { 'BOTSID': 'N3', 'N301': PartyAddress1 }) out.put({'BOTSID': 'ST'}, { 'BOTSID': 'N1', 'N101': 'BT', }, { 'BOTSID': 'N3', 'N302': PartyAddress2 }) out.put({'BOTSID': 'ST'}, { 'BOTSID': 'N1', 'N101': 'BT', }, { 'BOTSID': 'N4', 'N401': PartyCity }) out.put({'BOTSID': 'ST'}, { 'BOTSID': 'N1', 'N101': 'BT', }, { 'BOTSID': 'N4', 'N402': PartyCountrySubentity }) out.put({'BOTSID': 'ST'}, { 'BOTSID': 'N1', 'N101': 'BT', }, { 'BOTSID': 'N4', 'N403': PartyPostal }) out.put({'BOTSID': 'ST'}, { 'BOTSID': 'N1', 'N101': 'BT', }, { 'BOTSID': 'N4', 'N404': PartyCountry }) # N1 - ST PartyQual = inn.get({'BOTSID': 'Order'}, {'BOTSID': 'Delivery'}, {'BOTSID': 'DeliveryAddress'}, { 'BOTSID': 'ID', 'IdentificationSchemeIdentifier': None }) PartyName = inn.get({'BOTSID': 'Order'}, {'BOTSID': 'Delivery'}, {'BOTSID': 'DeliveryAddress'}, { 'BOTSID': 'BuildingName', 'TextContent': None }) PartyAgency = inn.get({'BOTSID': 'Order'}, {'BOTSID': 'Delivery'}, {'BOTSID': 'DeliveryAddress'}, { 'BOTSID': 'ID', 'IdentificationSchemeAgencyIdentifier': None }) PartyNumber = inn.get({'BOTSID': 'Order'}, {'BOTSID': 'Delivery'}, {'BOTSID': 'DeliveryAddress'}, { 'BOTSID': 'ID', 'IdentifierContent': None }) if PartyQual == 'ST': out.put({'BOTSID': 'ST'}, {'BOTSID': 'N1', 'N101': PartyQual}) out.put({'BOTSID': 'ST'}, {'BOTSID': 'N1', 'N102': PartyName}) out.put({'BOTSID': 'ST'}, {'BOTSID': 'N1', 'N103': PartyAgency}) out.put({'BOTSID': 'ST'}, {'BOTSID': 'N1', 'N104': PartyNumber}) PartyAddress1 = inn.get({'BOTSID': 'Order'}, {'BOTSID': 'Delivery'}, {'BOTSID': 'DeliveryAddress'}, { 'BOTSID': 'StreetName', 'TextContent': None }) PartyAddress2 = inn.get({'BOTSID': 'Order'}, {'BOTSID': 'Delivery'}, {'BOTSID': 'DeliveryAddress'}, { 'BOTSID': 'AdditionalStreetName', 'TextContent': None }) PartyCity = inn.get({'BOTSID': 'Order'}, {'BOTSID': 'Delivery'}, {'BOTSID': 'DeliveryAddress'}, { 'BOTSID': 'CityName', 'TextContent': None }) PartyCountrySubentity = inn.get({'BOTSID': 'Order'}, {'BOTSID': 'Delivery'}, {'BOTSID': 'DeliveryAddress'}, { 'BOTSID': 'CountrySubentity', 'TextContent': None }) PartyPostal = inn.get({'BOTSID': 'Order'}, {'BOTSID': 'Delivery'}, {'BOTSID': 'DeliveryAddress'}, { 'BOTSID': 'PostalZone', 'TextContent': None }) PartyCountry = inn.get({'BOTSID': 'Order'}, {'BOTSID': 'Delivery'}, {'BOTSID': 'DeliveryAddress'}, {'BOTSID': 'Country'}, { 'BOTSID': 'IdentificationCode', 'CodeContent': None }) out.put({'BOTSID': 'ST'}, { 'BOTSID': 'N1', 'N101': 'ST', }, { 'BOTSID': 'N3', 'N301': PartyAddress1 }) out.put({'BOTSID': 'ST'}, { 'BOTSID': 'N1', 'N101': 'ST', }, { 'BOTSID': 'N3', 'N302': PartyAddress2 }) out.put({'BOTSID': 'ST'}, { 'BOTSID': 'N1', 'N101': 'ST', }, { 'BOTSID': 'N4', 'N401': PartyCity }) out.put({'BOTSID': 'ST'}, { 'BOTSID': 'N1', 'N101': 'ST', }, { 'BOTSID': 'N4', 'N402': PartyCountrySubentity }) out.put({'BOTSID': 'ST'}, { 'BOTSID': 'N1', 'N101': 'ST', }, { 'BOTSID': 'N4', 'N403': PartyPostal }) out.put({'BOTSID': 'ST'}, { 'BOTSID': 'N1', 'N101': 'ST', }, { 'BOTSID': 'N4', 'N404': PartyCountry }) # Item Lines for line in inn.getloop({'BOTSID': 'Order'}, {'BOTSID': 'OrderLine'}): # Out Object Array lineout = out.putloop({'BOTSID': 'ST'}, {'BOTSID': 'PO1'}) # Get Values LineNumber = line.get({'BOTSID': 'OrderLine'}, {'BOTSID': 'LineItem'}, { 'BOTSID': 'ID', 'IdentifierContent': None }) # Get UOM, if empty use 'EA' ISO_UOM = transform.useoneof( line.get({'BOTSID': 'OrderLine'}, {'BOTSID': 'LineItem'}, { 'BOTSID': 'Quantity', 'QuantityUnitCode': None }), 'EA') X12_UOM = transform.reverse_ccode('X12_ELEM_355_TO_ISO_UOM', ISO_UOM) QuantityOrdered = line.get({'BOTSID': 'OrderLine'}, {'BOTSID': 'LineItem'}, { 'BOTSID': 'Quantity', 'QuantityContent': None }) ISO_PriceCode = transform.useoneof( line.get({'BOTSID': 'OrderLine'}, {'BOTSID': 'LineItem'}, {'BOTSID': 'Price'}, { 'BOTSID': 'PriceTypeCode', 'CodeContent': None }), 'PE') X12_PriceCode = transform.reverse_ccode( 'X12_ELEM_639_TO_ISO_PRICETYPE', ISO_PriceCode) UnitPrice = line.get({'BOTSID': 'OrderLine'}, {'BOTSID': 'LineItem'}, {'BOTSID': 'Price'}, { 'BOTSID': 'PriceAmount', 'AmountContent': None }) # Get Item Values by Qualifier BuyerItem = line.get({'BOTSID': 'OrderLine'}, {'BOTSID': 'LineItem'}, {'BOTSID': 'Item'}, {'BOTSID': 'BuyersItemIdentification'}, { 'BOTSID': 'ID', 'IdentifierContent': None }) SellerItem = line.get({'BOTSID': 'OrderLine'}, {'BOTSID': 'LineItem'}, {'BOTSID': 'Item'}, {'BOTSID': 'SellersItemIdentification'}, { 'BOTSID': 'ID', 'IdentifierContent': None }) StandardItemQual = line.get({'BOTSID': 'OrderLine'}, {'BOTSID': 'LineItem'}, {'BOTSID': 'Item'}, {'BOTSID': 'StandardItemIdentification'}, { 'BOTSID': 'ID', 'IdentificationSchemeIdentifier': None }) UPC = "" if StandardItemQual == 'UPC': UPC = line.get({'BOTSID': 'OrderLine'}, {'BOTSID': 'LineItem'}, {'BOTSID': 'Item'}, {'BOTSID': 'StandardItemIdentification'}, { 'BOTSID': 'ID', 'IdentifierContent': None }) Description = line.get({'BOTSID': 'OrderLine'}, {'BOTSID': 'LineItem'}, {'BOTSID': 'Item'}, { 'BOTSID': 'Description', 'TextContent': None }) # Write output lineout.put({'BOTSID': 'PO1', 'PO101': LineNumber}) lineout.put({'BOTSID': 'PO1', 'PO102': QuantityOrdered}) lineout.put({'BOTSID': 'PO1', 'PO103': X12_UOM}) lineout.put({'BOTSID': 'PO1', 'PO104': UnitPrice}) lineout.put({'BOTSID': 'PO1', 'PO105': X12_PriceCode}) lineout.put({'BOTSID': 'PO1', 'PO106': 'IN'}) lineout.put({'BOTSID': 'PO1', 'PO107': SellerItem}) lineout.put({'BOTSID': 'PO1', 'PO108': 'SK'}) lineout.put({'BOTSID': 'PO1', 'PO109': BuyerItem}) if StandardItemQual == 'UPC' and UPC != "": lineout.put({'BOTSID': 'PO1', 'PO110': 'UP'}) lineout.put({'BOTSID': 'PO1', 'PO111': UPC}) lineout.put({'BOTSID': 'PO1'}, { 'BOTSID': 'PID', 'PID01': 'F', 'PID05': Description }) # last line (counts the segments produced in out-message) out.put({'BOTSID': 'ST'}, {'BOTSID': 'SE', 'SE01': out.getcount() + 1}) out.put({'BOTSID': 'ST'}, { 'BOTSID': 'SE', 'SE02': (out.ta_info['reference']).zfill(4) })
def main(inn, out): #pick up some values from ISA envelope out.put({'BOTSID': 'message', 'sender': inn.ta_info['frompartner']}) out.put({'BOTSID': 'message', 'receiver': inn.ta_info['topartner']}) out.put({ 'BOTSID': 'message', 'testindicator': inn.ta_info['testindicator'] }) #pick up document number. is used in bots to give 'document-view' docnum = inn.get({'BOTSID': 'ST'}, {'BOTSID': 'BEG', 'BEG03': None}) out.put({'BOTSID': 'message', 'docnum': docnum}) inn.ta_info['botskey'] = docnum out.ta_info['botskey'] = docnum out.put({ 'BOTSID': 'message', 'docsrt': inn.get({'BOTSID': 'ST'}, { 'BOTSID': 'BEG', 'BEG02': None }) }) #convert dates to right internal format docdtm = inn.get({'BOTSID': 'ST'}, {'BOTSID': 'BEG', 'BEG05': None}) docdtm = transform.datemask(docdtm, 'CCYYMMDDHHMM', 'CCYY-MM-DD') out.put({'BOTSID': 'message', 'docdtm': docdtm}) #same date handling as above, now in a one-liner. out.put({ 'BOTSID': 'message', 'deldtm': transform.datemask( inn.get({'BOTSID': 'ST'}, { 'BOTSID': 'DTM', 'DTM01': '002', 'DTM02': None }), 'CCYYMMDDHHMM', 'CCYY-MM-DD') }) out.put({ 'BOTSID': 'message', 'earldeldtm': transform.datemask( inn.get({'BOTSID': 'ST'}, { 'BOTSID': 'DTM', 'DTM01': '064', 'DTM02': None }), 'CCYYMMDDHHMM', 'CCYY-MM-DD') }) out.put({ 'BOTSID': 'message', 'latedeldtm': transform.datemask( inn.get({'BOTSID': 'ST'}, { 'BOTSID': 'DTM', 'DTM01': '063', 'DTM02': None }), 'CCYYMMDDHHMM', 'CCYY-MM-DD') }) out.put({ 'BOTSID': 'message', 'currency': inn.get({'BOTSID': 'ST'}, { 'BOTSID': 'CUR', 'CUR01': 'BY', 'CUR02': None }) }) #loop over partys for party in inn.getloop({'BOTSID': 'ST'}, {'BOTSID': 'N1'}): pou = out.putloop({'BOTSID': 'message'}, {'BOTSID': 'partys'}, {'BOTSID': 'party'}) pou.put({ 'BOTSID': 'party', 'qual': party.get({ 'BOTSID': 'N1', 'N101': None }) }) pou.put({ 'BOTSID': 'party', 'gln': party.get({ 'BOTSID': 'N1', 'N103': 'UL', 'N104': None }) }) #get DUNS number. 2 qualifiers are used; helper function transform.useoneof checks both pou.put({ 'BOTSID': 'party', 'DUNS': transform.useoneof( party.get({ 'BOTSID': 'N1', 'N103': '1', 'N104': None }), party.get({ 'BOTSID': 'N1', 'N103': '9', 'N104': None })) }) pou.put({ 'BOTSID': 'party', 'externalID': party.get({ 'BOTSID': 'N1', 'N103': '92', 'N104': None }) }) pou.put({ 'BOTSID': 'party', 'internalID': party.get({ 'BOTSID': 'N1', 'N103': '91', 'N104': None }) }) pou.put({ 'BOTSID': 'party', 'name1': party.get({ 'BOTSID': 'N1', 'N102': None }) }) pou.put({ 'BOTSID': 'party', 'name2': party.get({'BOTSID': 'N1'}, { 'BOTSID': 'N2', 'N201': None }) }) pou.put({ 'BOTSID': 'party', 'address1': party.get({'BOTSID': 'N1'}, { 'BOTSID': 'N3', 'N301': None }) }) pou.put({ 'BOTSID': 'party', 'address2': party.get({'BOTSID': 'N1'}, { 'BOTSID': 'N3', 'N302': None }) }) pou.put({ 'BOTSID': 'party', 'city': party.get({'BOTSID': 'N1'}, { 'BOTSID': 'N4', 'N401': None }) }) pou.put({ 'BOTSID': 'party', 'state': party.get({'BOTSID': 'N1'}, { 'BOTSID': 'N4', 'N402': None }) }) pou.put({ 'BOTSID': 'party', 'pcode': party.get({'BOTSID': 'N1'}, { 'BOTSID': 'N4', 'N403': None }) }) pou.put({ 'BOTSID': 'party', 'country': party.get({'BOTSID': 'N1'}, { 'BOTSID': 'N4', 'N404': None }) }) #mapping above is for full addresses. Often only party-IDs are used (good EDI practices..... #mapping could be simpler, eg: #~ out.put({'BOTSID':'message','buyer_ID':inn.get({'BOTSID':'ST'},{'BOTSID':'N1','N101':'BY','N4':None})}) #~ out.put({'BOTSID':'message','delivery_ID':inn.get({'BOTSID':'ST'},{'BOTSID':'N1','N101':'ST','N4':None})}) #loop over lines for po1 in inn.getloop({'BOTSID': 'ST'}, {'BOTSID': 'PO1'}): lou = out.putloop({'BOTSID': 'message'}, {'BOTSID': 'lines'}, {'BOTSID': 'line'}) lou.put({ 'BOTSID': 'line', 'linenum': po1.get({ 'BOTSID': 'PO1', 'PO101': None }) }) lou.put({ 'BOTSID': 'line', 'ordqua': po1.get({ 'BOTSID': 'PO1', 'PO102': None }) }) #get ordering unit; if not there use 'EA' 9each, pice) as default lou.put({ 'BOTSID': 'line', 'ordunit': transform.useoneof(po1.get({ 'BOTSID': 'PO1', 'PO103': None }), 'EA') }) lou.put({ 'BOTSID': 'line', 'price': po1.get({ 'BOTSID': 'PO1', 'PO104': None }) }) lou.put({'BOTSID': 'line', 'gtin': get_art_num(po1, 'UP')}) lou.put({'BOTSID': 'line', 'suart': get_art_num(po1, 'VN')}) #get buyers article number; 1 different qualifiers are used; helper function transform.useoneof checks both lou.put({ 'BOTSID': 'line', 'byart': transform.useoneof(get_art_num(po1, 'IN'), get_art_num(po1, 'BP')) }) lou.put({ 'BOTSID': 'line', 'desc': po1.get({'BOTSID': 'PO1'}, { 'BOTSID': 'PID', 'PID01': 'F', 'PID05': None }) })
def main(inn, out): # Set Out TA info out.ta_info['frompartner'] = inn.ta_info['frompartner'] out.ta_info['topartner'] = inn.ta_info['topartner'] if 'testindicator' not in inn.ta_info: inn.ta_info['testindicator'] = 'P' out.ta_info['testindicator'] = 'P' # ST Segment out.put({'BOTSID': 'ST', 'ST01': '850'}) out.put({'BOTSID': 'ST', 'ST02': out.ta_info['reference'].zfill(4)}) purpose_code = '00' ordertype_code = inn.get({'BOTSID': 'message', 'docsrt': None}) order_number = inn.get({'BOTSID': 'message', 'docnum': None}) inn.ta_info['botskey'] = order_number out.ta_info['botskey'] = order_number order_date = inn.get({'BOTSID': 'message', 'docdtm': None}) order_date = transform.datemask(order_date, 'CCYY-MM-DD', 'CCYYMMDD') out.put({'BOTSID': 'ST'}, {'BOTSID': 'BEG', 'BEG01': purpose_code}) out.put({'BOTSID': 'ST'}, {'BOTSID': 'BEG', 'BEG02': ordertype_code}) out.put({'BOTSID': 'ST'}, {'BOTSID': 'BEG', 'BEG03': order_number}) out.put({'BOTSID': 'ST'}, {'BOTSID': 'BEG', 'BEG05': order_date}) # same date handling as above, now in a one-liner. out.put({'BOTSID': 'ST'}, { 'BOTSID': 'DTM', 'DTM01': '002', 'DTM02': transform.datemask(inn.get({ 'BOTSID': 'message', 'deldtm': None }), 'CCYY-MM-DD', 'CCYYMMDD') }) out.put({'BOTSID': 'ST'}, { 'BOTSID': 'DTM', 'DTM01': '064', 'DTM02': transform.datemask(inn.get({ 'BOTSID': 'message', 'earldeldtm': None }), 'CCYY-MM-DD', 'CCYYMMDD') }) out.put({'BOTSID': 'ST'}, { 'BOTSID': 'DTM', 'DTM01': '063', 'DTM02': transform.datemask(inn.get({ 'BOTSID': 'message', 'latedeldtm': None }), 'CCYY-MM-DD', 'CCYYMMDD') }) # currency out.put({'BOTSID': 'ST'}, { 'BOTSID': 'CUR', 'CUR01': 'BY', 'CUR02': inn.get({ 'BOTSID': 'message', 'currency': None }) }) # loop over partys for party in inn.getloop({'BOTSID': 'message'}, {'BOTSID': 'partys'}, {'BOTSID': 'party'}): pou = out.putloop({'BOTSID': 'ST'}, {'BOTSID': 'N1'}) pou.put({ 'BOTSID': 'N1', 'N101': party.get({ 'BOTSID': 'party', 'qual': None }) }) # write partyID: if gln write it, else DUNS etc # this uses the fact the out.put retunr True if succeeded. if pou.put({ 'BOTSID': 'N1', 'N103': 'UL', 'N104': party.get({ 'BOTSID': 'party', 'gln': None }) }): pass elif pou.put({ 'BOTSID': 'N1', 'N103': '1', 'N104': party.get({ 'BOTSID': 'party', 'DUNS': None }) }): pass elif pou.put({ 'BOTSID': 'N1', 'N103': '92', 'N104': party.get({ 'BOTSID': 'party', 'externalID': None }) }): pass else: pou.put({ 'BOTSID': 'N1', 'N103': '91', 'N104': party.get({ 'BOTSID': 'party', 'internalID': None }) }) pou.put({ 'BOTSID': 'N1', 'N102': party.get({ 'BOTSID': 'party', 'name1': None }) }) pou.put({'BOTSID': 'N1'}, { 'BOTSID': 'N2', 'N201': party.get({ 'BOTSID': 'party', 'name2': None }) }) pou.put({'BOTSID': 'N1'}, { 'BOTSID': 'N3', 'N301': party.get({ 'BOTSID': 'party', 'address1': None }) }) pou.put({'BOTSID': 'N1'}, { 'BOTSID': 'N3', 'N302': party.get({ 'BOTSID': 'party', 'address2': None }) }) pou.put({'BOTSID': 'N1'}, { 'BOTSID': 'N4', 'N401': party.get({ 'BOTSID': 'party', 'city': None }) }) pou.put({'BOTSID': 'N1'}, { 'BOTSID': 'N4', 'N402': party.get({ 'BOTSID': 'party', 'state': None }) }) pou.put({'BOTSID': 'N1'}, { 'BOTSID': 'N4', 'N403': party.get({ 'BOTSID': 'party', 'pcode': None }) }) pou.put({'BOTSID': 'N1'}, { 'BOTSID': 'N4', 'N404': party.get({ 'BOTSID': 'party', 'country': None }) }) # loop over lines for po1 in inn.getloop({'BOTSID': 'message'}, {'BOTSID': 'lines'}, {'BOTSID': 'line'}): lou = out.putloop({'BOTSID': 'ST'}, {'BOTSID': 'PO1'}) lou.put({ 'BOTSID': 'PO1', 'PO101': po1.get({ 'BOTSID': 'line', 'linenum': None }) }) lou.put({ 'BOTSID': 'PO1', 'PO102': po1.get({ 'BOTSID': 'line', 'ordqua': None }) }) lou.put({ 'BOTSID': 'PO1', 'PO103': po1.get({ 'BOTSID': 'line', 'ordunit': None }) }) lou.put({ 'BOTSID': 'PO1', 'PO104': po1.get({ 'BOTSID': 'line', 'price': None }) }) offset = 6 gtin = po1.get({'BOTSID': 'line', 'gtin': None}) if gtin: lou.put({ 'BOTSID': 'PO1', 'PO1%02d' % offset: 'UP', 'PO1%02d' % (offset + 1): gtin }) offset += 2 suart = po1.get({'BOTSID': 'line', 'suart': None}) if suart: lou.put({ 'BOTSID': 'PO1', 'PO1%02d' % offset: 'VN', 'PO1%02d' % (offset + 1): suart }) offset += 2 byart = po1.get({'BOTSID': 'line', 'byart': None}) if byart: lou.put({ 'BOTSID': 'PO1', 'PO1%02d' % offset: 'IN', 'PO1%02d' % (offset + 1): byart }) lou.put({'BOTSID': 'PO1'}, { 'BOTSID': 'PID', 'PID01': 'F', 'PID05': po1.get({ 'BOTSID': 'line', 'desc': None }) }) # bots counts line items out.put( {'BOTSID': 'ST'}, { 'BOTSID': 'CTT', 'CTT01': out.getcountoccurrences({'BOTSID': 'ST'}, {'BOTSID': 'PO1'}) }) # SE01: bots counts the segments produced in the X12 message. out.put({'BOTSID': 'ST'}, { 'BOTSID': 'SE', 'SE01': out.getcount() + 1, 'SE02': out.ta_info['reference'].zfill(4) })
def main(inn,out): #sender, receiver is correct via QUERIES in grammar. out.put({'BOTSID':'ST','ST01':'856','ST02':out.ta_info['reference'].zfill(4)}) out.put({'BOTSID':'ST'},{'BOTSID':'BSN','BSN01':'00'}) out.put({'BOTSID':'ST'},{'BOTSID':'BSN', 'BSN02':inn.get({'BOTSID': 'picking'}, {'BOTSID': 'header', 'docnum': None}), 'BSN03':transform.datemask(inn.get({'BOTSID': 'picking'}, {'BOTSID': 'header', 'date_msg': None}),'CCYY-MM-DD HH:mm:ss','CCYYMMDD'), 'BSN04':transform.datemask(inn.get({'BOTSID': 'picking'}, {'BOTSID': 'header', 'date_msg': None}),'CCYY-MM-DD HH:mm:ss','HHmm'), 'BSN05':'0001'}) #0001: Shipment, Order, Packaging, Item #*********************************************************************************************** #shipment level********************************************************************************* hlcounter = 1 #HL segments have sequentail count shipment = out.putloop({'BOTSID':'ST'},{'BOTSID':'HL','HL01':hlcounter,'HL03':'S'}) # TD1: Optional # TD5: Optional currentshipment = hlcounter #remember the current counter, as child-HL segments have to point to this shipment hlcounter += 1 total_ordered_qty = 0 pinn = inn.getloop({'BOTSID': 'picking'}, {'BOTSID': 'pickings'}) for pick in pinn: shipment.put({'BOTSID':'HL'},{'BOTSID':'DTM', 'DTM01':'011', 'DTM02':transform.datemask(pick.get({'BOTSID': 'pickings', 'ship_date': None}),'CCYY-MM-DD HH:mm:ss','CCYYMMDD'), 'DTM03':transform.datemask(pick.get({'BOTSID': 'pickings', 'ship_date': None}),'CCYY-MM-DD HH:mm:ss','HHmm'), 'DTM04':'MS'}) # DTM*069: Optional # N1, N2, N4: Optional ordernode = out.putloop({'BOTSID':'ST'},{'BOTSID':'HL','HL01':hlcounter,'HL02':currentshipment,'HL03':'O'}) currentorder = hlcounter hlcounter += 1 ordernode.put({'BOTSID':'HL'},{'BOTSID':'PRF', 'PRF01':pick.get({'BOTSID': 'pickings', 'order': None})}) ordernode.put({'BOTSID':'HL'},{'BOTSID':'PRF', 'PRF04':transform.datemask(pick.get({'BOTSID': 'pickings', 'order_date': None}),'CCYY-MM-DD HH:mm:ss','CCYYMMDD')}) # REF*VN: Optional # SAC*C: Optional pickingnode = out.putloop({'BOTSID':'ST'},{'BOTSID':'HL','HL01':hlcounter,'HL02':currentorder,'HL03':'P'}) currentpack = hlcounter hlcounter += 1 # MAN*GM: Optional # Tracking number TRACKING = pick.get({'BOTSID': 'pickings', 'tracking_number': None}) or '' if TRACKING: pickingnode.put({'BOTSID':'HL'},{'BOTSID':'REF','REF01':'CN','REF02':TRACKING}) #*************************************************************************************************** #line/article level********************************************************************************* #loop over all lines that have this sscc plines = pick.getloop({'BOTSID': 'pickings'}, {'BOTSID': 'line'}) for pline in plines: itemnode = out.putloop({'BOTSID':'ST'},{'BOTSID':'HL','HL01':hlcounter,'HL02':currentpack,'HL03':'I'}) hlcounter += 1 itemnode.put({'BOTSID':'HL'},{'BOTSID':'LIN', 'LIN01':pline.get({'BOTSID':'line','seq':None}), 'LIN02':'SK', 'LIN03':pline.get({'BOTSID':'line','product':None})}) ordered_qty = pline.get({'BOTSID':'line','ordered_qty':None}) total_ordered_qty += ordered_qty and int(ordered_qty) or 0 itemnode.put({'BOTSID':'HL'},{'BOTSID':'SN1', 'SN101':pline.get({'BOTSID':'line','seq':None}), 'SN102':pline.get({'BOTSID':'line','product_qty':None}), 'SN103':'EA', 'SN105':ordered_qty, 'SN106':'EA'}) out.put({'BOTSID':'ST'},{'BOTSID':'CTT', 'CTT01':out.getcountoccurrences({'BOTSID':'LIN'}), 'CTT01':total_ordered_qty}) out.put({'BOTSID':'ST'},{'BOTSID':'SE','SE01':out.getcount()+1,'SE02':out.ta_info['reference'].zfill(4)}) #SE01: bots counts the segments produced in the X12 message.
def main(inn, out): out.put({ 'BOTSID': 'ST', 'ST01': '850', 'ST02': out.ta_info['reference'].zfill(4) }) #pick up some values from ISA envelope #~ out.put({'BOTSID':'message','sender':inn.ta_info['frompartner']}) #~ out.put({'BOTSID':'message','receiver':inn.ta_info['topartner']}) #~ out.put({'BOTSID':'message','testindicator':inn.ta_info['testindicator']}) #pick up document number. is used in bots to give 'document-view' docnum = inn.get({'BOTSID': 'message', 'docnum': None}) out.put({'BOTSID': 'ST'}, { 'BOTSID': 'BEG', 'BEG01': '00', 'BEG03': docnum }) inn.ta_info['botskey'] = docnum out.ta_info['botskey'] = docnum out.put({'BOTSID': 'ST'}, { 'BOTSID': 'BEG', 'BEG02': inn.get({ 'BOTSID': 'message', 'docsrt': None }) }) #convert dates to right internal format docdtm = inn.get({'BOTSID': 'message', 'docdtm': None}) docdtm = transform.datemask(docdtm, 'CCYY-MM-DD', 'CCYYMMDD') out.put({'BOTSID': 'ST'}, {'BOTSID': 'BEG', 'BEG05': docdtm}) #same date handling as above, now in a one-liner. out.put({'BOTSID': 'ST'}, { 'BOTSID': 'DTM', 'DTM01': '002', 'DTM02': transform.datemask(inn.get({ 'BOTSID': 'message', 'deldtm': None }), 'CCYY-MM-DD', 'CCYYMMDD') }) out.put({'BOTSID': 'ST'}, { 'BOTSID': 'DTM', 'DTM01': '064', 'DTM02': transform.datemask(inn.get({ 'BOTSID': 'message', 'earldeldtm': None }), 'CCYY-MM-DD', 'CCYYMMDD') }) out.put({'BOTSID': 'ST'}, { 'BOTSID': 'DTM', 'DTM01': '063', 'DTM02': transform.datemask(inn.get({ 'BOTSID': 'message', 'latedeldtm': None }), 'CCYY-MM-DD', 'CCYYMMDD') }) out.put({'BOTSID': 'ST'}, { 'BOTSID': 'CUR', 'CUR01': 'BY', 'CUR02': inn.get({ 'BOTSID': 'message', 'currency': None }) }) #loop over partys for party in inn.getloop({'BOTSID': 'message'}, {'BOTSID': 'partys'}, {'BOTSID': 'party'}): pou = out.putloop({'BOTSID': 'ST'}, {'BOTSID': 'N1'}) pou.put({ 'BOTSID': 'N1', 'N101': party.get({ 'BOTSID': 'party', 'qual': None }) }) #write partyID: if gln write it, else DUNS etc #this uses the fact the out.put retunr True if succeeded. if pou.put({ 'BOTSID': 'N1', 'N103': 'UL', 'N104': party.get({ 'BOTSID': 'party', 'gln': None }) }): pass elif pou.put({ 'BOTSID': 'N1', 'N103': '1', 'N104': party.get({ 'BOTSID': 'party', 'DUNS': None }) }): pass elif pou.put({ 'BOTSID': 'N1', 'N103': '92', 'N104': party.get({ 'BOTSID': 'party', 'externalID': None }) }): pass else: pou.put({ 'BOTSID': 'N1', 'N103': '91', 'N104': party.get({ 'BOTSID': 'party', 'internalID': None }) }) pou.put({ 'BOTSID': 'N1', 'N102': party.get({ 'BOTSID': 'party', 'name1': None }) }) pou.put({'BOTSID': 'N1'}, { 'BOTSID': 'N2', 'N201': party.get({ 'BOTSID': 'party', 'name2': None }) }) pou.put({'BOTSID': 'N1'}, { 'BOTSID': 'N3', 'N301': party.get({ 'BOTSID': 'party', 'address1': None }) }) pou.put({'BOTSID': 'N1'}, { 'BOTSID': 'N3', 'N302': party.get({ 'BOTSID': 'party', 'address2': None }) }) pou.put({'BOTSID': 'N1'}, { 'BOTSID': 'N4', 'N401': party.get({ 'BOTSID': 'party', 'city': None }) }) pou.put({'BOTSID': 'N1'}, { 'BOTSID': 'N4', 'N402': party.get({ 'BOTSID': 'party', 'state': None }) }) pou.put({'BOTSID': 'N1'}, { 'BOTSID': 'N4', 'N403': party.get({ 'BOTSID': 'party', 'pcode': None }) }) pou.put({'BOTSID': 'N1'}, { 'BOTSID': 'N4', 'N404': party.get({ 'BOTSID': 'party', 'country': None }) }) #loop over lines for po1 in inn.getloop({'BOTSID': 'message'}, {'BOTSID': 'lines'}, {'BOTSID': 'line'}): lou = out.putloop({'BOTSID': 'ST'}, {'BOTSID': 'PO1'}) lou.put({ 'BOTSID': 'PO1', 'PO101': po1.get({ 'BOTSID': 'line', 'linenum': None }) }) lou.put({ 'BOTSID': 'PO1', 'PO102': po1.get({ 'BOTSID': 'line', 'ordqua': None }) }) lou.put({ 'BOTSID': 'PO1', 'PO103': po1.get({ 'BOTSID': 'line', 'ordunit': None }) }) lou.put({ 'BOTSID': 'PO1', 'PO104': po1.get({ 'BOTSID': 'line', 'price': None }) }) offset = 6 gtin = po1.get({'BOTSID': 'line', 'gtin': None}) if gtin: lou.put({ 'BOTSID': 'PO1', 'PO1%02d' % offset: 'UP', 'PO1%02d' % (offset + 1): gtin }) offset += 2 suart = po1.get({'BOTSID': 'line', 'suart': None}) if suart: lou.put({ 'BOTSID': 'PO1', 'PO1%02d' % offset: 'VN', 'PO1%02d' % (offset + 1): suart }) offset += 2 byart = po1.get({'BOTSID': 'line', 'byart': None}) if byart: lou.put({ 'BOTSID': 'PO1', 'PO1%02d' % offset: 'IN', 'PO1%02d' % (offset + 1): byart }) lou.put({'BOTSID': 'PO1'}, { 'BOTSID': 'PID', 'PID01': 'F', 'PID05': po1.get({ 'BOTSID': 'line', 'desc': None }) }) out.put( {'BOTSID': 'ST'}, { 'BOTSID': 'CTT', 'CTT01': out.getcountoccurrences({'BOTSID': 'ST'}, {'BOTSID': 'PO1'}) }) #bots counts line items out.put({'BOTSID': 'ST'}, { 'BOTSID': 'SE', 'SE01': out.getcount() + 1, 'SE02': out.ta_info['reference'].zfill(4) }) #SE01: bots counts the segments produced in the X12 message.
def main(inn, out): #sender, receiver is correct via QUERIES in grammar. out.put({ 'BOTSID': 'ST', 'ST01': '856', 'ST02': out.ta_info['reference'].zfill(4) }) out.put({'BOTSID': 'ST'}, {'BOTSID': 'BSN', 'BSN01': '00'}) out.put({'BOTSID': 'ST'}, { 'BOTSID': 'BSN', 'BSN02': inn.get({'BOTSID': 'picking'}, { 'BOTSID': 'header', 'docnum': None }), 'BSN03': transform.datemask( inn.get({'BOTSID': 'picking'}, { 'BOTSID': 'header', 'date_msg': None }), 'CCYY-MM-DD HH:mm:ss', 'CCYYMMDD'), 'BSN04': transform.datemask( inn.get({'BOTSID': 'picking'}, { 'BOTSID': 'header', 'date_msg': None }), 'CCYY-MM-DD HH:mm:ss', 'HHmm'), 'BSN05': '0001' }) #0001: Shipment, Order, Packaging, Item #*********************************************************************************************** #shipment level********************************************************************************* hlcounter = 1 #HL segments have sequentail count shipment = out.putloop({'BOTSID': 'ST'}, { 'BOTSID': 'HL', 'HL01': hlcounter, 'HL03': 'S' }) # TD1: Optional # TD5: Optional currentshipment = hlcounter #remember the current counter, as child-HL segments have to point to this shipment hlcounter += 1 total_ordered_qty = 0 pinn = inn.getloop({'BOTSID': 'picking'}, {'BOTSID': 'pickings'}) for pick in pinn: shipment.put({'BOTSID': 'HL'}, { 'BOTSID': 'DTM', 'DTM01': '011', 'DTM02': transform.datemask( pick.get({ 'BOTSID': 'pickings', 'ship_date': None }), 'CCYY-MM-DD HH:mm:ss', 'CCYYMMDD'), 'DTM03': transform.datemask( pick.get({ 'BOTSID': 'pickings', 'ship_date': None }), 'CCYY-MM-DD HH:mm:ss', 'HHmm'), 'DTM04': 'MS' }) # DTM*069: Optional # N1, N2, N4: Optional ordernode = out.putloop({'BOTSID': 'ST'}, { 'BOTSID': 'HL', 'HL01': hlcounter, 'HL02': currentshipment, 'HL03': 'O' }) currentorder = hlcounter hlcounter += 1 ordernode.put({'BOTSID': 'HL'}, { 'BOTSID': 'PRF', 'PRF01': pick.get({ 'BOTSID': 'pickings', 'order': None }) }) ordernode.put({'BOTSID': 'HL'}, { 'BOTSID': 'PRF', 'PRF04': transform.datemask( pick.get({ 'BOTSID': 'pickings', 'order_date': None }), 'CCYY-MM-DD HH:mm:ss', 'CCYYMMDD') }) # REF*VN: Optional # SAC*C: Optional pickingnode = out.putloop({'BOTSID': 'ST'}, { 'BOTSID': 'HL', 'HL01': hlcounter, 'HL02': currentorder, 'HL03': 'P' }) currentpack = hlcounter hlcounter += 1 # MAN*GM: Optional # Tracking number TRACKING = pick.get({ 'BOTSID': 'pickings', 'tracking_number': None }) or '' if TRACKING: pickingnode.put({'BOTSID': 'HL'}, { 'BOTSID': 'REF', 'REF01': 'CN', 'REF02': TRACKING }) #*************************************************************************************************** #line/article level********************************************************************************* #loop over all lines that have this sscc plines = pick.getloop({'BOTSID': 'pickings'}, {'BOTSID': 'line'}) for pline in plines: itemnode = out.putloop({'BOTSID': 'ST'}, { 'BOTSID': 'HL', 'HL01': hlcounter, 'HL02': currentpack, 'HL03': 'I' }) hlcounter += 1 itemnode.put( {'BOTSID': 'HL'}, { 'BOTSID': 'LIN', 'LIN01': pline.get({ 'BOTSID': 'line', 'seq': None }), 'LIN02': 'SK', 'LIN03': pline.get({ 'BOTSID': 'line', 'product': None }) }) ordered_qty = pline.get({'BOTSID': 'line', 'ordered_qty': None}) total_ordered_qty += ordered_qty and int(ordered_qty) or 0 itemnode.put( {'BOTSID': 'HL'}, { 'BOTSID': 'SN1', 'SN101': pline.get({ 'BOTSID': 'line', 'seq': None }), 'SN102': pline.get({ 'BOTSID': 'line', 'product_qty': None }), 'SN103': 'EA', 'SN105': ordered_qty, 'SN106': 'EA' }) out.put({'BOTSID': 'ST'}, { 'BOTSID': 'CTT', 'CTT01': out.getcountoccurrences({'BOTSID': 'LIN'}), 'CTT01': total_ordered_qty }) out.put({'BOTSID': 'ST'}, { 'BOTSID': 'SE', 'SE01': out.getcount() + 1, 'SE02': out.ta_info['reference'].zfill(4) }) #SE01: bots counts the segments produced in the X12 message.
def main(inn, out): # ISA,GS,ST sender = inn.ta_info['frompartner'] receiver = inn.ta_info['topartner'] testindicator = inn.ta_info['testindicator'] out.put({'BOTSID': 'message', 'sender': sender}) out.put({'BOTSID': 'message', 'receiver': receiver}) out.put({'BOTSID': 'message', 'testindicator': testindicator}) # BSN shipmentnum = inn.get({'BOTSID': 'ST'}, {'BOTSID': 'BSN', 'BSN02': None}) out.ta_info['botskey'] = shipmentnum asndate = transform.datemask( inn.get({'BOTSID': 'ST'}, { 'BOTSID': 'BSN', 'BSN03': None }), 'CCYYMMDD', 'CCYY-MM-DD') asntime = inn.get({'BOTSID': 'ST'}, {'BOTSID': 'BSN', 'BSN04': None}) out.put({'BOTSID': 'message', 'docnum': shipmentnum}) out.put({'BOTSID': 'message', 'docdtm': asndate}) out.put({'BOTSID': 'message', 'doctime': asntime}) # shipment level/loop shipmentLoop = inn.getloop({'BOTSID': 'ST'}, { 'BOTSID': 'HL', 'HL01': '1', 'HL03': 'S' }) for shipment in shipmentLoop: #TD5 scac = shipment.get({'BOTSID': 'HL'}, { 'BOTSID': 'TD5', 'TD501': 'O', 'TD502': '2', 'TD503': None }) out.put({'BOTSID': 'message', 'scac': scac}) # REF bol = shipment.get({'BOTSID': 'HL'}, { 'BOTSID': 'REF', 'REF01': 'BM', 'REF02': None }) carrierref = shipment.get({'BOTSID': 'HL'}, { 'BOTSID': 'REF', 'REF01': 'CN', 'REF02': None }) out.put({'BOTSID': 'message', 'bol': bol}) out.put({'BOTSID': 'message', 'carrierreferencenumber': carrierref}) # DTM shipdate = transform.datemask( shipment.get({'BOTSID': 'HL'}, { 'BOTSID': 'DTM', 'DTM01': '011', 'DTM02': None }), 'CCYYMMDD', 'CCYY-MM-DD') deliverydate = transform.datemask( shipment.get({'BOTSID': 'HL'}, { 'BOTSID': 'DTM', 'DTM01': '017', 'DTM02': None }), 'CCYYMMDD', 'CCYY-MM-DD') out.put({'BOTSID': 'message', 'shipdtm': shipdate}) out.put({'BOTSID': 'message', 'deldtm': deliverydate}) # N1 loop on shipment level partysLoop = shipment.getloop({'BOTSID': 'HL'}, {'BOTSID': 'N1'}) for party in partysLoop: partyout = out.putloop({'BOTSID': 'message'}, {'BOTSID': 'partys'}, {'BOTSID': 'party'}) # N1 partyQual = party.get({'BOTSID': 'N1', 'N101': None}) # get DUNS number. 2 qualifiers are used; helper function transform.useoneof checks both duns = transform.useoneof( party.get({ 'BOTSID': 'N1', 'N103': '1', 'N104': None }), party.get({ 'BOTSID': 'N1', 'N103': '9', 'N104': None })) externalID = party.get({ 'BOTSID': 'N1', 'N103': '92', 'N104': None }) internalID = party.get({ 'BOTSID': 'N1', 'N103': '91', 'N104': None }) name1 = party.get({'BOTSID': 'N1', 'N102': None}) partyout.put({'BOTSID': 'party', 'qual': partyQual}) partyout.put({'BOTSID': 'party', 'DUNS': duns}) partyout.put({'BOTSID': 'party', 'externalID': externalID}) partyout.put({'BOTSID': 'party', 'internalID': internalID}) partyout.put({'BOTSID': 'party', 'name1': name1}) # N2 name2 = party.get({'BOTSID': 'N1'}, {'BOTSID': 'N2', 'N201': None}) partyout.put({'BOTSID': 'party', 'name2': name2}) # N3 address1 = party.get({'BOTSID': 'N1'}, { 'BOTSID': 'N3', 'N301': None }) address2 = party.get({'BOTSID': 'N1'}, { 'BOTSID': 'N3', 'N302': None }) partyout.put({'BOTSID': 'party', 'address1': address1}) partyout.put({'BOTSID': 'party', 'address2': address2}) # N4 city = party.get({'BOTSID': 'N1'}, {'BOTSID': 'N4', 'N401': None}) region = party.get({'BOTSID': 'N1'}, { 'BOTSID': 'N4', 'N402': None }) zipcode = party.get({'BOTSID': 'N1'}, { 'BOTSID': 'N4', 'N403': None }) country = party.get({'BOTSID': 'N1'}, { 'BOTSID': 'N4', 'N404': None }) partyout.put({'BOTSID': 'party', 'city': city}) partyout.put({'BOTSID': 'party', 'state': region}) partyout.put({'BOTSID': 'party', 'pcode': zipcode}) partyout.put({'BOTSID': 'party', 'country': country}) # order level/loop orderLoop = inn.getloop({'BOTSID': 'ST'}, {'BOTSID': 'HL', 'HL03': 'O'}) for in_order in orderLoop: out_order = out.putloop({'BOTSID': 'message'}, {'BOTSID': 'orders'}, {'BOTSID': 'order'}) current_order = in_order.get({'BOTSID': 'HL', 'HL01': None}) # PRF order_number = in_order.get({'BOTSID': 'HL'}, { 'BOTSID': 'PRF', 'PRF01': None }) orderdate = transform.datemask( in_order.get({'BOTSID': 'HL'}, { 'BOTSID': 'PRF', 'PRF04': None }), 'CCYYMMDD', 'CCYY-MM-DD') out_order.put({'BOTSID': 'order', 'ordernumber': order_number}) out_order.put({'BOTSID': 'order', 'orderdtm': orderdate}) # pack/sscc level/loop packs = inn.getloop({'BOTSID': 'ST'}, { 'BOTSID': 'HL', 'HL02': current_order, 'HL03': 'P' }) for in_pack in packs: current_sscc = in_pack.get({'BOTSID': 'HL', 'HL01': None}) sscc = in_pack.get({'BOTSID': 'HL'}, { 'BOTSID': 'MAN', 'MAN01': 'GM', 'MAN02': None }) # linelevel/loop # loop over all lines that have this sscc linesinpack = inn.getloop({'BOTSID': 'ST'}, { 'BOTSID': 'HL', 'HL02': current_sscc, 'HL03': 'I' }) for line in linesinpack: lineout = out_order.putloop({'BOTSID': 'order'}, {'BOTSID': 'lines'}, {'BOTSID': 'line'}) # LIN linenum = line.get({'BOTSID': 'HL'}, { 'BOTSID': 'LIN', 'LIN01': None }) gtin = line.get({'BOTSID': 'HL'}, { 'BOTSID': 'LIN', 'LIN02': 'UP', 'LIN03': None }) lineout.put({'BOTSID': 'line', 'linenum': linenum}) lineout.put({'BOTSID': 'line', 'gtin': gtin}) # SN1 deliveryquantity = line.get({'BOTSID': 'HL'}, { 'BOTSID': 'SN1', 'SN103': 'EA', 'SN102': None }) orderquantity = line.get({'BOTSID': 'HL'}, { 'BOTSID': 'SN1', 'SN106': 'EA', 'SN105': None }) lineout.put({'BOTSID': 'line', 'delqua': deliveryquantity}) lineout.put({'BOTSID': 'line', 'ordqua': orderquantity}) # PID descritpion = line.get({'BOTSID': 'HL'}, { 'BOTSID': 'PID', 'PID01': 'F', 'PID02': '08', 'PID05': None }) lineout.put({'BOTSID': 'line', 'desc': descritpion}) lineout.put({'BOTSID': 'line', 'sscc': sscc})
def main(inn, out): #sender, receiver is correct via QUERIES in grammar. out.put({ 'BOTSID': 'ST', 'ST01': '810', 'ST02': out.ta_info['reference'].zfill(4) }) out.put({'BOTSID': 'ST'}, { 'BOTSID': 'BIG', 'BIG01': transform.datemask(inn.get({ 'BOTSID': 'message', 'docdtm': None }), 'CCYY-MM-DD HH:mm', 'CCYYMMDD') }) out.put({'BOTSID': 'ST'}, { 'BOTSID': 'BIG', 'BIG02': inn.get({ 'BOTSID': 'message', 'docnum': None }) }) out.put({'BOTSID': 'ST'}, { 'BOTSID': 'BIG', 'BIG04': inn.get({ 'BOTSID': 'message', 'ordernumber': None }) }) out.put({'BOTSID': 'ST'}, { 'BOTSID': 'BIG', 'BIG07': 'DR' }) #credit or debit out.put({'BOTSID': 'ST'}, { 'BOTSID': 'DTM', 'DTM01': '999', 'DTM02': transform.datemask(inn.get({ 'BOTSID': 'message', 'deldtm': None }), 'CCYY-MM-DD HH:mm', 'CCYYMMDD') }) out.put( {'BOTSID': 'ST'}, { 'BOTSID': 'ITD', 'ITD03': inn.get({ 'BOTSID': 'message', 'termsdiscountpercent': None }) }) out.put( {'BOTSID': 'ST'}, { 'BOTSID': 'ITD', 'ITD05': inn.get({ 'BOTSID': 'message', 'termsdiscountdaysdue': None }) }) out.put({'BOTSID': 'ST'}, { 'BOTSID': 'ITD', 'ITD07': inn.get({ 'BOTSID': 'message', 'termsnetdays': None }) }) out.put({'BOTSID': 'ST'}, { 'BOTSID': 'ITD', 'ITD08': inn.get({ 'BOTSID': 'message', 'totaltermsdiscount': None }) }) #loop over partys for party in inn.getloop({'BOTSID': 'message'}, {'BOTSID': 'partys'}, {'BOTSID': 'party'}): pou = out.putloop({'BOTSID': 'ST'}, {'BOTSID': 'N1'}) pou.put({ 'BOTSID': 'N1', 'N101': party.get({ 'BOTSID': 'party', 'qual': None }) }) #write partyID: if gln write it, else DUNS etc #this uses the fact the out.put retunr True if succeeded. if pou.put({ 'BOTSID': 'N1', 'N103': 'UL', 'N104': party.get({ 'BOTSID': 'party', 'gln': None }) }): pass elif pou.put({ 'BOTSID': 'N1', 'N103': '1', 'N104': party.get({ 'BOTSID': 'party', 'DUNS': None }) }): pass elif pou.put({ 'BOTSID': 'N1', 'N103': '92', 'N104': party.get({ 'BOTSID': 'party', 'externalID': None }) }): pass else: pou.put({ 'BOTSID': 'N1', 'N103': '91', 'N104': party.get({ 'BOTSID': 'party', 'internalID': None }) }) pou.put({ 'BOTSID': 'N1', 'N102': party.get({ 'BOTSID': 'party', 'name1': None }) }) pou.put({'BOTSID': 'N1'}, { 'BOTSID': 'N2', 'N201': party.get({ 'BOTSID': 'party', 'name2': None }) }) pou.put({'BOTSID': 'N1'}, { 'BOTSID': 'N3', 'N301': party.get({ 'BOTSID': 'party', 'address1': None }) }) pou.put({'BOTSID': 'N1'}, { 'BOTSID': 'N3', 'N302': party.get({ 'BOTSID': 'party', 'address2': None }) }) pou.put({'BOTSID': 'N1'}, { 'BOTSID': 'N4', 'N401': party.get({ 'BOTSID': 'party', 'city': None }) }) pou.put({'BOTSID': 'N1'}, { 'BOTSID': 'N4', 'N402': party.get({ 'BOTSID': 'party', 'state': None }) }) pou.put({'BOTSID': 'N1'}, { 'BOTSID': 'N4', 'N403': party.get({ 'BOTSID': 'party', 'pcode': None }) }) pou.put({'BOTSID': 'N1'}, { 'BOTSID': 'N4', 'N404': party.get({ 'BOTSID': 'party', 'country': None }) }) #loop over lines*************************************** for lin in inn.getloop({'BOTSID': 'message'}, {'BOTSID': 'lines'}, {'BOTSID': 'line'}): lou = out.putloop({'BOTSID': 'ST'}, {'BOTSID': 'IT1'}) lou.put({ 'BOTSID': 'IT1', 'IT101': lin.get({ 'BOTSID': 'line', 'linenum': None }) }) lou.put({ 'BOTSID': 'IT1', 'IT103': 'EA', 'IT102': lin.get({ 'BOTSID': 'line', 'invqua': None }) }) lou.put({ 'BOTSID': 'IT1', 'IT104': lin.get({ 'BOTSID': 'line', 'price': None }) }) lou.put({ 'BOTSID': 'IT1', 'IT106': 'VN', 'IT107': lin.get({ 'BOTSID': 'line', 'suart': None }) }) lou.put({ 'BOTSID': 'IT1', 'IT108': 'UP', 'IT109': lin.get({ 'BOTSID': 'line', 'gtin': None }) }) lou.put({ 'BOTSID': 'IT1', 'IT110': 'BP', 'IT111': lin.get({ 'BOTSID': 'line', 'byart': None }) }) lou.put({'BOTSID': 'IT1'}, { 'BOTSID': 'PID', 'PID01': 'F', 'PID05': lin.get({ 'BOTSID': 'line', 'desc': None }) }) out.put({'BOTSID': 'ST'}, { 'BOTSID': 'TDS', 'TDS01': inn.get({ 'BOTSID': 'message', 'totalinvoiceamount': None }) }) out.put({'BOTSID': 'ST'}, { 'BOTSID': 'ISS', 'ISS02': 'EA', 'ISS01': out.getcountsum({'BOTSID': 'ST'}, { 'BOTSID': 'IT1', 'IT102': None }) }) #bots counts total Number of Units Shipped out.put( {'BOTSID': 'ST'}, { 'BOTSID': 'CTT', 'CTT01': out.getcountoccurrences({'BOTSID': 'ST'}, {'BOTSID': 'IT1'}) }) #bots counts number of line items/IT1 segments out.put({'BOTSID': 'ST'}, { 'BOTSID': 'SE', 'SE01': out.getcount() + 1, 'SE02': out.ta_info['reference'].zfill(4) }) #SE01: bots counts the segments produced in the X12 message.
def main(inn, out): #pick up some values from ISA envelope out.put({'BOTSID': 'message', 'sender': inn.ta_info['frompartner']}) out.put({'BOTSID': 'message', 'receiver': inn.ta_info['topartner']}) out.put({ 'BOTSID': 'message', 'testindicator': inn.ta_info['testindicator'] }) out.put({ 'BOTSID': 'message', 'docnum': inn.get({'BOTSID': 'ST'}, { 'BOTSID': 'BSN', 'BSN02': None }) }) out.put({ 'BOTSID': 'message', 'docdtm': transform.datemask( inn.get({'BOTSID': 'ST'}, { 'BOTSID': 'BSN', 'BSN03': None }), 'CCYYMMDD', 'CCYY-MM-DD') }) out.put({ 'BOTSID': 'message', 'doctime': inn.get({'BOTSID': 'ST'}, { 'BOTSID': 'BSN', 'BSN04': None }) }) #*********************************************************************************************** #shipment level********************************************************************************* for shipment in inn.getloop({'BOTSID': 'ST'}, { 'BOTSID': 'HL', 'HL01': '1', 'HL03': 'S' }): #~ hlcounter = 1 #HL segments have sequentail count #~ shipment = out.putloop({'BOTSID':'ST'},{'BOTSID':'HL','HL01':hlcounter,'HL03':'S'}) #~ currentshipment = hlcounter #remember the current counter, as child-HL segments have to point to this shipment #~ hlcounter += 1 out.put({ 'BOTSID': 'message', 'scac': shipment.get({'BOTSID': 'HL'}, { 'BOTSID': 'TD5', 'TD501': 'O', 'TD502': '2', 'TD503': None }) }) out.put({ 'BOTSID': 'message', 'bol': shipment.get({'BOTSID': 'HL'}, { 'BOTSID': 'REF', 'REF01': 'BM', 'REF02': None }) }) out.put({ 'BOTSID': 'message', 'carrierreferencenumber': shipment.get({'BOTSID': 'HL'}, { 'BOTSID': 'REF', 'REF01': 'CN', 'REF02': None }) }) out.put({ 'BOTSID': 'message', 'shipdtm': transform.datemask( shipment.get({'BOTSID': 'HL'}, { 'BOTSID': 'DTM', 'DTM01': '011', 'DTM02': None }), 'CCYYMMDD', 'CCYY-MM-DD') }) out.put({ 'BOTSID': 'message', 'deldtm': transform.datemask( shipment.get({'BOTSID': 'HL'}, { 'BOTSID': 'DTM', 'DTM01': '017', 'DTM02': None }), 'CCYYMMDD', 'CCYY-MM-DD') }) #loop over partys on shipment level for party in shipment.getloop({'BOTSID': 'HL'}, {'BOTSID': 'N1'}): pou = out.putloop({'BOTSID': 'message'}, {'BOTSID': 'partys'}, {'BOTSID': 'party'}) pou.put({ 'BOTSID': 'party', 'qual': party.get({ 'BOTSID': 'N1', 'N101': None }) }) pou.put({ 'BOTSID': 'party', 'gln': party.get({ 'BOTSID': 'N1', 'N103': 'UL', 'N104': None }) }) #get DUNS number. 2 qualifiers are used; helper function transform.useoneof checks both pou.put({ 'BOTSID': 'party', 'DUNS': transform.useoneof( party.get({ 'BOTSID': 'N1', 'N103': '1', 'N104': None }), party.get({ 'BOTSID': 'N1', 'N103': '9', 'N104': None })) }) pou.put({ 'BOTSID': 'party', 'externalID': party.get({ 'BOTSID': 'N1', 'N103': '92', 'N104': None }) }) pou.put({ 'BOTSID': 'party', 'internalID': party.get({ 'BOTSID': 'N1', 'N103': '91', 'N104': None }) }) pou.put({ 'BOTSID': 'party', 'name1': party.get({ 'BOTSID': 'N1', 'N102': None }) }) pou.put({ 'BOTSID': 'party', 'name2': party.get({'BOTSID': 'N1'}, { 'BOTSID': 'N2', 'N201': None }) }) pou.put({ 'BOTSID': 'party', 'address1': party.get({'BOTSID': 'N1'}, { 'BOTSID': 'N3', 'N301': None }) }) pou.put({ 'BOTSID': 'party', 'address2': party.get({'BOTSID': 'N1'}, { 'BOTSID': 'N3', 'N302': None }) }) pou.put({ 'BOTSID': 'party', 'city': party.get({'BOTSID': 'N1'}, { 'BOTSID': 'N4', 'N401': None }) }) pou.put({ 'BOTSID': 'party', 'state': party.get({'BOTSID': 'N1'}, { 'BOTSID': 'N4', 'N402': None }) }) pou.put({ 'BOTSID': 'party', 'pcode': party.get({'BOTSID': 'N1'}, { 'BOTSID': 'N4', 'N403': None }) }) pou.put({ 'BOTSID': 'party', 'country': party.get({'BOTSID': 'N1'}, { 'BOTSID': 'N4', 'N404': None }) }) #******************************************************************************************** #order level********************************************************************************* for in_order in inn.getloop({'BOTSID': 'ST'}, { 'BOTSID': 'HL', 'HL03': 'O' }): out_order = out.putloop({'BOTSID': 'message'}, {'BOTSID': 'orders'}, {'BOTSID': 'order'}) out_order.put({ 'BOTSID': 'order', 'ordernumber': in_order.get({'BOTSID': 'HL'}, { 'BOTSID': 'PRF', 'PRF01': None }) }) out_order.put({ 'BOTSID': 'order', 'orderdtm': transform.datemask( in_order.get({'BOTSID': 'HL'}, { 'BOTSID': 'PRF', 'PRF04': None }), 'CCYYMMDD', 'CCYY-MM-DD') }) current_order = in_order.get({'BOTSID': 'HL', 'HL01': None}) #pack/sscc level********************************************************************************* for in_sscc in inn.getloop({'BOTSID': 'ST'}, { 'BOTSID': 'HL', 'HL02': current_order, 'HL03': 'P' }): current_sscc = in_sscc.get({'BOTSID': 'HL', 'HL01': None}) sscc = in_sscc.get({'BOTSID': 'HL'}, { 'BOTSID': 'MAN', 'MAN01': 'GM', 'MAN02': None }) #line/article level********************************************************************************* #loop over all lines that have this sscc for lin in inn.getloop({'BOTSID': 'ST'}, { 'BOTSID': 'HL', 'HL02': current_sscc, 'HL03': 'I' }): lou = out_order.putloop({'BOTSID': 'order'}, {'BOTSID': 'lines'}, {'BOTSID': 'line'}) lou.put({ 'BOTSID': 'line', 'linenum': lin.get({'BOTSID': 'HL'}, { 'BOTSID': 'LIN', 'LIN01': None }) }) lou.put({ 'BOTSID': 'line', 'gtin': lin.get({'BOTSID': 'HL'}, { 'BOTSID': 'LIN', 'LIN02': 'UP', 'LIN03': None }) }) lou.put({ 'BOTSID': 'line', 'delqua': lin.get({'BOTSID': 'HL'}, { 'BOTSID': 'SN1', 'SN103': 'EA', 'SN102': None }) }) lou.put({ 'BOTSID': 'line', 'ordqua': lin.get({'BOTSID': 'HL'}, { 'BOTSID': 'SN1', 'SN106': 'EA', 'SN105': None }) }) lou.put({ 'BOTSID': 'line', 'desc': lin.get({'BOTSID': 'HL'}, { 'BOTSID': 'PID', 'PID01': 'F', 'PID02': '08', 'PID05': None }) }) lou.put({'BOTSID': 'line', 'sscc': sscc})
def main(inn, out): #sender, receiver is correct via QUERIES in grammar. out.put({ 'BOTSID': 'ST', 'ST01': '856', 'ST02': out.ta_info['reference'].zfill(4) }) out.put({'BOTSID': 'ST'}, {'BOTSID': 'BSN', 'BSN01': '00'}) out.put({'BOTSID': 'ST'}, { 'BOTSID': 'BSN', 'BSN02': inn.get({ 'BOTSID': 'message', 'docnum': None }) }) out.put({'BOTSID': 'ST'}, { 'BOTSID': 'BSN', 'BSN03': transform.datemask(inn.get({ 'BOTSID': 'message', 'docdtm': None }), 'CCYY-MM-DD HH:mm', 'CCYYMMDD') }) out.put({'BOTSID': 'ST'}, { 'BOTSID': 'BSN', 'BSN04': transform.useoneof(inn.get({ 'BOTSID': 'message', 'doctime': None }), '0000') }) out.put({'BOTSID': 'ST'}, { 'BOTSID': 'BSN', 'BSN05': '0001' }) #0001: Shipment, Order, Packaging, Item #*********************************************************************************************** #shipment level********************************************************************************* hlcounter = 1 #HL segments have sequentail count shipment = out.putloop({'BOTSID': 'ST'}, { 'BOTSID': 'HL', 'HL01': hlcounter, 'HL03': 'S' }) currentshipment = hlcounter #remember the current counter, as child-HL segments have to point to this shipment hlcounter += 1 shipment.put({'BOTSID': 'HL'}, { 'BOTSID': 'TD5', 'TD501': 'O', 'TD502': '2', 'TD503': inn.get({ 'BOTSID': 'message', 'scac': None }) }) shipment.put({'BOTSID': 'HL'}, { 'BOTSID': 'REF', 'REF01': 'BM', 'REF02': inn.get({ 'BOTSID': 'message', 'bol': None }) }) shipment.put( {'BOTSID': 'HL'}, { 'BOTSID': 'REF', 'REF01': 'CN', 'REF02': inn.get({ 'BOTSID': 'message', 'carrierreferencenumber': None }) }) shipment.put({'BOTSID': 'HL'}, { 'BOTSID': 'DTM', 'DTM01': '011', 'DTM02': transform.datemask(inn.get({ 'BOTSID': 'message', 'shipdtm': None }), 'CCYY-MM-DD HH:mm', 'CCYYMMDD') }) shipment.put({'BOTSID': 'HL'}, { 'BOTSID': 'DTM', 'DTM01': '017', 'DTM02': transform.datemask(inn.get({ 'BOTSID': 'message', 'deldtm': None }), 'CCYY-MM-DD HH:mm', 'CCYYMMDD') }) #loop over partys (all on shipment level for simplicity ;-) for party in inn.getloop({'BOTSID': 'message'}, {'BOTSID': 'partys'}, {'BOTSID': 'party'}): pou = shipment.putloop({'BOTSID': 'HL'}, {'BOTSID': 'N1'}) pou.put({ 'BOTSID': 'N1', 'N101': party.get({ 'BOTSID': 'party', 'qual': None }) }) #write partyID: if gln write it, else DUNS etc #this uses the fact the out.put returns True if succeeded. if pou.put({ 'BOTSID': 'N1', 'N103': 'UL', 'N104': party.get({ 'BOTSID': 'party', 'gln': None }) }): pass elif pou.put({ 'BOTSID': 'N1', 'N103': '1', 'N104': party.get({ 'BOTSID': 'party', 'DUNS': None }) }): pass elif pou.put({ 'BOTSID': 'N1', 'N103': '92', 'N104': party.get({ 'BOTSID': 'party', 'externalID': None }) }): pass else: pou.put({ 'BOTSID': 'N1', 'N103': '91', 'N104': party.get({ 'BOTSID': 'party', 'internalID': None }) }) pou.put({ 'BOTSID': 'N1', 'N102': party.get({ 'BOTSID': 'party', 'name1': None }) }) pou.put({'BOTSID': 'N1'}, { 'BOTSID': 'N2', 'N201': party.get({ 'BOTSID': 'party', 'name2': None }) }) pou.put({'BOTSID': 'N1'}, { 'BOTSID': 'N3', 'N301': party.get({ 'BOTSID': 'party', 'address1': None }) }) pou.put({'BOTSID': 'N1'}, { 'BOTSID': 'N3', 'N302': party.get({ 'BOTSID': 'party', 'address2': None }) }) pou.put({'BOTSID': 'N1'}, { 'BOTSID': 'N4', 'N401': party.get({ 'BOTSID': 'party', 'city': None }) }) pou.put({'BOTSID': 'N1'}, { 'BOTSID': 'N4', 'N402': party.get({ 'BOTSID': 'party', 'state': None }) }) pou.put({'BOTSID': 'N1'}, { 'BOTSID': 'N4', 'N403': party.get({ 'BOTSID': 'party', 'pcode': None }) }) pou.put({'BOTSID': 'N1'}, { 'BOTSID': 'N4', 'N404': party.get({ 'BOTSID': 'party', 'country': None }) }) #******************************************************************************************** #order level********************************************************************************* for order in inn.getloop({'BOTSID': 'message'}, {'BOTSID': 'orders'}, {'BOTSID': 'order'}): ordernode = out.putloop({'BOTSID': 'ST'}, { 'BOTSID': 'HL', 'HL01': hlcounter, 'HL02': currentshipment, 'HL03': 'O' }) currentorder = hlcounter hlcounter += 1 ordernode.put( {'BOTSID': 'HL'}, { 'BOTSID': 'PRF', 'PRF01': order.get({ 'BOTSID': 'order', 'ordernumber': None }) }) ordernode.put({'BOTSID': 'HL'}, { 'BOTSID': 'PRF', 'PRF04': transform.datemask( order.get({ 'BOTSID': 'order', 'orderdtm': None }), 'CCYY-MM-DD HH:mm', 'CCYYMMDD') }) #************************************************************************************************ #pack/sscc level********************************************************************************* #in xml; inhouse file sscc number is included in each line. #so first: get a list of all sscc's for this order list_of_sscc = [ orderline.get({ 'BOTSID': 'line', 'sscc': None }) for orderline in order.getloop( {'BOTSID': 'order'}, {'BOTSID': 'lines'}, {'BOTSID': 'line'}) ] #list_of_sscc has double sscc's, so remove doubles list_of_sscc = set(list_of_sscc) if None in list_of_sscc: raise Exception( 'found lines in ASN without SSCC. SSCC is really needed for this customer.' ) #now write sscc/pack level for each sscc for sscc in list_of_sscc: ssccnode = out.putloop({'BOTSID': 'ST'}, { 'BOTSID': 'HL', 'HL01': hlcounter, 'HL02': currentorder, 'HL03': 'P' }) currentsscc = hlcounter hlcounter += 1 ssccnode.put({'BOTSID': 'HL'}, { 'BOTSID': 'MAN', 'MAN01': 'GM', 'MAN02': '00' + sscc }) #*************************************************************************************************** #line/article level********************************************************************************* #loop over all lines that have this sscc for lin in order.getloop({'BOTSID': 'order'}, {'BOTSID': 'lines'}, { 'BOTSID': 'line', 'sscc': sscc }): itemnode = out.putloop({'BOTSID': 'ST'}, { 'BOTSID': 'HL', 'HL01': hlcounter, 'HL02': currentsscc, 'HL03': 'I' }) hlcounter += 1 itemnode.put( {'BOTSID': 'HL'}, { 'BOTSID': 'LIN', 'LIN01': lin.get({ 'BOTSID': 'line', 'linenum': None }) }) itemnode.put({'BOTSID': 'HL'}, { 'BOTSID': 'LIN', 'LIN02': 'UP', 'LIN03': lin.get({ 'BOTSID': 'line', 'gtin': None }) }) itemnode.put( {'BOTSID': 'HL'}, { 'BOTSID': 'LIN', 'LIN04': 'VN', 'LIN05': lin.get({ 'BOTSID': 'line', 'suart': None }) }) itemnode.put( {'BOTSID': 'HL'}, { 'BOTSID': 'LIN', 'LIN06': 'BP', 'LIN07': lin.get({ 'BOTSID': 'line', 'byart': None }) }) itemnode.put( {'BOTSID': 'HL'}, { 'BOTSID': 'SN1', 'SN103': 'EA', 'SN102': lin.get({ 'BOTSID': 'line', 'delqua': None }) }) itemnode.put( {'BOTSID': 'HL'}, { 'BOTSID': 'SN1', 'SN106': 'EA', 'SN105': lin.get({ 'BOTSID': 'line', 'ordqua': None }) }) itemnode.put({'BOTSID': 'HL'}, { 'BOTSID': 'PID', 'PID01': 'F', 'PID02': '08', 'PID05': lin.get({ 'BOTSID': 'line', 'desc': None }) }) out.put({'BOTSID': 'ST'}, { 'BOTSID': 'CTT', 'CTT01': out.getcountoccurrences({'BOTSID': 'ST'}, {'BOTSID': 'HL'}, {'BOTSID': 'LIN'}) }) #bots counts line items out.put({'BOTSID': 'ST'}, { 'BOTSID': 'SE', 'SE01': out.getcount() + 1, 'SE02': out.ta_info['reference'].zfill(4) }) #SE01: bots counts the segments produced in the X12 message.
def main(inn, out): out.put({'BOTSID': 'Header', 'SenderId': inn.ta_info['frompartner']}) out.put({'BOTSID': 'Header', 'ReceiverId': inn.ta_info['topartner']}) out.put({'BOTSID': 'Header', 'OrderType': inn.get({'BOTSID': 'ST'}, {'BOTSID': 'BEG', 'BEG02': None})}) doc_num = inn.get({'BOTSID': 'ST'}, {'BOTSID': 'BEG', 'BEG03': None}) inn.ta_info['botskey'] = out.ta_info['botskey'] = doc_num out.put({'BOTSID': 'Header', 'OrderNumber': doc_num}) order_date = inn.get({'BOTSID': 'ST'}, {'BOTSID': 'BEG', 'BEG05.02': None}) + \ inn.get({'BOTSID': 'ST'}, {'BOTSID': 'BEG', 'BEG05.01': None}) out.put({'BOTSID': 'Header', 'OrderDate': transform.datemask( order_date, 'YYYYMMDD', 'YYYY-MM-DD')}) out.put({'BOTSID': 'Header', 'RequisitionNumber': inn.get({'BOTSID': 'ST'}, {'BOTSID': 'BEG', 'BEG06': None})}) out.put({'BOTSID': 'Header', 'BatchNumber': transform.datemask( order_date, 'CCYYMMDD', 'MMDDYY') + inn.ta_info['bots_accessenvelope'].children[0].get( {'BOTSID': 'ISA', 'ISA10': None}) }) ship_date_begin = inn.get({'BOTSID': 'ST'}, {'BOTSID': 'DTM', 'DTM01': '010', 'DTM02': None}) ship_date_begin_ce = inn.get({'BOTSID': 'ST'}, {'BOTSID': 'DTM', 'DTM01': '010', 'DTM05': None}) if ship_date_begin and ship_date_begin_ce: out.put({'BOTSID': 'Header', 'RequestedShipEarliest': transform.datemask( ship_date_begin_ce + ship_date_begin, 'YYYYMMDD', 'YYYY-MM-DD') }) ship_date_end = inn.get({'BOTSID': 'ST'}, {'BOTSID': 'DTM', 'DTM01': '084', 'DTM02': None}) ship_date_end_ce = inn.get({'BOTSID': 'ST'}, {'BOTSID': 'DTM', 'DTM01': '084', 'DTM05': None}) if ship_date_end and ship_date_end_ce: out.put({'BOTSID': 'Header', 'RequestedShipLatest': transform.datemask( ship_date_end_ce + ship_date_end, 'YYYYMMDD', 'YYYY-MM-DD') }) for n1 in inn.getloop({'BOTSID': 'ST'}, {'BOTSID': 'N1'}): address = out.putloop({'BOTSID': 'Header'}, {'BOTSID': 'Address'}) address.put({'BOTSID': 'Address', 'AddressType': n1.get({'BOTSID': 'N1', 'N101': None})}) address.put({'BOTSID': 'Address', 'Name': n1.get({'BOTSID': 'N1', 'N102': None})}) address.put({'BOTSID': 'Address', 'CodeQualifier': n1.get({'BOTSID': 'N1', 'N103': None})}) address.put({'BOTSID': 'Address', 'Code': n1.get({'BOTSID': 'N1', 'N104': None})}) address.put({'BOTSID': 'Address', 'DivisionName': n1.get({'BOTSID': 'N1'}, {'BOTSID': 'N2', 'N201': None})}) address.put({'BOTSID': 'Address', 'AddressLine1': n1.get({'BOTSID': 'N1'}, {'BOTSID': 'N3', 'N301': None})}) address.put({'BOTSID': 'Address', 'AddressLine2': n1.get({'BOTSID': 'N1'}, {'BOTSID': 'N3', 'N302': None})}) address.put({'BOTSID': 'Address', 'City': n1.get({'BOTSID': 'N1'}, {'BOTSID': 'N4', 'N401': None})}) address.put({'BOTSID': 'Address', 'StateCode': n1.get({'BOTSID': 'N1'}, {'BOTSID': 'N4', 'N402': None})}) address.put({'BOTSID': 'Address', 'PostalCode': n1.get({'BOTSID': 'N1'}, {'BOTSID': 'N4', 'N403': None})}) address.put({'BOTSID': 'Address', 'ContactName': n1.get({'BOTSID': 'N1'}, {'BOTSID': 'PER', 'PER02': None})}) address.put({'BOTSID': 'Address', 'ContactEmail': n1.get({'BOTSID': 'N1'}, {'BOTSID': 'PER', 'PER08': None})}) address.put({'BOTSID': 'Address', 'ContactPhone': n1.get({'BOTSID': 'N1'}, {'BOTSID': 'PER', 'PER04': None})}) address.put({'BOTSID': 'Address', 'ContactFax': n1.get({'BOTSID': 'N1'}, {'BOTSID': 'PER', 'PER06': None})}) for po1 in inn.getloop({'BOTSID': 'ST'}, {'BOTSID': 'PO1'}): line = out.putloop({'BOTSID': 'Header'}, {'BOTSID': 'LineItem'}) line.put({'BOTSID': 'LineItem', 'LineNumber': po1.get({'BOTSID': 'PO1', 'PO101': None})}) line.put({'BOTSID': 'LineItem', 'QuantityOrdered': po1.get({'BOTSID': 'PO1', 'PO102': None})}) line.put({'BOTSID': 'LineItem', 'QuantityUOM': po1.get({'BOTSID': 'PO1', 'PO103': None})}) line.put({'BOTSID': 'LineItem', 'UnitPrice': po1.get({'BOTSID': 'PO1', 'PO104': None})}) line.put({'BOTSID': 'LineItem', 'UnitPriceCode': po1.get({'BOTSID': 'PO1', 'PO105': None})}) line.put({'BOTSID': 'LineItem', 'ISBN': po1.get({'BOTSID': 'PO1', 'PO107': None}).split('-')[0]}) line.put({'BOTSID': 'LineItem', 'StudentEdition': po1.get({'BOTSID': 'PO1', 'PO109': None})}) line.put({'BOTSID': 'LineItem', 'StudentEditionCost': po1.get( {'BOTSID': 'PO1', 'PO111': None})}) line.put({'BOTSID': 'LineItem', 'SchoolDistrictOwes': po1.get( {'BOTSID': 'PO1', 'PO113': None})})