diff --git a/backend/mail.py b/backend/mail.py index 9b27213..9c96bbc 100644 --- a/backend/mail.py +++ b/backend/mail.py @@ -14,9 +14,10 @@ def send_checkout_mails(user_infos): } """ for username, info in user_infos.items(): + mail=username if "@" in username else f"{username}@{util.mail_postfix}" # do for all send_checkout_mail(info["name"], info["balance"], - info["income"], info["paid"], f"{username}@{util.mail_postfix}") + info["income"], info["paid"], mail) def compile_latex(name): @@ -118,9 +119,12 @@ def send_checkout_mail(name, current_balance, income, paid, mail_address): raw_latex_file = raw_latex_file.replace("??income-table??", income_table) raw_latex_file = raw_latex_file.replace("??paid-table??", paid_table) - with open('Latex/checkout.tex', "w") as writer: + filename="checkout" + + with open(f'Latex/{filename}.tex', "w") as writer: writer.write(raw_latex_file) + + compile_latex(filename) - compile_latex("checkout") - send_mail_with_attachment("Getränkelisten Abrechnung", mail_address, "Latex/checkout.pdf", - "Abrechnung.pdf", util.checkout_mail_text.format(name=name, balance=format_float(current_balance))) + send_mail_with_attachment("Getränkelisten Abrechnung", mail_address, f"Latex/{filename}.pdf", + "Abrechnung.pdf", util.checkout_mail_text.format(name=name, balance=format_float(current_balance))) diff --git a/backend/main.py b/backend/main.py index 21ace2f..2f97cb3 100644 --- a/backend/main.py +++ b/backend/main.py @@ -522,8 +522,9 @@ def put(self): """ db.do_checkout(request.json) mail_infos = db.get_checkout_mail() - mail.send_checkout_mails(mail_infos) - return util.build_response() + if util.mail_server is not None: + mail.send_checkout_mails(mail_infos) + return util.build_response("") @admin def get(self): @@ -690,7 +691,7 @@ def post(self): if __name__ == "__main__": if util.logging_enabled: - app.run("0.0.0.0", threaded=True) + app.run("0.0.0.0", threaded=True, debug=True) else: from waitress import serve serve(app, host="0.0.0.0", port=5000, threads=4)