the Changes are fixing a problem in the invoice creation
This commit is contained in:
+19
-2
@@ -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', '')
|
||||
|
||||
Reference in New Issue
Block a user