|
@@ -21,6 +21,8 @@ ACCOUNT_INFO = [
|
|
|
|
|
|
|
|
|
class GCHR:
|
|
|
+ booking_date: datetime
|
|
|
+
|
|
|
def __init__(self, base_dir) -> None:
|
|
|
self.base_dir = base_dir
|
|
|
|
|
@@ -60,8 +62,8 @@ class GCHR:
|
|
|
"Currency": "EUR",
|
|
|
"NumberOfMakes": len(makes),
|
|
|
"NumberOfSites": len(sites),
|
|
|
- "ExtractionDate": datetime.now().strftime("%d.%m.%Y"),
|
|
|
- "ExtractionTime": datetime.now().strftime("%H:%M:%S"),
|
|
|
+ "ExtractionDate": self.booking_date.strftime("%d.%m.%Y"),
|
|
|
+ "ExtractionTime": self.booking_date.strftime("%H:%M:%S"),
|
|
|
"BeginFiscalYear": self.first_month_of_financial_year,
|
|
|
}
|
|
|
|
|
@@ -92,8 +94,10 @@ class GCHR:
|
|
|
df[acct_info] = df["Konto_Nr_SKR51"].str.split(pat="-", n=6, expand=True)
|
|
|
return df
|
|
|
|
|
|
- def export_all_periods(self, overwrite=False):
|
|
|
+ def export_all_periods(self, overwrite=False, today=None):
|
|
|
dt = datetime.now()
|
|
|
+ if today is not None:
|
|
|
+ dt = datetime.fromisoformat(today)
|
|
|
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)
|
|
@@ -118,8 +122,10 @@ class GCHR:
|
|
|
|
|
|
|
|
|
df_bookings = self.load_bookings_from_file()
|
|
|
+ all_periods = set(df_bookings["Bookkeep Period"].to_list())
|
|
|
+ bookkeep_period_date = datetime(int(year), int(month), 28)
|
|
|
|
|
|
- if df_bookings.shape[0] == 0 or len(set(df_bookings["Bookkeep Period"].to_list())) <= 1:
|
|
|
+ if df_bookings.shape[0] == 0 or len(all_periods) <= 1 or self.booking_date < bookkeep_period_date:
|
|
|
logging.error("ABBRUCH!!! Keine Daten vorhanden!")
|
|
|
return False
|
|
|
|
|
@@ -336,6 +342,8 @@ class GCHR:
|
|
|
|
|
|
def load_bookings_from_file(self):
|
|
|
df2 = []
|
|
|
+ timestamps = []
|
|
|
+
|
|
|
for csv_file in self.account_bookings:
|
|
|
df2.append(
|
|
|
pd.read_csv(
|
|
@@ -346,7 +354,10 @@ class GCHR:
|
|
|
converters={0: str, 1: str},
|
|
|
)
|
|
|
)
|
|
|
+ timestamps.append(Path(csv_file).stat().st_mtime)
|
|
|
df_bookings = pd.concat(df2)
|
|
|
+ self.booking_date = datetime.fromtimestamp(max(timestamps))
|
|
|
+
|
|
|
|
|
|
filter_from = self.current_year + self.first_month_of_financial_year
|
|
|
filter_prev = self.last_year + self.first_month_of_financial_year
|
|
@@ -483,7 +494,7 @@ def gchr_local(base_dir):
|
|
|
|
|
|
def gchr_export(base_dir):
|
|
|
gchr = GCHR(base_dir)
|
|
|
- gchr.export_all_periods(overwrite=True)
|
|
|
+ gchr.export_all_periods(overwrite=True, today="2022-08-01")
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|