fixed some bugs, improved main

This commit is contained in:
Anton
2026-04-30 03:23:24 +02:00
parent 82daeffaf8
commit c5d823cfb4
2 changed files with 33 additions and 22 deletions

View File

@@ -26,25 +26,32 @@ class Forderung:
def __str__(self):
return f"Name{self.name}, Haben {self.haben}, Soll {self.soll}, Amount {self.amount},Verwendung {self.text}"
def printC(forderungen:dict):
for key,values in forderungen.items():
print(f"//////////////{key}/////////////////////////////")
for nkey,nvalues in values.items():
print(f" {nkey}, {nvalues}")
def print_to_file_lexware(forderungen:dict):
"""
print Forderungen to a file, that can be read by lexware according the following format:
"Belegdatum";"Buchungsdatum";"Buchungstext"; "Buchungsbetrag"; "Sollkonto";"Habenkonto";"Kostenstelle"
01.03.2025; 19.02.2026;2; "Miete Familienzimmer"; 357,08; 12161; 4107; 200
"Belegdatum";"Buchungstext"; "Buchungsbetrag"; "Sollkonto";"Habenkonto";"Kostenstelle"
01.03.2025; "Miete Familienzimmer"; 357,08; 12161; 4107; 200
"""
print('Start Drucken der Forderugen')
names = read_account_names(config.filename_debitoren)
#print(names)
#printC(forderungen)
for period, forderung in forderungen.items():
if forderung !={}:
filename = f"output/{period[0]}-{period[1]:02d}_Forderungen_Familienzimmer.csv"
print(f"\t ...{filename}")
with open(filename, "w",encoding="cp1252", newline="\r\c") as file:
with open(filename, "w",encoding="cp1252", newline="\r\n") as file:
file.write("\"Belegdatum\";\"Buchungstext\";\"Buchungsbetrag\";\"Sollkonto\";\"Habenkonto\";\"Kostenstelle\"\n")
for key in forderung:
f = forderung[key]
name = names[key]
file.write(f"01.{period[1]:02d}.{period[0]};\"{name} {f.text}\";{f.amount};{key};{f.haben};{f.kostenstelle}\n")
name = ' '.join(names[key[0]])
file.write(f"01.{period[1]:02d}.{period[0]};\"{name} {f.text}\";{f.amount};{f.soll};{f.haben};{f.kostenstelle}\n")
print("Fertig mit Drucken der Forderungen.")
def create_forderungen(forderungen:dict, period:tuple, id_subject:tuple, belegdatum:str, amount:float, soll:int|None, haben:str, kostenstelle:str)->dict:
@@ -119,14 +126,15 @@ def create_forderungen_familienzimmer(filename:str, accounts:dict, forderungen:d
"""
print(f"Start Einlesen der Buchungen des Familienźimmers von {filename}")
priceFamilyRooms = readPriceFamilyRooms(config.filname_price_familyroom)
counter = 0
counter_recievables = 0
counter_errors = 0
try:
with open(filename, "r") as file:
reader = csv.DictReader(file)
for row in reader:
name = row["Created by"]
name = getWords(name)
id_subject = (getID(accounts, name[1:]), "Familienzimmer")
id_subject = (getID(accounts, name), "Familienzimmer")
month = getMonth(row["End time"].split(" ")[2])
year = row["End time"].split(" ")[3]
@@ -136,15 +144,16 @@ def create_forderungen_familienzimmer(filename:str, accounts:dict, forderungen:d
duration = getDuration(row["Duration"])
number_person = getNumberPerson(row["Number of guests"])
price = getPrice(room, priceFamilyRooms, duration, number_person)
#print(f"{name[1]} {id_subject} {room} dauer {duration} Tage, personen {number_person} preis {price}")
#print(f"{counter_recievables} \n{name[1]} {id_subject} {room} dauer {duration} Tage, personen {number_person} preis {price}")
datum = f"01.{period[1]:02d}.{period[0]}"
create_forderungen(forderungen,period,id_subject,datum,
price,id_subject[0],KN_HABEN_MIETE_FZ,KOSTENSTELLE_FZ)
counter+=1
counter_recievables+=1
else:
counter_errors+=1
print(f"Fehler, Name nicht gefunden\n\t{row}")
print(f"Fertig mit Erstellen von {counter} Forderungen")
print(f"Fertig mit Erstellen von {counter_recievables} Forderungen, {counter_errors}")
except IOError:
print(f"Fehler, Datei {filename} nicht gefunden.")
return forderungen
@@ -170,9 +179,11 @@ def getWords(sentence:str)->list:
for c in sentence:
if ord("a")<= ord(c) <= ord("z") or ord("A")<= ord(c) <= ord("Z") or ord("0")<= ord(c) <= ord("9"):
word = word + c
elif len(word)>0:
elif len(word)>2:
result.append(word)
word = ""
else:
word = ""
if len(word)>0:
result.append(word)
return result
@@ -267,7 +278,7 @@ def read_account_ids(filename:str)->dict:
def read_account_names(filename:str)->dict:
"""
Create a dictionary from account id to name
Create a dictionary: account id -> name
"""
print(f"Start Einlesen der Kontonummern und Namen \"{filename}\" ")
try: