Ver Fonte

Exportformat Honda und Volkswagen

gc-server3 há 2 meses atrás
pai
commit
d5f1b6b1d3
6 ficheiros alterados com 53 adições e 64 exclusões
  1. BIN
      GCHR.ico
  2. BIN
      dist/gchr2.exe
  3. 45 59
      gchr/export_format/honda.py
  4. 5 4
      gchr/export_format/volkswagen.py
  5. 2 1
      gchr2.bat
  6. 1 0
      gchr2.spec

BIN
GCHR.ico


BIN
dist/gchr2.exe


+ 45 - 59
gchr/export_format/honda.py

@@ -1,14 +1,16 @@
 import csv
-import xml.etree.ElementTree as ET
 from datetime import datetime
 from pathlib import Path
-from xml.dom import minidom
 
 from gchr.gchr_model import GchrExportConfig
 
-MODEL_CODE = {
-    "01": "0600",
-    "02": "0603",
+MAKE_CODE = {
+    "08": "04",
+}
+
+SITE_CODE = {
+    "07": "01",
+    "04": "02",
 }
 
 
@@ -17,77 +19,61 @@ def export_honda_csv(export_cfg: GchrExportConfig):
     fiscal_year = export_cfg.current_year
     ts = datetime.now().strftime("%m%d%Y;%H%M%S")
     header = "\n".join(
-        f"{dealer_number};Dealernumber",
-        ";Honda Germany",
-        f"{export_cfg.current_year};Evaluation;{export_cfg.current_month}"
-        f"{fiscal_year};Fiscal-Year;{export_cfg.first_month}"
-        f";Timestamp;{ts}",
+        [
+            f"{dealer_number};Dealernumber",
+            ";Honda Germany",
+            f"{export_cfg.current_year};Evaluation;{export_cfg.current_month}",
+            f"{fiscal_year};Fiscal-Year;{export_cfg.first_month}",
+            f";Timestamp;{ts}",
+        ]
     )
 
+    base_dir = Path(export_cfg.export_file).parent.parent.parent
+
+    account_desc = f"{base_dir}\\data\\Kontenrahmen.csv"
+    if Path(account_desc).exists():
+        with open(account_desc, "r", encoding="latin-1") as frh:
+            csv_frh = csv.DictReader(frh, delimiter=";")
+            accounts = {row["Konto_Nr"]: row["Konto_Bezeichnung"] for row in csv_frh}
+
     records = []
-    for row in sorted(export_cfg.bookkeep_records, key=lambda x: x["Account"] + x["CostAccountingString"]):
-        val = "{0:.2f}".format(row["CumulatedYear"] * -1)
-        if val[0] != "-":
-            val = "+" + val
+    for row in sorted(export_cfg.bookkeep_records, key=lambda x: account_number(x)):
         records.append(
-            {
-                "tns:ProfitCenter": "00",
-                "tns:AccountKey": account_number(row),
-                "tns:AccountValue": val,
-            }
+            [
+                account_number(row),
+                accounts.get(row["Account"], ""),
+                "{0:.2f}".format(row["Period" + export_cfg.current_month]),
+                "{0:.2f}".format(row["CumulatedYear"]),
+            ]
         )
 
-    base_dir = Path(export_cfg.export_file).parent.parent.parent
     add_values = f"{base_dir}\\data\\Manuelle_Eingabe_{export_cfg.current_year}-{export_cfg.current_month}.csv"
     if Path(add_values).exists():
         with open(add_values, "r", encoding="latin-1") as frh:
             csv_frh = csv.DictReader(frh, delimiter=";")
             for row in csv_frh:
                 records.append(
-                    {
-                        "tns:ProfitCenter": "00",
-                        "tns:AccountKey": row["Kontonummer"][1:],
-                        "tns:AccountValue": "+{0:.2f}".format(float(row["Akt.Monat"].replace(",", "."))),
-                    }
+                    [
+                        row["Kontonummer"],
+                        "",
+                        "+{0:.2f}".format(float(row["Akt.Monat"].replace(",", "."))),
+                        "+{0:.2f}".format(float(row["Akt.Monat"].replace(",", "."))),
+                    ]
                 )
 
-    nsmap = {"xmlns:tns": "http://xmldefs.volkswagenag.com/Retail/AccountBalanceDTS/V1"}
-    root = ET.Element("tns:ShowAccountBalance", nsmap)
-    root = dict_to_xml(root, header)
-
-    record_list = ET.SubElement(root, "tns:Accounts")
-    for r in records:
-        dict_to_xml(ET.SubElement(record_list, "tns:Account"), r)
-
-    raw_xml = ET.tostring(root, encoding="latin-1")
-    with open(export_cfg.export_file, "w", encoding="latin-1") as fwh:
-        fwh.write(minidom.parseString(raw_xml).toprettyxml(indent="  "))
-
-
-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
+    with open(export_cfg.export_file[:-4] + "_Honda.csv", "w", encoding="latin-1") as fwh:
+        fwh.write(header + "\n")
+        for row in records:
+            fwh.write(";".join(row) + "\n")
 
 
 def account_number(row: dict[str, str]) -> str:
     res = {
-        "Brand": row["Make"],
-        "ModelCode": MODEL_CODE.get(row["Make"], "0000"),
-        "Account": row["Account"],
-        "CostCentre": row["Origin"],
-        "TradeChannel": row["SalesChannel"],
-        "CostUnit": row["CostCarrier"],
-        "Location": row["Site"],
-        "TaxCode": "000",
+        "Konto": row["Account"],
+        "Marke": MAKE_CODE.get(row["Make"], "00"),
+        "Betrieb": SITE_CODE.get(row["Site"], "00"),
+        "Kostenstelle": row["Origin"],
+        "Absatzkanal": row["SalesChannel"],
+        "Kostenträger": row["CostCarrier"],
     }
     return "".join(res.values())

+ 5 - 4
gchr/export_format/volkswagen.py

@@ -16,8 +16,8 @@ from gchr.gchr_model import GchrExportConfig
 # internal enum Hauptmarke { V, A, S, C, E, L };
 
 MODEL_CODE = {
-    "01": "0600",
-    "02": "0603",
+    "05": "0600",
+    "06": "0603",
 }
 
 
@@ -39,7 +39,8 @@ def export_volkswagen_xml(export_cfg: GchrExportConfig):
 
     records = []
     for row in sorted(export_cfg.bookkeep_records, key=lambda x: x["Account"] + x["CostAccountingString"]):
-        val = "{0:.2f}".format(row["CumulatedYear"] * -1)
+        factor = 1 if row["Kontoart"] == "1" else -1
+        val = "{0:.2f}".format(row["CumulatedYear"] * factor)
         if val[0] != "-":
             val = "+" + val
         records.append(
@@ -94,7 +95,7 @@ def dict_to_xml(root: ET.Element, subtree: dict):
 
 def account_number(row: dict[str, str]) -> str:
     res = {
-        "Brand": row["Make"],
+        "Brand": row["Make"],  # if row["Make"] in MODEL_CODE else "99",
         "ModelCode": MODEL_CODE.get(row["Make"], "0000"),
         "Account": row["Account"],
         "CostCentre": row["Origin"],

+ 2 - 1
gchr2.bat

@@ -1,4 +1,5 @@
 cd /d %~dp0
 call .venv\Scripts\activate.bat
-pyinstaller -F --path %~dp0 gchr2.py
+pyinstaller -F --path %~dp0 --icon GCHR.ico gchr2.py
+copy /Y %~dp0\dist\gchr2.exe P:\GCHR2
 pause

+ 1 - 0
gchr2.spec

@@ -35,4 +35,5 @@ exe = EXE(
     target_arch=None,
     codesign_identity=None,
     entitlements_file=None,
+    icon=['GCHR.ico'],
 )