Browse Source

.venv und black formatter 120 Zeichen

gc-server3 1 year ago
parent
commit
1dd6dc4f3b
8 changed files with 354 additions and 340 deletions
  1. 2 4
      .vscode/settings.json
  2. 274 189
      gcstruct/gchr.py
  3. 1 0
      gcstruct/gchr2.bat
  4. 37 33
      gcstruct/gchr2.spec
  5. 37 112
      gcstruct/gcstruct.py
  6. 1 0
      gcstruct/gcstruct_uebersetzung.bat
  7. 1 1
      gcstruct/gcstruct_uebersetzung.py
  8. 1 1
      tox.ini

+ 2 - 4
.vscode/settings.json

@@ -1,15 +1,13 @@
 {
     "[python]": {
         "editor.defaultFormatter": "ms-python.black-formatter",
-        "editor.formatOnSave": true
+        "editor.formatOnSave": true,
     },
     "python.pythonPath": "/usr/bin/python",
     "python.testing.pytestEnabled": false,
     "python.testing.nosetestsEnabled": false,
     "python.testing.unittestEnabled": true,
-    "python.linting.pylintEnabled": false,
-    "python.linting.flake8Enabled": true,
-    "python.linting.enabled": true,
+    "black-formatter.args": ["--line-length", "120"],
     "files.associations": {
         "*.mac": "vbs"
     },

+ 274 - 189
gcstruct/gchr.py

@@ -10,7 +10,15 @@ import os
 from enum import Enum, auto
 
 
-ACCOUNT_INFO = ['Account', 'Make', 'Site', 'Origin', 'SalesChannel', 'CostCarrier', 'CostAccountingString']
+ACCOUNT_INFO = [
+    "Account",
+    "Make",
+    "Site",
+    "Origin",
+    "SalesChannel",
+    "CostCarrier",
+    "CostAccountingString",
+]
 
 
 class GCHR:
@@ -18,11 +26,11 @@ class GCHR:
         self.base_dir = base_dir
 
         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.account_bookings = list(Path(self.base_dir).joinpath("data").glob("GuV_Bilanz_Salden*.csv"))
+        self.first_month_of_financial_year = "09"
 
-        pd.set_option('display.max_rows', 500)
-        pd.set_option('display.float_format', lambda x: '%.2f' % x)
+        pd.set_option("display.max_rows", 500)
+        pd.set_option("display.float_format", lambda x: "%.2f" % x)
 
     def set_bookkeep_period(self, year, month):
         self.current_year = year
@@ -31,10 +39,10 @@ class GCHR:
         prot_file = f"{self.export_info_dir}/protokoll_{period}.log"
         logging.basicConfig(
             filename=prot_file,
-            filemode='w',
-            encoding='utf-8',
+            filemode="w",
+            encoding="utf-8",
             level=logging.DEBUG,
-            force=True
+            force=True,
         )
         self.debug_file = f"{self.export_info_dir}/debug_{period}.csv"
         self.account_ignored = f"{self.export_info_dir}/ignoriert_{period}.csv"
@@ -46,74 +54,108 @@ class GCHR:
 
     def header(self, makes, sites):
         return {
-            'Country': 'DE',
-            'MainBmCode': sites[0]['Standort_HBV'],
-            'Month': self.current_month,
-            'Year': self.current_year,
-            'Currency': 'EUR',
-            'NumberOfMakes': len(makes),
-            'NumberOfSites': len(sites),
-            'ExtractionDate': datetime.now().strftime('%d.%m.%Y'),
-            'ExtractionTime': datetime.now().strftime('%H:%M:%S'),
-            'BeginFiscalYear': self.first_month_of_financial_year
+            "Country": "DE",
+            "MainBmCode": sites[0]["Standort_HBV"],
+            "Month": self.current_month,
+            "Year": self.current_year,
+            "Currency": "EUR",
+            "NumberOfMakes": len(makes),
+            "NumberOfSites": len(sites),
+            "ExtractionDate": datetime.now().strftime("%d.%m.%Y"),
+            "ExtractionTime": datetime.now().strftime("%H:%M:%S"),
+            "BeginFiscalYear": self.first_month_of_financial_year,
         }
 
     def bookkeep_filter(self):
         period = [self.current_year + str(i).zfill(2) for i in range(1, 13)]
-        if self.first_month_of_financial_year != '01':
+        if self.first_month_of_financial_year != "01":
             if self.first_month_of_financial_year > self.current_month:
                 period = [self.last_year + str(i).zfill(2) for i in range(1, 13)] + period
             else:
                 period = period + [self.next_year + str(i).zfill(2) for i in range(1, 13)]
             fm = int(self.first_month_of_financial_year)
-            period = period[fm - 1:fm + 12]
-        period = [self.current_year + '00'] + period
-        rename_to = ['OpeningBalance'] + ['Period' + str(i).zfill(2) for i in range(1, 13)]
+            period = period[fm - 1 : fm + 12]
+        period = [self.current_year + "00"] + period
+        rename_to = ["OpeningBalance"] + ["Period" + str(i).zfill(2) for i in range(1, 13)]
         return dict(zip(period, rename_to))
 
     def extract_acct_info(self, df: pd.DataFrame):
-        acct_info = ['Marke', 'Standort', 'Konto_Nr', 'Kostenstelle', 'Absatzkanal', 'Kostenträger']
-        df['Konto_Nr_SKR51'] = df.index
-        df[acct_info] = df['Konto_Nr_SKR51'].str.split('-', 6, expand=True)
+        acct_info = [
+            "Marke",
+            "Standort",
+            "Konto_Nr",
+            "Kostenstelle",
+            "Absatzkanal",
+            "Kostenträger",
+        ]
+        df["Konto_Nr_SKR51"] = df.index
+        df[acct_info] = df["Konto_Nr_SKR51"].str.split(pat="-", n=6, expand=True)
         return df
 
     def export_all_periods(self):
         dt = datetime.now()
         prev = str(dt.year - 1)
-        periods = [(prev, str(x).zfill(2)) for x in range(dt.month, 13)] + \
-            [(str(dt.year), str(x).zfill(2)) for x in range(1, dt.month)]
+        periods = [(prev, str(x).zfill(2)) for x in range(dt.month, 13)] + [
+            (str(dt.year), str(x).zfill(2)) for x in range(1, dt.month)
+        ]
         for year, month in periods:
             filename = self.export_filename_for_period(year, month)
             if not Path(filename).exists():
-                os.makedirs(Path(filename).parent.joinpath('info'), exist_ok=True)
+                os.makedirs(Path(filename).parent.joinpath("info"), exist_ok=True)
                 self.export_period(year, month)
 
     def export_period(self, year, month):
         self.set_bookkeep_period(year, month)
         # Übersetzungstabelle laden
-        df_translate = pd.read_csv(self.account_translation, decimal=',', sep=';', encoding='latin-1',
-                                   converters={i: str for i in range(0, 200)})
+        df_translate = pd.read_csv(
+            self.account_translation,
+            decimal=",",
+            sep=";",
+            encoding="latin-1",
+            converters={i: str for i in range(0, 200)},
+        )
         logging.info(df_translate.shape)
-        df_translate['duplicated'] = df_translate.duplicated()
-        logging.info(df_translate[df_translate['duplicated']])
-        df_translate = df_translate[['Konto_Nr_Händler', 'Konto_Nr_SKR51', 'Marke',
-                                     'Marke_HBV', 'Standort', 'Standort_HBV']]
-
-        row = df_translate[['Marke', 'Marke_HBV', 'Standort', 'Standort_HBV']] \
-            .drop_duplicates().sort_values(by=['Marke', 'Standort']).iloc[:1].to_dict(orient='records')[0]
-        row['Konto_Nr_Händler'] = '01-01-0861-00-00-00'
-        row['Konto_Nr_SKR51'] = '01-01-0861-00-00-00'
+        df_translate["duplicated"] = df_translate.duplicated()
+        logging.info(df_translate[df_translate["duplicated"]])
+        df_translate = df_translate[
+            [
+                "Konto_Nr_Händler",
+                "Konto_Nr_SKR51",
+                "Marke",
+                "Marke_HBV",
+                "Standort",
+                "Standort_HBV",
+            ]
+        ]
+
+        row = (
+            df_translate[["Marke", "Marke_HBV", "Standort", "Standort_HBV"]]
+            .drop_duplicates()
+            .sort_values(by=["Marke", "Standort"])
+            .iloc[:1]
+            .to_dict(orient="records")[0]
+        )
+        row["Konto_Nr_Händler"] = "01-01-0861-00-00-00"
+        row["Konto_Nr_SKR51"] = "01-01-0861-00-00-00"
 
         df_translate = pd.concat([df_translate, pd.DataFrame.from_records([row])])
         # print(df_translate.tail())
         # df_translate.drop(columns=['duplicated'], inplace=True)
         df_translate.drop_duplicates(inplace=True)
-        df_translate.set_index('Konto_Nr_Händler')
+        df_translate.set_index("Konto_Nr_Händler")
 
         # Kontensalden laden
         df2 = []
         for csv_file in self.account_bookings:
-            df2.append(pd.read_csv(csv_file, decimal=',', sep=';', encoding='latin-1', converters={0: str, 1: str}))
+            df2.append(
+                pd.read_csv(
+                    csv_file,
+                    decimal=",",
+                    sep=";",
+                    encoding="latin-1",
+                    converters={0: str, 1: str},
+                )
+            )
         df_bookings = pd.concat(df2)
         # Kontensalden auf gegebenen Monat filtern
         filter_from = self.current_year + self.first_month_of_financial_year
@@ -123,194 +165,238 @@ class GCHR:
             filter_from = self.last_year + self.first_month_of_financial_year
             filter_prev = self.last_year2 + self.first_month_of_financial_year
         filter_to = self.current_year + self.current_month
-        filter_opening = self.current_year + '00'
-        filter_prev_opening = self.last_year + '00'
+        filter_opening = self.current_year + "00"
+        filter_prev_opening = self.last_year + "00"
         prev_year_closed = True
 
-        df_opening_balance = df_bookings[(df_bookings['Bookkeep Period'] == filter_opening)]
+        df_opening_balance = df_bookings[(df_bookings["Bookkeep Period"] == filter_opening)]
         if df_opening_balance.shape[0] == 0:
-            df_opening_balance = df_bookings[(df_bookings['Bookkeep Period'] == filter_prev_opening) |
-                                             ((df_bookings['Bookkeep Period'] >= filter_prev) &
-                                             (df_bookings['Bookkeep Period'] < filter_from))].copy()
-            df_opening_balance['Bookkeep Period'] = filter_opening
+            df_opening_balance = df_bookings[
+                (df_bookings["Bookkeep Period"] == filter_prev_opening)
+                | ((df_bookings["Bookkeep Period"] >= filter_prev) & (df_bookings["Bookkeep Period"] < filter_from))
+            ].copy()
+            df_opening_balance["Bookkeep Period"] = filter_opening
             prev_year_closed = False
         # df_opening_balance = df_opening_balance.merge(df_translate, how='inner', on='Konto_Nr_Händler')
-        df_opening_balance = df_opening_balance[(df_opening_balance['Konto_Nr_Händler'].str.contains(r'-[013]\d\d+-'))]
-        df_opening_balance['amount'] = (df_opening_balance['Debit Amount'] + df_opening_balance['Credit Amount']).round(2)
+        df_opening_balance = df_opening_balance[(df_opening_balance["Konto_Nr_Händler"].str.contains(r"-[013]\d\d+-"))]
+        df_opening_balance["amount"] = (df_opening_balance["Debit Amount"] + df_opening_balance["Credit Amount"]).round(
+            2
+        )
         # df_opening_balance.drop(columns=['Debit Amount', 'Credit Amount', 'Debit Quantity', 'Credit Quantity'], inplace=True)
         # df_opening_balance = df_opening_balance.groupby(['Marke', 'Standort']).sum()
-        opening_balance = df_opening_balance['amount'].sum().round(2)
-        logging.info('Gewinn/Verlustvortrag')
+        opening_balance = df_opening_balance["amount"].aggregate("sum").round(2)
+        logging.info("Gewinn/Verlustvortrag")
         logging.info(opening_balance)
 
         if not prev_year_closed:
             row = {
-                'Konto_Nr_Händler': '01-01-0861-00-00-00',
-                'Bookkeep Period': filter_opening,
-                'Debit Amount': opening_balance * -1,
-                'Credit Amount': 0,
-                'Debit Quantity': 0,
-                'Credit Quantity': 0,
-                'amount': opening_balance * -1
+                "Konto_Nr_Händler": "01-01-0861-00-00-00",
+                "Bookkeep Period": filter_opening,
+                "Debit Amount": opening_balance * -1,
+                "Credit Amount": 0,
+                "Debit Quantity": 0,
+                "Credit Quantity": 0,
+                "amount": opening_balance * -1,
             }
             df_opening_balance = pd.concat([df_opening_balance, pd.DataFrame.from_records([row])])
 
-        df_bookings = df_bookings[(df_bookings['Bookkeep Period'] >= filter_from) & (df_bookings['Bookkeep Period'] <= filter_to)]
-        df_bookings['amount'] = (df_bookings['Debit Amount'] + df_bookings['Credit Amount']).round(2)
+        df_bookings = df_bookings[
+            (df_bookings["Bookkeep Period"] >= filter_from) & (df_bookings["Bookkeep Period"] <= filter_to)
+        ]
+        df_bookings["amount"] = (df_bookings["Debit Amount"] + df_bookings["Credit Amount"]).round(2)
         df_stats = df_bookings.copy()
         # df_stats = df_stats[df_stats['Konto_Nr_Händler'].str.match(r'-[24578]\d\d\d-')]
-        df_stats['Konto_Nr_Händler'] = df_stats['Konto_Nr_Händler'].str.replace(r'-(\d\d\d+)-', r'-\1_STK-', regex=True)
-        df_stats['amount'] = (df_bookings['Debit Quantity'] + df_bookings['Credit Quantity']).round(2)
+        df_stats["Konto_Nr_Händler"] = df_stats["Konto_Nr_Händler"].str.replace(r"-(\d\d\d+)-", r"-\1_STK-", regex=True)
+        df_stats["amount"] = (df_bookings["Debit Quantity"] + df_bookings["Credit Quantity"]).round(2)
 
         df_bookings = pd.concat([df_opening_balance, df_bookings, df_stats])
-        df_bookings = df_bookings[df_bookings['amount'] != 0.00]
+        df_bookings = df_bookings[df_bookings["amount"] != 0.00]
 
         if df_bookings.shape[0] == 0:
-            logging.error('ABBRUCH!!! Keine Daten vorhanden!')
+            logging.error("ABBRUCH!!! Keine Daten vorhanden!")
             return False
 
         bk_filter = self.bookkeep_filter()
         period_no = list(bk_filter.keys()).index(filter_to) + 1
 
         # Spalten konvertieren
-        df_bookings['period'] = df_bookings['Bookkeep Period'].apply(lambda x: bk_filter[x])
+        df_bookings["period"] = df_bookings["Bookkeep Period"].apply(lambda x: bk_filter[x])
 
-        logging.info('df_bookings: ' + str(df_bookings.shape))
+        logging.info("df_bookings: " + str(df_bookings.shape))
         # Join auf Übersetzung
-        df_combined = df_bookings.merge(df_translate, how='inner', on='Konto_Nr_Händler')
-        logging.info('df_combined: ' + str(df_combined.shape))
+        df_combined = df_bookings.merge(df_translate, how="inner", on="Konto_Nr_Händler")
+        logging.info(f"df_combined: {df_combined.shape}")
 
         # Hack für fehlende Markenzuordnung
-        df_combined['Fremdmarke'] = (df_combined['Marke_HBV'].str.match(r'^0000'))
-        df_combined['Marke'] = np.where(df_combined['Fremdmarke'], '99', df_combined['Marke'])
-
-        df_combined['Standort_egal'] = (df_combined['Standort_HBV'].str.match(r'^\d\d_'))
-        df_combined['Standort_HBV'] = np.where(df_combined['Fremdmarke'] | df_combined['Standort_egal'],
-                                               '0000', df_combined['Standort_HBV'])
+        df_combined["Fremdmarke"] = df_combined["Marke_HBV"].str.match(r"^0000")
+        df_combined["Marke"] = np.where(df_combined["Fremdmarke"], "99", df_combined["Marke"])
+
+        df_combined["Standort_egal"] = df_combined["Standort_HBV"].str.match(r"^\d\d_")
+        df_combined["Standort_HBV"] = np.where(
+            df_combined["Fremdmarke"] | df_combined["Standort_egal"],
+            "0000",
+            df_combined["Standort_HBV"],
+        )
 
-        makes = df_combined[['Marke', 'Marke_HBV']].drop_duplicates().sort_values(by=['Marke'])
-        sites = df_combined[['Marke', 'Standort', 'Standort_HBV']].drop_duplicates().sort_values(by=['Marke', 'Standort'])
+        makes = df_combined[["Marke", "Marke_HBV"]].drop_duplicates().sort_values(by=["Marke"])
+        sites = (
+            df_combined[["Marke", "Standort", "Standort_HBV"]].drop_duplicates().sort_values(by=["Marke", "Standort"])
+        )
 
         # df_combined.to_csv(account_invalid, decimal=',', sep=';', encoding='latin-1', index=False)
         # Gruppieren
         # df_grouped = df_combined.groupby(['Konto_Nr_SKR51', 'period']).sum()
-        df = df_combined.pivot_table(index=['Konto_Nr_SKR51'], columns=['period'], values='amount',
-                                     aggfunc=np.sum, margins=True, margins_name='CumulatedYear')
+        df = df_combined.pivot_table(
+            index=["Konto_Nr_SKR51"],
+            columns=["period"],
+            values="amount",
+            aggfunc=np.sum,
+            margins=True,
+            margins_name="CumulatedYear",
+        )
 
-        logging.info('df_pivot: ' + str(df.shape))
+        logging.info("df_pivot: " + str(df.shape))
         df = self.extract_acct_info(df)
         # df = df_translate.reset_index(drop=True).drop(columns=['Kostenträger_Ebene']).drop_duplicates()
         logging.info(df.shape)
         logging.info(df.columns)
         logging.info(df.head())
         # df = df.merge(df_translate, how='inner', on='Konto_Nr_SKR51')
-        logging.info('df: ' + str(df.shape))
-        df['Bilanz'] = (df['Konto_Nr'].str.match(r'^[013]'))
-        df['Kontoart'] = np.where(df['Bilanz'], '1', '2')
-        df['Kontoart'] = np.where(df['Konto_Nr'].str.contains('_STK'), '3', df['Kontoart'])
-        df['Kontoart'] = np.where(df['Konto_Nr'].str.match(r'^[9]'), '3', df['Kontoart'])
-        df['Konto_1'] = (df['Konto_Nr'].str.slice(0, 1))
+        logging.info("df: " + str(df.shape))
+        df["Bilanz"] = df["Konto_Nr"].str.match(r"^[013]")
+        df["Kontoart"] = np.where(df["Bilanz"], "1", "2")
+        df["Kontoart"] = np.where(df["Konto_Nr"].str.contains("_STK"), "3", df["Kontoart"])
+        df["Kontoart"] = np.where(df["Konto_Nr"].str.match(r"^[9]"), "3", df["Kontoart"])
+        df["Konto_1"] = df["Konto_Nr"].str.slice(0, 1)
 
         # Hack für fehlende Markenzuordnung
-        df = df.merge(makes, how='left', on='Marke')
-        df['Marke'] = np.where(df['Marke_HBV'].isna(), '99', df['Marke'])
-
-        df_debug = df.drop(columns=['Bilanz'])
-        logging.info(df_debug.groupby(['Kontoart']).sum())
-        logging.info(df_debug.groupby(['Kontoart', 'Konto_1']).sum())
-        logging.info(df_debug.groupby(['Konto_Nr']).sum())
-        df_debug.groupby(['Konto_Nr']).sum().to_csv(self.debug_file, decimal=',', sep=';', encoding='latin-1')
+        df = df.merge(makes, how="left", on="Marke")
+        df["Marke"] = np.where(df["Marke_HBV"].isna(), "99", df["Marke"])
+
+        df_debug = df.drop(columns=["Bilanz"])
+        logging.info(df_debug.groupby(["Kontoart"]).aggregate("sum"))
+        logging.info(df_debug.groupby(["Kontoart", "Konto_1"]).aggregate("sum"))
+        logging.info(df_debug.groupby(["Konto_Nr"]).aggregate("sum"))
+        df_debug.groupby(["Konto_Nr"]).aggregate("sum").to_csv(
+            self.debug_file, decimal=",", sep=";", encoding="latin-1"
+        )
 
         # Bereinigung GW-Kostenträger
-        df['NW_Verkauf_1'] = (df['Konto_Nr'].str.match(r'^[78]0')) & (df['Kostenstelle'].str.match(r'^[^1]\d'))
-        df['Kostenstelle'] = np.where(df['NW_Verkauf_1'] == True, '11', df['Kostenstelle'])
+        df["NW_Verkauf_1"] = (df["Konto_Nr"].str.match(r"^[78]0")) & (df["Kostenstelle"].str.match(r"^[^1]\d"))
+        df["Kostenstelle"] = np.where(df["NW_Verkauf_1"] == True, "11", df["Kostenstelle"])
 
-        df['Konto_7010'] = (df['Konto_Nr'].str.match(r'^[78]01[01]'))
-        df['Kostenstelle'] = np.where(df['Konto_7010'] == True, '14', df['Kostenstelle'])
+        df["Konto_7010"] = df["Konto_Nr"].str.match(r"^[78]01[01]")
+        df["Kostenstelle"] = np.where(df["Konto_7010"] == True, "14", df["Kostenstelle"])
 
-        df['GW_Verkauf_2'] = (df['Konto_Nr'].str.match(r'^[78]1')) & (df['Kostenstelle'].str.match(r'^[^2]\d'))
-        df['Kostenstelle'] = np.where(df['GW_Verkauf_2'] == True, '21', df['Kostenstelle'])
+        df["GW_Verkauf_2"] = (df["Konto_Nr"].str.match(r"^[78]1")) & (df["Kostenstelle"].str.match(r"^[^2]\d"))
+        df["Kostenstelle"] = np.where(df["GW_Verkauf_2"] == True, "21", df["Kostenstelle"])
 
-        df['GW_Verkauf_3'] = (df['Konto_Nr'].str.match(r'^[78]3')) & (df['Kostenstelle'].str.match(r'^[^3]\d'))
-        df['Kostenstelle'] = np.where(df['GW_Verkauf_3'] == True, '31', df['Kostenstelle'])
+        df["GW_Verkauf_3"] = (df["Konto_Nr"].str.match(r"^[78]3")) & (df["Kostenstelle"].str.match(r"^[^3]\d"))
+        df["Kostenstelle"] = np.where(df["GW_Verkauf_3"] == True, "31", df["Kostenstelle"])
 
-        df['GW_Verkauf_4'] = (df['Konto_Nr'].str.match(r'^[78]4')) & (df['Kostenstelle'].str.match(r'^[^4]\d'))
-        df['Kostenstelle'] = np.where(df['GW_Verkauf_4'] == True, '41', df['Kostenstelle'])
+        df["GW_Verkauf_4"] = (df["Konto_Nr"].str.match(r"^[78]4")) & (df["Kostenstelle"].str.match(r"^[^4]\d"))
+        df["Kostenstelle"] = np.where(df["GW_Verkauf_4"] == True, "41", df["Kostenstelle"])
 
-        df['GW_Verkauf_x420'] = (df['Konto_Nr'].str.match(r'^[78]420'))
-        df['Kostenstelle'] = np.where(df['GW_Verkauf_x420'] == True, '42', df['Kostenstelle'])
+        df["GW_Verkauf_x420"] = df["Konto_Nr"].str.match(r"^[78]420")
+        df["Kostenstelle"] = np.where(df["GW_Verkauf_x420"] == True, "42", df["Kostenstelle"])
 
-        df['GW_Verkauf_5'] = (df['Konto_Nr'].str.match(r'^[78]5')) & (df['Kostenstelle'].str.match(r'^[^5]\d'))
-        df['Kostenstelle'] = np.where(df['GW_Verkauf_5'] == True, '51', df['Kostenstelle'])
+        df["GW_Verkauf_5"] = (df["Konto_Nr"].str.match(r"^[78]5")) & (df["Kostenstelle"].str.match(r"^[^5]\d"))
+        df["Kostenstelle"] = np.where(df["GW_Verkauf_5"] == True, "51", df["Kostenstelle"])
 
-        df['GW_Verkauf_50'] = (df['Konto_Nr'].str.match(r'^[78]')) & (df['Kostenstelle'].str.match(r'^2'))
-        df['Kostenträger'] = np.where(df['GW_Verkauf_50'] == True, '52', df['Kostenträger'])
-        df['Kostenträger'] = np.where((df['GW_Verkauf_50'] == True) & (df['Marke'] == '01'), '50', df['Kostenträger'])
-
-        df['NW_Verkauf_00'] = (df['Konto_Nr'].str.match(r'^[78]2')) & \
-                              (df['Kostenstelle'].str.match(r'^1')) & \
-                              (df['Kostenträger'].str.match(r'^[^01234]'))
-        df['Kostenträger'] = np.where(df['NW_Verkauf_00'] == True, '00', df['Kostenträger'])
+        df["GW_Verkauf_50"] = (df["Konto_Nr"].str.match(r"^[78]")) & (df["Kostenstelle"].str.match(r"^2"))
+        df["Kostenträger"] = np.where(df["GW_Verkauf_50"] == True, "52", df["Kostenträger"])
+        df["Kostenträger"] = np.where(
+            (df["GW_Verkauf_50"] == True) & (df["Marke"] == "01"),
+            "50",
+            df["Kostenträger"],
+        )
 
-        df['GW_Stk_50'] = (df['Konto_Nr'].str.match(r'^9130')) & (df['Kostenstelle'].str.match(r'^2'))
-        df['Kostenträger'] = np.where(df['GW_Stk_50'] == True, '52', df['Kostenträger'])
-        df['Kostenträger'] = np.where((df['GW_Stk_50'] == True) & (df['Marke'] == '01'), '50', df['Kostenträger'])
+        df["NW_Verkauf_00"] = (
+            (df["Konto_Nr"].str.match(r"^[78]2"))
+            & (df["Kostenstelle"].str.match(r"^1"))
+            & (df["Kostenträger"].str.match(r"^[^01234]"))
+        )
+        df["Kostenträger"] = np.where(df["NW_Verkauf_00"] == True, "00", df["Kostenträger"])
 
-        df['Kostenträger'] = np.where(df['Bilanz'] == True, '00', df['Kostenträger'])
+        df["GW_Stk_50"] = (df["Konto_Nr"].str.match(r"^9130")) & (df["Kostenstelle"].str.match(r"^2"))
+        df["Kostenträger"] = np.where(df["GW_Stk_50"] == True, "52", df["Kostenträger"])
+        df["Kostenträger"] = np.where((df["GW_Stk_50"] == True) & (df["Marke"] == "01"), "50", df["Kostenträger"])
 
-        df['Konto_5er'] = (df['Konto_Nr'].str.match('^5')) | (df['Konto_Nr'].str.match('^9143'))
-        df['Absatzkanal'] = np.where(df['Konto_5er'] == True, '99', df['Absatzkanal'])
+        df["Kostenträger"] = np.where(df["Bilanz"] == True, "00", df["Kostenträger"])
 
-        df['Konto_5005'] = (df['Konto_Nr'].str.match('^5005')) & (df['Kostenstelle'].str.match(r'^[^12]'))
-        df['Kostenstelle'] = np.where(df['Konto_5005'] == True, '20', df['Kostenstelle'])
-        df['Kostenträger'] = np.where(df['Konto_5005'] == True, '50', df['Kostenträger'])
+        df["Konto_5er"] = (df["Konto_Nr"].str.match("^5")) | (df["Konto_Nr"].str.match("^9143"))
+        df["Absatzkanal"] = np.where(df["Konto_5er"] == True, "99", df["Absatzkanal"])
 
-        df['Konto_5007'] = (df['Konto_Nr'].str.match('^5007')) & (df['Kostenstelle'].str.match(r'^([^4]|42)'))
-        df['Kostenstelle'] = np.where(df['Konto_5007'] == True, '41', df['Kostenstelle'])
-        df['Kostenträger'] = np.where(df['Konto_5007'] == True, '70', df['Kostenträger'])
+        df["Konto_5005"] = (df["Konto_Nr"].str.match("^5005")) & (df["Kostenstelle"].str.match(r"^[^12]"))
+        df["Kostenstelle"] = np.where(df["Konto_5005"] == True, "20", df["Kostenstelle"])
+        df["Kostenträger"] = np.where(df["Konto_5005"] == True, "50", df["Kostenträger"])
 
-        df['Konto_914er'] = (df['Konto_Nr'].str.match('^914[34]')) & (df['Kostenträger'].str.match(r'^[^7]'))
-        df['Kostenträger'] = np.where(df['Konto_914er'] == True, '70', df['Kostenträger'])
+        df["Konto_5007"] = (df["Konto_Nr"].str.match("^5007")) & (df["Kostenstelle"].str.match(r"^([^4]|42)"))
+        df["Kostenstelle"] = np.where(df["Konto_5007"] == True, "41", df["Kostenstelle"])
+        df["Kostenträger"] = np.where(df["Konto_5007"] == True, "70", df["Kostenträger"])
 
-        df['Teile_30_60'] = (df['Konto_Nr'].str.match(r'^[578]')) & \
-                            (df['Kostenstelle'].str.match(r'^[3]')) & \
-                            (df['Kostenträger'].str.match(r'^[^6]'))
-        df['Kostenträger'] = np.where(df['Teile_30_60'] == True, '60', df['Kostenträger'])
+        df["Konto_914er"] = (df["Konto_Nr"].str.match("^914[34]")) & (df["Kostenträger"].str.match(r"^[^7]"))
+        df["Kostenträger"] = np.where(df["Konto_914er"] == True, "70", df["Kostenträger"])
 
-        df['Service_40_70'] = (df['Konto_Nr'].str.match(r'^[578]')) & \
-                              (df['Kostenstelle'].str.match(r'^[4]')) & \
-                              (df['Kostenträger'].str.match(r'^[^7]'))
-        df['Kostenträger'] = np.where(df['Service_40_70'] == True, '70', df['Kostenträger'])
+        df["Teile_30_60"] = (
+            (df["Konto_Nr"].str.match(r"^[578]"))
+            & (df["Kostenstelle"].str.match(r"^[3]"))
+            & (df["Kostenträger"].str.match(r"^[^6]"))
+        )
+        df["Kostenträger"] = np.where(df["Teile_30_60"] == True, "60", df["Kostenträger"])
 
-        from_label = ['Marke', 'Standort', 'Konto_Nr', 'Kostenstelle', 'Absatzkanal', 'Kostenträger']
-        to_label = ['Make', 'Site', 'Account', 'Origin', 'SalesChannel', 'CostCarrier']
+        df["Service_40_70"] = (
+            (df["Konto_Nr"].str.match(r"^[578]"))
+            & (df["Kostenstelle"].str.match(r"^[4]"))
+            & (df["Kostenträger"].str.match(r"^[^7]"))
+        )
+        df["Kostenträger"] = np.where(df["Service_40_70"] == True, "70", df["Kostenträger"])
+
+        from_label = [
+            "Marke",
+            "Standort",
+            "Konto_Nr",
+            "Kostenstelle",
+            "Absatzkanal",
+            "Kostenträger",
+        ]
+        to_label = ["Make", "Site", "Account", "Origin", "SalesChannel", "CostCarrier"]
         df = df.rename(columns=dict(zip(from_label, to_label)))
-        makes = makes.rename(columns=dict(zip(from_label, to_label))).to_dict(orient='records')
-        sites = sites.rename(columns=dict(zip(from_label, to_label))).to_dict(orient='records')
+        makes = makes.rename(columns=dict(zip(from_label, to_label))).to_dict(orient="records")
+        sites = sites.rename(columns=dict(zip(from_label, to_label))).to_dict(orient="records")
 
-        df['CostAccountingString'] = df['Make'] + df['Site'] + df['Origin'] + \
-            df['SalesChannel'] + df['CostCarrier']
-        df['IsNumeric'] = (df['CostAccountingString'].str.isdigit()) & (df['Account'].str.isdigit()) & (df['Account'].str.len() == 4)
+        df["CostAccountingString"] = df["Make"] + df["Site"] + df["Origin"] + df["SalesChannel"] + df["CostCarrier"]
+        df["IsNumeric"] = (
+            (df["CostAccountingString"].str.isdigit()) & (df["Account"].str.isdigit()) & (df["Account"].str.len() == 4)
+        )
 
-        df_invalid = df[df['IsNumeric'] == False]
-        df_invalid.to_csv(self.account_invalid, decimal=',', sep=';', encoding='latin-1', index=False)
-        export_csv = self.export_filename[:-4] + '.csv'
+        df_invalid = df[df["IsNumeric"] == False]
+        df_invalid.to_csv(self.account_invalid, decimal=",", sep=";", encoding="latin-1", index=False)
+        export_csv = self.export_filename[:-4] + ".csv"
 
-        df.to_csv(export_csv, decimal=',', sep=';', encoding='latin-1', index=False)
-        df = df[df['IsNumeric'] != False].groupby(ACCOUNT_INFO, as_index=False).sum()
+        df.to_csv(export_csv, decimal=",", sep=";", encoding="latin-1", index=False)
+        df = df[df["IsNumeric"] != False].groupby(ACCOUNT_INFO, as_index=False).aggregate("sum")
         # Infos ergänzen
-        df['Decimals'] = 2
+        df["Decimals"] = 2
         # df['OpeningBalance'] = 0.0
         logging.info(df.shape)
-        self.export_xml(df.to_dict(orient='records'), bk_filter, period_no, makes, sites)
+        self.export_xml(df.to_dict(orient="records"), bk_filter, period_no, makes, sites)
 
         # Join auf Übersetzung - nicht zugeordnet
-        df_ignored = df_bookings.merge(df_translate, how='left', on='Konto_Nr_Händler')
-        df_ignored = df_ignored[df_ignored['Konto_Nr_SKR51'].isna()]    # [['Konto_Nr_Händler', 'Bookkeep Period', 'amount', 'quantity']]
+        df_ignored = df_bookings.merge(df_translate, how="left", on="Konto_Nr_Händler")
+        df_ignored = df_ignored[
+            df_ignored["Konto_Nr_SKR51"].isna()
+        ]  # [['Konto_Nr_Händler', 'Bookkeep Period', 'amount', 'quantity']]
         if not df_ignored.empty:
-            df_ignored = df_ignored.pivot_table(index=['Konto_Nr_Händler'], columns=['period'], values='amount',
-                                                aggfunc=np.sum, margins=True, margins_name='CumulatedYear')
-            df_ignored.to_csv(self.account_ignored, decimal=',', sep=';', encoding='latin-1')
+            df_ignored = df_ignored.pivot_table(
+                index=["Konto_Nr_Händler"],
+                columns=["period"],
+                values="amount",
+                aggfunc=np.sum,
+                margins=True,
+                margins_name="CumulatedYear",
+            )
+            df_ignored.to_csv(self.account_ignored, decimal=",", sep=";", encoding="latin-1")
         return self.export_filename
 
     @property
@@ -325,59 +411,58 @@ class GCHR:
         return f"{self.base_dir}/Export/{year}/export_{year}-{month}.xml"
 
     def export_xml(self, records, bk_filter, period_no, makes, sites):
-        record_elements = ACCOUNT_INFO + ['Decimals'] + \
-            list(bk_filter.values())[:period_no] + ['CumulatedYear']
-        root = ET.Element('HbvData')
-        h = ET.SubElement(root, 'Header')
+        record_elements = ACCOUNT_INFO + ["Decimals"] + list(bk_filter.values())[:period_no] + ["CumulatedYear"]
+        root = ET.Element("HbvData")
+        h = ET.SubElement(root, "Header")
         for k, v in self.header(makes, sites).items():
             ET.SubElement(h, k).text = str(v)
 
-        make_list = ET.SubElement(root, 'MakeList')
+        make_list = ET.SubElement(root, "MakeList")
         for m in makes:
-            e = ET.SubElement(make_list, 'MakeListEntry')
-            ET.SubElement(e, 'Make').text = m['Make']
-            ET.SubElement(e, 'MakeCode').text = m['Marke_HBV']
+            e = ET.SubElement(make_list, "MakeListEntry")
+            ET.SubElement(e, "Make").text = m["Make"]
+            ET.SubElement(e, "MakeCode").text = m["Marke_HBV"]
 
-        bm_code_list = ET.SubElement(root, 'BmCodeList')
+        bm_code_list = ET.SubElement(root, "BmCodeList")
         for s in sites:
-            e = ET.SubElement(bm_code_list, 'BmCodeEntry')
-            ET.SubElement(e, 'Make').text = s['Make']
-            ET.SubElement(e, 'Site').text = s['Site']
-            ET.SubElement(e, 'BmCode').text = s['Standort_HBV']
+            e = ET.SubElement(bm_code_list, "BmCodeEntry")
+            ET.SubElement(e, "Make").text = s["Make"]
+            ET.SubElement(e, "Site").text = s["Site"]
+            ET.SubElement(e, "BmCode").text = s["Standort_HBV"]
 
-        record_list = ET.SubElement(root, 'RecordList')
+        record_list = ET.SubElement(root, "RecordList")
         for row in records:
-            record = ET.SubElement(record_list, 'Record')
+            record = ET.SubElement(record_list, "Record")
             for e in record_elements:
                 child = ET.SubElement(record, e)
                 field = row.get(e, 0.0)
-                if str(field) == 'nan':
-                    field = '0'
+                if str(field) == "nan":
+                    field = "0"
                 elif type(field) is float:
-                    field = '{:.0f}'.format(field * 100)
+                    field = "{:.0f}".format(field * 100)
                 child.text = str(field)
 
-        with open(self.export_filename, 'w', encoding='utf-8') as fwh:
-            fwh.write(minidom.parseString(ET.tostring(root)).toprettyxml(indent='  '))
+        with open(self.export_filename, "w", encoding="utf-8") as fwh:
+            fwh.write(minidom.parseString(ET.tostring(root)).toprettyxml(indent="  "))
 
     def convert_to_row(self, node):
         return [child.text for child in node]
 
     def convert_xml_to_csv(self, xmlfile, csvfile):
-        record_list = ET.parse(xmlfile).getroot().find('RecordList')
-        header = [child.tag for child in record_list.find('Record')]
-        bookings = [self.convert_to_row(node) for node in record_list.findall('Record')]
-        with open(csvfile, 'w') as fwh:
-            cwh = csv.writer(fwh, delimiter=';')
+        record_list = ET.parse(xmlfile).getroot().find("RecordList")
+        header = [child.tag for child in record_list.find("Record")]
+        bookings = [self.convert_to_row(node) for node in record_list.findall("Record")]
+        with open(csvfile, "w") as fwh:
+            cwh = csv.writer(fwh, delimiter=";")
             cwh.writerow(header)
             cwh.writerows(bookings)
         return True
 
     def convert_csv_to_xml(self, csvfile, xmlfile):
-        makes = [{'Make': '01', 'Marke_HBV': '1844'}]
-        sites = [{'Make': '01', 'Site': '01', 'Marke_HBV': '1844'}]
-        with open(csvfile, 'r', encoding='latin-1') as frh:
-            csv_reader = csv.DictReader(frh, delimiter=';')
+        makes = [{"Make": "01", "Marke_HBV": "1844"}]
+        sites = [{"Make": "01", "Site": "01", "Marke_HBV": "1844"}]
+        with open(csvfile, "r", encoding="latin-1") as frh:
+            csv_reader = csv.DictReader(frh, delimiter=";")
             self.export_xml(csv_reader, self.bookkeep_filter(), 1, makes, sites, xmlfile)
 
 
@@ -393,7 +478,7 @@ class Kunden(Enum):
 
 
 def gchr_local(base_dir):
-    for path in Path(base_dir).glob('*'):
+    for path in Path(base_dir).glob("*"):
         if path.is_dir():
             print(path.name)
             gchr_export(str(path))
@@ -404,8 +489,8 @@ def gchr_export(base_dir):
     gchr.export_all_periods()
 
 
-if __name__ == '__main__':
-    base_dir = os.getcwd() + '/gcstruct/Kunden'
+if __name__ == "__main__":
+    base_dir = os.getcwd() + "/gcstruct/Kunden"
 
     if Path(base_dir).exists():
         gchr_local(base_dir)

+ 1 - 0
gcstruct/gchr2.bat

@@ -1,3 +1,4 @@
 cd /d %~dp0
+call ..\.venv\Scripts\activate.bat
 pyinstaller -F --path %~dp0 gchr2.py
 pause

+ 37 - 33
gcstruct/gchr2.spec

@@ -4,37 +4,41 @@
 block_cipher = None
 
 
-a = Analysis(['gchr2.py'],
-             pathex=['C:\\Projekte\\Python\\gcstruct\\'],
-             binaries=[],
-             datas=[],
-             hiddenimports=[],
-             hookspath=[],
-             hooksconfig={},
-             runtime_hooks=[],
-             excludes=[],
-             win_no_prefer_redirects=False,
-             win_private_assemblies=False,
-             cipher=block_cipher,
-             noarchive=False)
-pyz = PYZ(a.pure, a.zipped_data,
-             cipher=block_cipher)
+a = Analysis(
+    ['gchr2.py'],
+    pathex=['C:\\Projekte\\Python\\gcstruct\\'],
+    binaries=[],
+    datas=[],
+    hiddenimports=[],
+    hookspath=[],
+    hooksconfig={},
+    runtime_hooks=[],
+    excludes=[],
+    win_no_prefer_redirects=False,
+    win_private_assemblies=False,
+    cipher=block_cipher,
+    noarchive=False,
+)
+pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher)
 
-exe = EXE(pyz,
-          a.scripts,
-          a.binaries,
-          a.zipfiles,
-          a.datas,  
-          [],
-          name='gchr2',
-          debug=False,
-          bootloader_ignore_signals=False,
-          strip=False,
-          upx=True,
-          upx_exclude=[],
-          runtime_tmpdir=None,
-          console=True,
-          disable_windowed_traceback=False,
-          target_arch=None,
-          codesign_identity=None,
-          entitlements_file=None )
+exe = EXE(
+    pyz,
+    a.scripts,
+    a.binaries,
+    a.zipfiles,
+    a.datas,
+    [],
+    name='gchr2',
+    debug=False,
+    bootloader_ignore_signals=False,
+    strip=False,
+    upx=True,
+    upx_exclude=[],
+    runtime_tmpdir=None,
+    console=True,
+    disable_windowed_traceback=False,
+    argv_emulation=False,
+    target_arch=None,
+    codesign_identity=None,
+    entitlements_file=None,
+)

+ 37 - 112
gcstruct/gcstruct.py

@@ -23,8 +23,7 @@ def get_flat(node):
             "accounts": node["accounts"],
             "costcenter": "",
             "level": node["level"],
-            "drilldown": node["level"]
-            < 2,  # (node['level'] != 2 and len(node['accounts']) == 0),
+            "drilldown": node["level"] < 2,  # (node['level'] != 2 and len(node['accounts']) == 0),
             "form": node["form"],
             "accountlevel": False,
             "absolute": True,
@@ -104,19 +103,13 @@ def get_structure_exports(s):
         "NeueHerstellerkontenAnlegen",
     ]
     for e in export_files:
-        if (
-            s.find(e) is not None
-            and s.find(e).text is not None
-            and s.find(e).text[-4:] == ".csv"
-        ):
+        if s.find(e) is not None and s.find(e).text is not None and s.find(e).text[-4:] == ".csv":
             result["files"][e] = s.find(e).text
     for e in export_format:
         if s.find(e) is not None and s.find(e).text != "":
             result["format"][e] = s.find(e).text
 
-    result["format"]["NeueHerstellerkontenAnlegen"] = (
-        result["format"]["NeueHerstellerkontenAnlegen"] == "true"
-    )
+    result["format"]["NeueHerstellerkontenAnlegen"] = result["format"]["NeueHerstellerkontenAnlegen"] == "true"
     return result
 
 
@@ -170,9 +163,7 @@ class GCStruct:
 
     def __init__(self, struct_dir, export_dir=None):
         self.config["path"] = struct_dir
-        self.config["path2"] = (
-            struct_dir + "/export" if export_dir is None else export_dir
-        )
+        self.config["path2"] = struct_dir + "/export" if export_dir is None else export_dir
 
         self.config["file"] = f"{self.config['path']}/config/gcstruct.xml"
         if not Path(self.config["file"]).exists():
@@ -180,8 +171,7 @@ class GCStruct:
 
         cfg = ET.parse(self.config["file"])
         self.config["default"] = [
-            s.find("Name").text
-            for s in cfg.getroot().find("Strukturdefinitionen").findall("Struktur")
+            s.find("Name").text for s in cfg.getroot().find("Strukturdefinitionen").findall("Struktur")
         ]
         self.config["export"] = dict(
             [
@@ -190,9 +180,7 @@ class GCStruct:
             ]
         )
 
-        struct = dict(
-            [(x, get_default_cols(i)) for (i, x) in enumerate(self.config["default"])]
-        )
+        struct = dict([(x, get_default_cols(i)) for (i, x) in enumerate(self.config["default"])])
         struct.update(self.config["special"])
         self.config["struct"] = struct
         # print(self.config['struct'])
@@ -232,21 +220,17 @@ class GCStruct:
             csv_reader = csv.reader(f, delimiter=";")
             imported_csv = [row[:max_rows] for row in csv_reader]
 
-        df = pd.DataFrame.from_records(
-            np.array(imported_csv[1:], dtype="object"), columns=imported_csv[0]
-        ).fillna(value="")
+        df = pd.DataFrame.from_records(np.array(imported_csv[1:], dtype="object"), columns=imported_csv[0]).fillna(
+            value=""
+        )
         df = df.rename(columns={"Kostenstelle": "Konto_KST", "STK": "Konto_STK"})
 
         for i, (s, cols) in enumerate(struct.items()):
             df[s] = reduce(lambda x, y: x + ";" + df[y], cols, "")
             df[s] = df[s].apply(lambda x: x[1:])
             df["LetzteEbene" + str(i + 1)] = df[s].apply(lambda x: last_layer(x))
-            df["LetzteEbene" + str(i + 1) + "_Nr"] = df[s].apply(
-                lambda x: split_it(x, 0)
-            )
-            df["LetzteEbene" + str(i + 1) + "_Bez"] = df[s].apply(
-                lambda x: split_it(x, 1)
-            )
+            df["LetzteEbene" + str(i + 1) + "_Nr"] = df[s].apply(lambda x: split_it(x, 0))
+            df["LetzteEbene" + str(i + 1) + "_Bez"] = df[s].apply(lambda x: split_it(x, 1))
         df["Herstellerkonto_Nr"] = df["LetzteEbene1_Nr"]
         df["Herstellerkonto_Bez"] = df["LetzteEbene1_Bez"]
         return df
@@ -298,9 +282,7 @@ class GCStruct:
         )
 
     def get_accounts(self, structure, id):
-        return [
-            x["Konto_Nr"] for x in self.json_result["accounts"] if x[structure] == id
-        ]
+        return [x["Konto_Nr"] for x in self.json_result["accounts"] if x[structure] == id]
         # return []
         # res = self.structure_ids.groups.get((structure, id))
         # if res is None:
@@ -311,26 +293,16 @@ class GCStruct:
         for s in self.config["export"].keys():
             for filetype, filename in self.config["export"][s]["files"].items():
                 with open(self.config["path2"] + "/" + filename, "w") as fwh:
-                    fwh.write(
-                        "Konto_Nr_Hersteller;Konto_Nr_Split;Konto_Nr_Haendler;Info\n"
-                    )
+                    fwh.write("Konto_Nr_Hersteller;Konto_Nr_Split;Konto_Nr_Haendler;Info\n")
                     # 'Hersteller'Konto_Nr;Konto_Bezeichnung;Case;Info'
                     for a in self.json_result["accounts"]:
                         if a["Herstellerkonto_Nr"] != "":
                             account = chevron.render(
-                                self.config["export"]["SKR51"]["format"][
-                                    "HerstellerkontoFormat"
-                                ],
+                                self.config["export"]["SKR51"]["format"]["HerstellerkontoFormat"],
                                 a,
                             )
                             fwh.write(
-                                account
-                                + ";"
-                                + account
-                                + ";"
-                                + a["Konto_Nr"]
-                                + ";"
-                                + "\n"
+                                account + ";" + account + ";" + a["Konto_Nr"] + ";" + "\n"
                             )  # a['Herstellerkonto_Bez']
 
     def get_tree(self, node, parents, structure):
@@ -366,14 +338,10 @@ class GCStruct:
         }
 
     def post_structure_and_tree(self):
-        json_post = json.load(
-            open(f"{self.config['path']}/{self.config['output']}", "r")
-        )
+        json_post = json.load(open(f"{self.config['path']}/{self.config['output']}", "r"))
 
         # Kontenrahmen.csv
-        ebenen = [
-            "Ebene" + str(i) for i in range(1, len(self.config["default"]) * 10 + 1)
-        ]
+        ebenen = ["Ebene" + str(i) for i in range(1, len(self.config["default"]) * 10 + 1)]
         header = ";".join(self.config["columns"] + ebenen)
         cols = self.config["columns"] + self.config["default"]
         with open(
@@ -392,9 +360,7 @@ class GCStruct:
                 "w",
                 encoding="latin-1",
             ) as f:
-                f.write(
-                    ";".join(["Ebene" + str(i * 10 + j) for j in range(1, 11)]) + "\n"
-                )
+                f.write(";".join(["Ebene" + str(i * 10 + j) for j in range(1, 11)]) + "\n")
                 rows = structure_from_tree({"id": ";" * 9, "children": json_post[s]})
                 f.write("\n".join(rows))
 
@@ -403,9 +369,7 @@ class GCStruct:
             root.set("Name", s)
             xml_from_tree(root, {"id": ";" * 9, "children": json_post[s]})
 
-            with open(
-                f"{self.config['path']}/Xml/{s}_out.xml", "w", encoding="utf-8"
-            ) as f:
+            with open(f"{self.config['path']}/Xml/{s}_out.xml", "w", encoding="utf-8") as f:
                 f.write(BeautifulSoup(ET.tostring(root), "xml").prettify())
 
     def skr51_translate(self, accounts_combined_files):
@@ -457,9 +421,7 @@ class GCStruct:
             elif t_from in ["Marke_HBV"]:
                 df_source["Marke_HBV"] = df_source["Marke"]
             elif t_from in ["Standort_HBV"]:
-                df_source["Standort_HBV"] = (
-                    df_source["Standort"] + "_" + df_source["Marke"]
-                )
+                df_source["Standort_HBV"] = df_source["Standort"] + "_" + df_source["Marke"]
                 df_source["BMC"] = "BMC_" + df_source["Standort_HBV"]
             elif t_to == "KTR":
                 df_source["KTR"] = np.where(
@@ -479,9 +441,7 @@ class GCStruct:
                 )
             else:
                 df_source[t_to] = t_to + "_" + df_source[t_from]
-            df_source = df_source.merge(
-                df_translate[t_from], how="left", on=[t_to], suffixes=(None, "_" + t_to)
-            )
+            df_source = df_source.merge(df_translate[t_from], how="left", on=[t_to], suffixes=(None, "_" + t_to))
             df_source[t_to + "_Nr"] = np.where(
                 df_source[t_to + "_Nr"].isna(),
                 df_source[t_from],
@@ -515,9 +475,7 @@ class GCStruct:
             + df_source["Kostenträger"]
         )
         # df_source.to_csv(f"{self.config['path2']}/SKR51_Uebersetzung.csv", sep=';', encoding='latin-1', index=False)
-        df_source["MAR_Nr_MAR"] = np.where(
-            df_source["MAR_Nr_MAR"].isna(), "0000", df_source["MAR_Nr_MAR"]
-        )
+        df_source["MAR_Nr_MAR"] = np.where(df_source["MAR_Nr_MAR"].isna(), "0000", df_source["MAR_Nr_MAR"])
         from_label = [
             "MAR_Nr",
             "STA_Nr",
@@ -544,9 +502,7 @@ class GCStruct:
             "Marke_HBV",
             "Standort_HBV",
         ]
-        df_combined = df_source[from_label].rename(
-            columns=dict(zip(from_label, to_label))
-        )
+        df_combined = df_source[from_label].rename(columns=dict(zip(from_label, to_label)))
         df_combined.to_csv(
             f"{self.config['path2']}/Kontenrahmen_uebersetzt.csv",
             sep=";",
@@ -589,8 +545,7 @@ class GCStruct:
         )
         df_source["Konto_Nr"] = np.where(
             df_source["Konto_Nr"].str.contains(r"^5\d+_4"),
-            df_source["Konto_Nr"]
-            + df_source["Kostenstelle"].str.slice(start=1, stop=2),
+            df_source["Konto_Nr"] + df_source["Kostenstelle"].str.slice(start=1, stop=2),
             df_source["Konto_Nr"],
         )
 
@@ -629,9 +584,7 @@ class GCStruct:
                 df_source[e].str.extract(r"\/(.*)}", expand=False) + " falsch",
                 df_source[e],
             )  # df_source[e].str.extract(r'/(.*)}') +
-            df_source[e] = np.where(
-                df_source[e] == "[KTR]", df_source["Kostenträger_Ebene"], df_source[e]
-            )
+            df_source[e] = np.where(df_source[e] == "[KTR]", df_source["Kostenträger_Ebene"], df_source[e])
         # df_all[df_all['Ebene1'] == ]
         # print(df_source.head())
         df_source["Konto_neu"] = (
@@ -649,24 +602,12 @@ class GCStruct:
             + " - "
             + df_source["Konto_Bezeichnung"]
         )
-        df_source["Ebene1_empty"] = df_source[
-            "Ebene1"
-        ].isna()  # , df_source['Ebene1'].map(lambda x: x == ''))
-        df_source["Konto_neu"] = np.where(
-            df_source["Ebene1_empty"], "keine Zuordnung", df_source["Konto_neu"]
-        )
-        df_source["Ebene1"] = np.where(
-            df_source["Ebene1_empty"], "keine Zuordnung", df_source["Ebene1"]
-        )
-        df_source["Konto_Gruppe"] = (
-            df_source["Konto_Nr"] + " - " + df_source["Konto_Bezeichnung"]
-        )
-        df_source["Konto_Gruppe"] = np.where(
-            df_source["Ebene1_empty"], "keine Zuordnung", df_source["Konto_Gruppe"]
-        )
-        df_source["Konto_Gesamt"] = (
-            df_source["Konto_Nr_Gesamt"] + " - " + df_source["Konto_Bezeichnung"]
-        )
+        df_source["Ebene1_empty"] = df_source["Ebene1"].isna()  # , df_source['Ebene1'].map(lambda x: x == ''))
+        df_source["Konto_neu"] = np.where(df_source["Ebene1_empty"], "keine Zuordnung", df_source["Konto_neu"])
+        df_source["Ebene1"] = np.where(df_source["Ebene1_empty"], "keine Zuordnung", df_source["Ebene1"])
+        df_source["Konto_Gruppe"] = df_source["Konto_Nr"] + " - " + df_source["Konto_Bezeichnung"]
+        df_source["Konto_Gruppe"] = np.where(df_source["Ebene1_empty"], "keine Zuordnung", df_source["Konto_Gruppe"])
+        df_source["Konto_Gesamt"] = df_source["Konto_Nr_Gesamt"] + " - " + df_source["Konto_Bezeichnung"]
 
         df_amount = df_source[df_source["Ebene1"] == "Umsatzerlöse"].reset_index()
         df_amount["Ebene1"] = "verkaufte Stückzahlen"
@@ -691,9 +632,7 @@ class GCStruct:
         df_source["Ebene100"] = np.where(df_source["BWA"], df_source["Ebene90"], "")
 
         df_source["GuV"] = df_source["Ebene71"] == "GuV"
-        df_source["Ebene81"] = np.where(
-            df_source["GuV"], df_source["Ebene72"], "Bilanz"
-        )
+        df_source["Ebene81"] = np.where(df_source["GuV"], df_source["Ebene72"], "Bilanz")
         df_source["Ebene82"] = np.where(df_source["GuV"], df_source["Ebene73"], "")
         df_source["Ebene83"] = np.where(df_source["GuV"], df_source["Ebene74"], "")
         df_source["Ebene84"] = np.where(df_source["GuV"], df_source["Ebene75"], "")
@@ -781,12 +720,8 @@ class GCStruct:
         )
         df_main["value"] = ""
         for c in cols:
-            df_main = df_main.merge(
-                df_vars, how="left", left_on=c, right_on="key", suffixes=(None, "_" + c)
-            )
-            df_main[c] = np.where(
-                df_main["value_" + c].isna(), df_main[c], df_main["value_" + c]
-            )
+            df_main = df_main.merge(df_vars, how="left", left_on=c, right_on="key", suffixes=(None, "_" + c))
+            df_main[c] = np.where(df_main["value_" + c].isna(), df_main[c], df_main["value_" + c])
 
         df_amount = df_main[df_main["Ebene1"] == "Umsatzerlöse"].reset_index()
         df_amount["Ebene1"] = "verkaufte Stückzahlen"
@@ -818,13 +753,9 @@ def gcstruct_uebersetzung(base_dir=None):
             base_dir = base_dir.parent.parent
             import_dir = base_dir.joinpath("System/OPTIMA/Export")
     elif not base_dir.joinpath("GCStruct_Aufbereitung").exists():
-        base_dir = Path(
-            "//192.168.2.21/verwaltung/Kunden/Luchtenberg/1 Umstellung SKR51/"
-        )
+        base_dir = Path("//192.168.2.21/verwaltung/Kunden/Luchtenberg/1 Umstellung SKR51/")
         if not base_dir.exists():
-            base_dir = Path(
-                "//media/fileserver1/verwaltung/Kunden/Luchtenberg/1 Umstellung SKR51/"
-            )
+            base_dir = Path("//media/fileserver1/verwaltung/Kunden/Luchtenberg/1 Umstellung SKR51/")
         import_dir = base_dir
 
     struct = GCStruct(str(base_dir.joinpath("GCStruct_Aufbereitung")))
@@ -833,13 +764,7 @@ def gcstruct_uebersetzung(base_dir=None):
     # copyfile('c:/Projekte/Python/Gcstruct/Kontenrahmen_kombiniert.csv', base_dir + 'GCStruct_Modell/Export/Kontenrahmen_kombiniert.csv')
 
     struct2 = GCStruct(str(base_dir.joinpath("GCStruct_Modell")))
-    struct2.skr51_translate2(
-        str(
-            base_dir.joinpath(
-                "GCStruct_Aufbereitung/Export/Kontenrahmen_uebersetzt.csv"
-            )
-        )
-    )
+    struct2.skr51_translate2(str(base_dir.joinpath("GCStruct_Aufbereitung/Export/Kontenrahmen_uebersetzt.csv")))
     print("SKR51_Uebersetzung.csv erstellt.")
     struct2.skr51_vars()
     print("SKR51_Struktur.csv erstellt.")

+ 1 - 0
gcstruct/gcstruct_uebersetzung.bat

@@ -1,3 +1,4 @@
 cd /d %~dp0
+call ..\.venv\Scripts\activate.bat
 pyinstaller -F --path %~dp0 gcstruct_uebersetzung.py
 pause

+ 1 - 1
gcstruct/gcstruct_uebersetzung.py

@@ -1,5 +1,5 @@
 from gcstruct import gcstruct_uebersetzung
 
 
-if __name__ == '__main__':
+if __name__ == "__main__":
     gcstruct_uebersetzung()

+ 1 - 1
tox.ini

@@ -1,5 +1,5 @@
 [flake8]
-ignore = E712, W504
+ignore = E203, E712, W503, W504
 max-line-length = 140
 # exclude = tests/*
 # max-complexity = 10