From d6ecf419eaa975c6d6251ea6a21d08b10d6c016a Mon Sep 17 00:00:00 2001 From: Aiirondev Date: Sat, 25 Jul 2026 22:39:01 +0200 Subject: [PATCH] the Changes are fixing a problem in the invoice creation --- Web/app.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/Web/app.py b/Web/app.py index d90bd41..43a9979 100755 --- a/Web/app.py +++ b/Web/app.py @@ -8623,10 +8623,27 @@ def admin_create_invoice(borrow_id): client = MongoClient(cfg.MONGODB_HOST, cfg.MONGODB_PORT) db = client[cfg.MONGODB_DB] student_cards = db['student_cards'] - card = student_cards.find_one({'_id': ObjectId(borrow_id)}) + + student_id = borrow_doc.get('AusweisId') + + if not student_id: + client.close() + flash('Dieser Ausleihe ist kein Schülerausweis zugeordnet.', 'error') + return redirect(url_for('admin_borrowings')) + + # 2. Mit der korrekten ID in student_cards suchen + card = student_cards.find_one({'_id': ObjectId(student_id)}) + + if not card: + client.close() + flash('Der zugehörige Schülerausweis wurde in der Datenbank nicht gefunden.', 'error') + return redirect(url_for('admin_borrowings')) + card = _decrypt_student_card_doc(card) client.close() - borrower = card['SchülerName'] + + # 3. Sicherer Zugriff mit .get() als zusätzliche Schutzmaßnahme + borrower = card.get('SchülerName', 'Unbekannt') invoice_number = existing_invoice.get('invoice_number') or _build_invoice_number(borrow_doc['_id'], now) item_name = item_doc.get('Name', '')