Jelajahi Sumber

Erster Entwurf Volkswagen

gc-server3 3 bulan lalu
induk
melakukan
ca502816b0
1 mengubah file dengan 57 tambahan dan 0 penghapusan
  1. 57 0
      gchr/gchr_export.py

+ 57 - 0
gchr/gchr_export.py

@@ -94,17 +94,74 @@ def export_skr51_header(export_cfg: GchrExportConfig) -> dict[str, str]:
     }
 
 
+def export_volkswagen_xml(export_cfg: GchrExportConfig):
+    header = {
+        "PartnerKey": {
+            "Country": "DEU",
+            "Brand": "V",
+            "PartnerNumber": "21996",
+        },
+        "IsCumulative": "true",
+        "AccountingDate": {
+            "AccountingMonth": "09",
+            "AccountingYear": "2024",
+        },
+        "Currency": "EUR",
+        "Level": "1",
+    }
+    record_elements = {"ProfitCenter": "00", "AccountKey": "010600002700000007000", "AccountValue": "+11.00"}
+
+    ET.register_namespace("tns", "http://xmldefs.volkswagenag.com/Retail/AccountBalanceDTS/V1")
+    root = ET.Element("tns:ShowAccountBalance")
+    root = dict_to_xml(root, header)
+
+    record_list = ET.SubElement(root, "Accounts")
+    for row in export_cfg.bookkeep_records:
+        record = ET.SubElement(record_list, "Account")
+        for e, v in record_elements.items():
+            child = ET.SubElement(record, e)
+            field = row.get(e, v)
+            if str(field) == "nan":
+                field = "0"
+            elif type(field) is float:
+                field = "{:.2f}".format(field * -1)
+            child.text = str(field)
+
+    with open(export_cfg.export_file, "w", encoding="latin-1") as fwh:
+        fwh.write(
+            minidom.parseString(ET.tostring(root, encoding="ISO-8859-1")).toprettyxml(indent="  ", encoding="latin-1")
+        )
+
+
 GchrExportFn = Callable[[GchrExportConfig], None]
 
 
 EXPORT_FN: dict[GchrExportFormat, GchrExportFn] = {
     GchrExportFormat.SKR51: export_skr51_xml,
+    GchrExportFormat.Volkswagen: export_volkswagen_xml,
 }
 
 
 def export_dummy(export_cfg: GchrExportConfig) -> None:
+    print("DUMMY")
+    print(export_cfg.main_site)
     pass
 
 
 def get_export_fn(export_format: GchrExportFormat) -> GchrExportFn:
     return EXPORT_FN.get(export_format, export_dummy)
+
+
+def dict_to_xml(root: ET.Element, subtree: dict):
+    # if isinstance(subtree, list):
+    #     for item in subtree:
+    #         dict_to_xml(root, item)
+    #     return root
+
+    for key, value in subtree.items():
+        e = ET.SubElement(root, key)
+        if isinstance(value, dict):
+            dict_to_xml(e, value)
+        else:
+            e.text = str(value)
+    return root