Procházet zdrojové kódy

Black Formatter GCHR

gc-server3 před 3 měsíci
rodič
revize
9389ae9be7

binární
gcstruct/dist/gchr2_Oktober.exe → gcstruct/dist/gchr2_10.exe


+ 12 - 8
gcstruct/gchr.py

@@ -1,13 +1,13 @@
-import pandas as pd
-import numpy as np
-import xml.etree.ElementTree as ET
 import csv
-from xml.dom import minidom
-from datetime import datetime
 import logging
-from pathlib import Path
 import os
+import xml.etree.ElementTree as ET
+from datetime import datetime
+from pathlib import Path
+from xml.dom import minidom
 
+import numpy as np
+import pandas as pd
 
 ACCOUNT_INFO = [
     "Account",
@@ -48,7 +48,7 @@ class GCHR:
 
         self.account_translation = f"{self.base_dir}/data/Kontenrahmen_uebersetzt.csv"
         self.account_bookings = list(Path(self.base_dir).joinpath("data").glob("GuV_Bilanz_Salden*.csv"))
-        self.first_month_of_financial_year = "01"
+        self.first_month_of_financial_year = "10"
 
         pd.set_option("display.max_rows", 500)
         pd.set_option("display.float_format", lambda x: "%.2f" % x)
@@ -267,7 +267,10 @@ class GCHR:
         return df_translate
 
     def special_translation(self, df: pd.DataFrame):
+        df["Konto_Nr_Händler"] = df["Konto_Nr_Händler"].str.upper()
+        df["Konto_Nr_SKR51"] = df["Konto_Nr_SKR51"].str.upper()
         df = self.extract_acct_info(df)
+        df["Konto_Nr"] = df["Konto_Nr"].str.upper()
         logging.info(df.shape)
         logging.info(df.columns)
         logging.info(df.head())
@@ -544,7 +547,8 @@ def gchr_local():
 
 def gchr_export(base_dir):
     gchr = GCHR(base_dir)
-    gchr.export_all_periods(overwrite=True, today="2022-08-01")
+    # gchr.export_all_periods(overwrite=True, today="2022-08-01")
+    gchr.export_all_periods()
 
 
 if __name__ == "__main__":

+ 1 - 1
gcstruct/gchr2.py

@@ -1,6 +1,6 @@
-import gchr
 import os
 
+import gchr
 
 if __name__ == "__main__":
     gchr.gchr_export(os.getcwd())

+ 33 - 18
gcstruct/gchr_error.py

@@ -1,29 +1,44 @@
 import pandas as pd
 
-base_dir = '/home/robert/projekte/python/gcstruct/Siebrecht/'
+base_dir = "/home/robert/projekte/python/gcstruct/Siebrecht/"
 
 
 def read_csv():
-    header = ['Kontonummer', 'Wert', 'Fehler', 'Beschreibung']
-    df_log = pd.read_csv(base_dir + 'Siebrecht_12_2021.txt', decimal=',', sep='\t', encoding='latin-1',
-                         converters={0: str, 1: str, 2: str, 3: str}, header=None, names=header)  # , skiprows=3)
-    df_log['Marke_HBV'] = df_log['Kontonummer'].str.slice(4, 8)
-    df_log['Site'] = df_log['Kontonummer'].str.slice(8, 10)
-    df_log['Account'] = df_log['Kontonummer'].str.slice(0, 4)
-    df_log['Origin'] = df_log['Kontonummer'].str.slice(10, 12)
-    df_log['SalesChannel'] = df_log['Kontonummer'].str.slice(12, 14)
-    df_log['CostCarrier'] = df_log['Kontonummer'].str.slice(14, 16)
+    header = ["Kontonummer", "Wert", "Fehler", "Beschreibung"]
+    df_log = pd.read_csv(
+        base_dir + "Siebrecht_12_2021.txt",
+        decimal=",",
+        sep="\t",
+        encoding="latin-1",
+        converters={0: str, 1: str, 2: str, 3: str},
+        header=None,
+        names=header,
+    )  # , skiprows=3)
+    df_log["Marke_HBV"] = df_log["Kontonummer"].str.slice(4, 8)
+    df_log["Site"] = df_log["Kontonummer"].str.slice(8, 10)
+    df_log["Account"] = df_log["Kontonummer"].str.slice(0, 4)
+    df_log["Origin"] = df_log["Kontonummer"].str.slice(10, 12)
+    df_log["SalesChannel"] = df_log["Kontonummer"].str.slice(12, 14)
+    df_log["CostCarrier"] = df_log["Kontonummer"].str.slice(14, 16)
     # df_log['CumulatedYear'] = df_log['Wert'].str.replace(r'\.', '', regex=True)
 
-    df_export = pd.read_csv(base_dir + 'export_2021-12.csv', sep=';', encoding='latin-1',
-                            converters={i: str for i in range(0, 200)})
-    df = df_export.merge(df_log, how='left', on=['Marke_HBV', 'Site', 'Account', 'Origin', 'SalesChannel', 'CostCarrier'])
-    df.to_csv(base_dir + 'export_error_2021-12.csv', decimal=',', sep=';', encoding='latin-1', index=False)
+    df_export = pd.read_csv(
+        base_dir + "export_2021-12.csv", sep=";", encoding="latin-1", converters={i: str for i in range(0, 200)}
+    )
+    df = df_export.merge(
+        df_log, how="left", on=["Marke_HBV", "Site", "Account", "Origin", "SalesChannel", "CostCarrier"]
+    )
+    df.to_csv(base_dir + "export_error_2021-12.csv", decimal=",", sep=";", encoding="latin-1", index=False)
 
-    df_bookings = pd.read_csv(base_dir + 'GuV_Bilanz_Salden_Debug.csv', decimal=',', sep=';',
-                              encoding='latin-1', converters={0: str, 1: str, 6: str, 7: str})
-    df = df.merge(df_bookings, how='inner', on=[])
+    df_bookings = pd.read_csv(
+        base_dir + "GuV_Bilanz_Salden_Debug.csv",
+        decimal=",",
+        sep=";",
+        encoding="latin-1",
+        converters={0: str, 1: str, 6: str, 7: str},
+    )
+    df = df.merge(df_bookings, how="inner", on=[])
 
 
-if __name__ == '__main__':
+if __name__ == "__main__":
     read_csv()

+ 2 - 1
gcstruct/gcstruct_profiler.py

@@ -1,6 +1,7 @@
-from gcstruct import gcstruct_uebersetzung
 import cProfile
 
+from gcstruct import gcstruct_uebersetzung
+
 
 def gcstruct_profiler():
     gcstruct_uebersetzung("C:\\GlobalCube\\Tasks\\scripts")

+ 11 - 2
gcstruct/gcstruct_uebersetzung.py

@@ -5,7 +5,7 @@ sys.path.insert(0, "C:\\Projekte\\Python\\gcstruct")
 from gcstruct import GCStruct  # noqa:E402
 
 
-def gcstruct_uebersetzung(base_dir=None):
+def get_base_and_import_dir(base_dir):
     if base_dir is None:
         base_dir = Path(".").absolute()
     else:
@@ -23,9 +23,18 @@ def gcstruct_uebersetzung(base_dir=None):
         if not base_dir.exists():
             base_dir = Path("//media/fileserver1/verwaltung/Kunden/Luchtenberg/1 Umstellung SKR51/")
         import_dir = base_dir
+    return base_dir, import_dir
+
+
+def gcstruct_uebersetzung(base_dir=None):
+    base_dir, import_dir = get_base_and_import_dir(base_dir)
 
     struct = GCStruct(str(base_dir.joinpath("GCStruct_Aufbereitung")))
-    struct.skr51_translate(import_dir.glob("Kontenrahmen_kombiniert*.csv"))
+    input_files = [f for f in import_dir.glob("Kontenrahmen_kombiniert*.csv")]
+    print("Quelldateien:")
+    for file in input_files:
+        print("* " + file.name)
+    struct.skr51_translate(input_files)
     print("Kontenrahmen_uebersetzt.csv erstellt.")
     # copyfile('c:/Projekte/Python/Gcstruct/Kontenrahmen_kombiniert.csv', base_dir + 'GCStruct_Modell/Export/Kontenrahmen_kombiniert.csv')
 

+ 78 - 56
gcstruct/skr51.py

@@ -1,23 +1,27 @@
-import pandas as pd
+from itertools import product
+
 # import numpy as np
 from pathlib import Path
-from itertools import product
+
+import pandas as pd
 
 
-class skr51_validation():
-    current_dir = Path('/home/robert/projekte/python/gcstruct/SKR51')
+class skr51_validation:
+    current_dir = Path("/home/robert/projekte/python/gcstruct/SKR51")
 
     def __init__(self):
-        filter_csv = pd.read_csv(self.current_dir.joinpath('SKR51_Kostenrechnungsmerkmale.csv'),
-                                 sep=';', quotechar='"')  # , encoding='latin-1')
-        filter_csv['Filter'] = filter_csv['Filter'].apply(self.create_list)
-        self.filter = filter_csv.set_index('Block').to_dict(orient='dict')['Filter']
+        filter_csv = pd.read_csv(
+            self.current_dir.joinpath("SKR51_Kostenrechnungsmerkmale.csv"), sep=";", quotechar='"'
+        )  # , encoding='latin-1')
+        filter_csv["Filter"] = filter_csv["Filter"].apply(self.create_list)
+        self.filter = filter_csv.set_index("Block").to_dict(orient="dict")["Filter"]
         # print(self.filter)
 
-        explode_cols = ['Kostenstelle', 'Absatzkanal', 'Kostenträger']
-        matrix_csv = pd.read_csv(self.current_dir.joinpath('Plausibilitaetsmatrix.csv'), sep=';',
-                                 converters={i: str for i in range(0, 200)})   # , encoding='latin-1'  .set_index('Konto_Nr')
-        matrix_csv['valid'] = True
+        explode_cols = ["Kostenstelle", "Absatzkanal", "Kostenträger"]
+        matrix_csv = pd.read_csv(
+            self.current_dir.joinpath("Plausibilitaetsmatrix.csv"), sep=";", converters={i: str for i in range(0, 200)}
+        )  # , encoding='latin-1'  .set_index('Konto_Nr')
+        matrix_csv["valid"] = True
         for col in explode_cols:
             matrix_csv[col] = matrix_csv[col].apply(self.create_list)
         self.matrix = matrix_csv
@@ -25,77 +29,95 @@ class skr51_validation():
         # print(self.matrix[self.matrix['Konto_Nr'] == '3300'])
 
     def create_list(self, whitelist):
-        if whitelist == '':
+        if whitelist == "":
             # return [str(i).zfill(2) for i in range(0, 100)]
-            return ['00']
+            return ["00"]
 
         result = []
-        for x in whitelist.split(','):
-            if '-' in x:
-                start, end = map(int, x.split('-'))
+        for x in whitelist.split(","):
+            if "-" in x:
+                start, end = map(int, x.split("-"))
                 result += [str(i).zfill(2) for i in range(start, end + 1)]
             else:
                 result.append(x)
         return result
 
     def check_bookings(self, bookings_file):
-        export_csv = pd.read_csv(self.current_dir.joinpath(bookings_file), sep=';', decimal=',',
-                                 converters={i: str for i in range(0, 200)}, encoding='latin-1')
-        export_csv = export_csv.merge(self.matrix[['Konto_Nr', 'valid']], how='left', on='Konto_Nr', suffixes=(None, '_matrix'))
-        export_csv['Konto_Nr_valid'] = export_csv['valid'] == True
-        temp = export_csv['Konto_Nr_Händler']
-        export_csv.drop(['Konto_Nr_Händler'], axis=1, inplace=True)
-        export_csv.insert(0, 'Konto_Nr_Händler', temp)
-
-        for col in ['Marke', 'Standort']:
-            export_csv[col + '_valid'] = export_csv[col].isin(self.filter[col])
-            export_csv['valid'] = export_csv['valid'] & export_csv[col + '_valid']
-
-        for col in ['Kostenstelle', 'Absatzkanal', 'Kostenträger']:
-            export_csv = export_csv.merge(self.matrix[['Konto_Nr', col, 'valid']].explode(col),
-                                          how='left', on=['Konto_Nr', col], suffixes=(None, '_' + col))
-            export_csv[col + '_valid'] = export_csv[col].isin(self.filter[col]) & export_csv['valid_' + col] == True
-            export_csv.drop(['valid_' + col], axis=1, inplace=True)
-            export_csv['valid'] = export_csv['valid'] & export_csv[col + '_valid']
+        export_csv = pd.read_csv(
+            self.current_dir.joinpath(bookings_file),
+            sep=";",
+            decimal=",",
+            converters={i: str for i in range(0, 200)},
+            encoding="latin-1",
+        )
+        export_csv = export_csv.merge(
+            self.matrix[["Konto_Nr", "valid"]], how="left", on="Konto_Nr", suffixes=(None, "_matrix")
+        )
+        export_csv["Konto_Nr_valid"] = export_csv["valid"] == True
+        temp = export_csv["Konto_Nr_Händler"]
+        export_csv.drop(["Konto_Nr_Händler"], axis=1, inplace=True)
+        export_csv.insert(0, "Konto_Nr_Händler", temp)
+
+        for col in ["Marke", "Standort"]:
+            export_csv[col + "_valid"] = export_csv[col].isin(self.filter[col])
+            export_csv["valid"] = export_csv["valid"] & export_csv[col + "_valid"]
+
+        for col in ["Kostenstelle", "Absatzkanal", "Kostenträger"]:
+            export_csv = export_csv.merge(
+                self.matrix[["Konto_Nr", col, "valid"]].explode(col),
+                how="left",
+                on=["Konto_Nr", col],
+                suffixes=(None, "_" + col),
+            )
+            export_csv[col + "_valid"] = export_csv[col].isin(self.filter[col]) & export_csv["valid_" + col] == True
+            export_csv.drop(["valid_" + col], axis=1, inplace=True)
+            export_csv["valid"] = export_csv["valid"] & export_csv[col + "_valid"]
         return export_csv
 
     def maximum_accounts(self):
-        accounts = self.matrix.to_dict(orient='records')
-        header = ['Account', 'Make', 'Site', 'Origin', 'SalesChannel', 'CostCarrier', 'CostAccountingString',
-                  'Decimals', 'OpeningBalance', 'Period01', 'CumulatedYear', 'Marke_HBV']
-        with open(self.current_dir.joinpath('maximum.csv'), 'w', encoding='latin-1') as fwh:
-            fwh.write(';'.join(header) + '\n')
+        accounts = self.matrix.to_dict(orient="records")
+        header = [
+            "Account",
+            "Make",
+            "Site",
+            "Origin",
+            "SalesChannel",
+            "CostCarrier",
+            "CostAccountingString",
+            "Decimals",
+            "OpeningBalance",
+            "Period01",
+            "CumulatedYear",
+            "Marke_HBV",
+        ]
+        with open(self.current_dir.joinpath("maximum.csv"), "w", encoding="latin-1") as fwh:
+            fwh.write(";".join(header) + "\n")
 
             for a in accounts:
-                for entry in product(a['Kostenstelle'], a['Absatzkanal'], a['Kostenträger']):
-                    row = [a['Konto_Nr'], '01', '01', *entry, '0101' + ''.join(entry), '2', '0', '100', '100', '0000']
-                    fwh.write(';'.join(row) + '\n')
+                for entry in product(a["Kostenstelle"], a["Absatzkanal"], a["Kostenträger"]):
+                    row = [a["Konto_Nr"], "01", "01", *entry, "0101" + "".join(entry), "2", "0", "100", "100", "0000"]
+                    fwh.write(";".join(row) + "\n")
         return None
 
     @staticmethod
     def format_konto(k):
         return "{0}-{1}-{2}-{3}-{4}-{5}".format(
-            k['Kontonummer'],
-            k['Marke'],
-            k['Standort'],
-            k['Kostenstelle'],
-            k['Absatzkanal'],
-            k['Kostentraeger']
+            k["Kontonummer"], k["Marke"], k["Standort"], k["Kostenstelle"], k["Absatzkanal"], k["Kostentraeger"]
         )
 
     @staticmethod
     def format_konto_neu(k):
         return "{0}-{1}-{2}-{3}-{4}-{5}".format(
-            k['Kontonummer_neu'],
-            k['Marke_neu'],
-            k['Standort_neu'],
-            k['Kostenstelle_neu'],
-            k['Absatzkanal_neu'],
-            k['Kostentraeger_neu']
+            k["Kontonummer_neu"],
+            k["Marke_neu"],
+            k["Standort_neu"],
+            k["Kostenstelle_neu"],
+            k["Absatzkanal_neu"],
+            k["Kostentraeger_neu"],
         )
 
 
-if __name__ == '__main__':
+if __name__ == "__main__":
     skr = skr51_validation()
     skr.maximum_accounts()
 

+ 5 - 5
gcstruct/skr51_default.py

@@ -1,12 +1,12 @@
-topics1 = ['MAR', 'STA']
-topics2 = ['KST', 'ABS', 'KTR']
+topics1 = ["MAR", "STA"]
+topics2 = ["KST", "ABS", "KTR"]
 
 accounts = []
 
 for t in topics1:
-    accounts += [t + '_' + str(i).zfill(2) + ';n.v.\n' for i in range(10)]
+    accounts += [t + "_" + str(i).zfill(2) + ";n.v.\n" for i in range(10)]
 for t in topics2:
-    accounts += [t + '_' + str(i).zfill(2) + ';n.v.\n' for i in range(100)]
+    accounts += [t + "_" + str(i).zfill(2) + ";n.v.\n" for i in range(100)]
 
-with open('Kontenrahmen_Merkmale.csv', 'w') as f:
+with open("Kontenrahmen_Merkmale.csv", "w") as f:
     f.writelines(accounts)