-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxmlize.py
71 lines (61 loc) · 3.68 KB
/
xmlize.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import argparse
import xml.etree.ElementTree as ET
def get_edi_documents():
return {
"ANSI X12 (North American Standard)": {
"204": "Motor Carrier Load Tender - A transportation order for shipping goods",
"810": "Invoice - Used for sending billing information",
"820": "Payment Order/Remittance Advice - Communicates payment details from buyer to seller",
"834": "Benefit Enrollment and Maintenance - For exchanging enrollment information in health insurance plans",
"837": "Healthcare Claim - Used for submitting healthcare claims electronically",
"846": "Inventory Inquiry/Advice - Provides details about stock availability",
"850": "Purchase Order (PO) - Used to request products or services",
"855": "Purchase Order Acknowledgment - Confirms receipt and acceptance of a purchase order",
"856": "Advance Shipping Notice (ASN) - Provides shipment details to the recipient before delivery",
"867": "Product Transfer and Resale Report - Tracks resales of products through distribution channels",
"997": "Functional Acknowledgment - Confirms receipt of an EDI transaction",
},
"EDIFACT (International Standard)": {
"DESADV": "Dispatch Advice - Provides shipment details (like ASN in X12)",
"IFCSUM": "International Forwarding and Consolidation Summary - Used in logistics for shipment consolidation",
"INVOIC": "Invoice - Used for billing and invoicing globally",
"ORDERS": "Purchase Order - Used to order goods or services internationally",
"ORDRSP": "Order Response - Communicates acceptance or rejection of a purchase order",
"PAYMUL": "Multiple Payment Order - Handles multiple payments in financial transactions",
"PRICAT": "Price/Sales Catalog - Contains pricing and product information",
"RECADV": "Receiving Advice - Notifies the sender of the goods that they were received",
},
}
def generate_xml(edi_documents):
root = ET.Element("EDI_Documents")
for standard, documents in edi_documents.items():
standard_element = ET.SubElement(root, "Standard", name=standard)
for code, description in documents.items():
document_element = ET.SubElement(standard_element, "Document", code=code)
document_element.text = description
return ET.tostring(root, encoding="unicode")
def list_edi_documents(filter_standard=None):
edi_documents = get_edi_documents()
if filter_standard and filter_standard in edi_documents:
edi_documents = {filter_standard: edi_documents[filter_standard]}
xml_output = generate_xml(edi_documents)
print(xml_output)
def search_edi_code(code):
edi_documents = get_edi_documents()
for standard, documents in edi_documents.items():
if code in documents:
root = ET.Element("Search_Result")
document_element = ET.SubElement(root, "Document", code=code, standard=standard)
document_element.text = documents[code]
print(ET.tostring(root, encoding="unicode"))
return
print(f"<Error>EDI code {code} not found.</Error>")
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="List and search EDI documents in XML format.")
parser.add_argument("--standard", type=str, help="Filter by EDI standard (e.g., 'ANSI X12 (North American Standard)')")
parser.add_argument("--search", type=str, help="Search for a specific EDI code (e.g., '850')")
args = parser.parse_args()
if args.search:
search_edi_code(args.search)
else:
list_edi_documents(args.standard)