Tabelle anpassen
This commit is contained in:
parent
2ee620a836
commit
947b412441
26
main.py
26
main.py
|
|
@ -10,6 +10,12 @@ import fitz
|
||||||
import requests
|
import requests
|
||||||
from pydantic import BaseModel, Field
|
from pydantic import BaseModel, Field
|
||||||
|
|
||||||
|
# ==========================================
|
||||||
|
# 0. SITZUNGS-STATUS INITIALISIEREN (ZÄHLER GEGEN WIDGET-CACHING)
|
||||||
|
# ==========================================
|
||||||
|
if "invoice_counter" not in st.session_state:
|
||||||
|
st.session_state.invoice_counter = 0
|
||||||
|
|
||||||
# ==========================================
|
# ==========================================
|
||||||
# 1. API-CLIENT FÜR EXTERNE BACKENDS (vLLM / Ollama)
|
# 1. API-CLIENT FÜR EXTERNE BACKENDS (vLLM / Ollama)
|
||||||
# ==========================================
|
# ==========================================
|
||||||
|
|
@ -445,6 +451,9 @@ with col2:
|
||||||
final_data["recipient_email"] = ""
|
final_data["recipient_email"] = ""
|
||||||
|
|
||||||
final_data["items"] = extract_invoice_items_pure_python(pdf_text)
|
final_data["items"] = extract_invoice_items_pure_python(pdf_text)
|
||||||
|
|
||||||
|
# 🔥 REPARATUR: Erhöhe den Zähler, um Streamlits Widget-Cache für die neue Rechnung komplett zu wipen
|
||||||
|
st.session_state.invoice_counter += 1
|
||||||
st.session_state.extracted_data = final_data
|
st.session_state.extracted_data = final_data
|
||||||
|
|
||||||
if st.session_state.extracted_data:
|
if st.session_state.extracted_data:
|
||||||
|
|
@ -511,33 +520,36 @@ with col2:
|
||||||
|
|
||||||
edited_items = []
|
edited_items = []
|
||||||
|
|
||||||
|
# Hole den aktuellen Rechnungs-ID-Zustand für die Widget-Keys
|
||||||
|
inv_id = st.session_state.invoice_counter
|
||||||
|
|
||||||
for idx, item in enumerate(data.get("items", [])):
|
for idx, item in enumerate(data.get("items", [])):
|
||||||
|
# 🔥 REPARATUR: Alle Keys sind jetzt an die 'inv_id' gekoppelt. Neue Rechnung = Neue Keys = Frische Daten!
|
||||||
with st.expander(f"📋 Position {idx+1}: {item.get('name', 'Dienstleistung')}", expanded=True):
|
with st.expander(f"📋 Position {idx+1}: {item.get('name', 'Dienstleistung')}", expanded=True):
|
||||||
|
|
||||||
c_del, _ = st.columns([1, 4])
|
c_del, _ = st.columns([1, 4])
|
||||||
with c_del:
|
with c_del:
|
||||||
if st.button("🗑️ Position löschen", key=f"del_btn_{idx}"):
|
if st.button("🗑️ Position löschen", key=f"del_btn_{inv_id}_{idx}"):
|
||||||
data["items"].pop(idx)
|
data["items"].pop(idx)
|
||||||
st.rerun()
|
st.rerun()
|
||||||
|
|
||||||
c_name, c_desc = st.columns([1, 1])
|
c_name, c_desc = st.columns([1, 1])
|
||||||
with c_name:
|
with c_name:
|
||||||
item_name = st.text_input("Artikelname (BT-153)", value=item.get("name", ""), key=f"item_name_{idx}")
|
item_name = st.text_input("Artikelname (BT-153)", value=item.get("name", ""), key=f"item_name_{inv_id}_{idx}")
|
||||||
with c_desc:
|
with c_desc:
|
||||||
desc_text = item.get("description", "")
|
desc_text = item.get("description", "")
|
||||||
estimated_lines = desc_text.count("\n") + (len(desc_text) // 45) + 1
|
estimated_lines = desc_text.count("\n") + (len(desc_text) // 45) + 1
|
||||||
calc_height = max(68, min(400, estimated_lines * 24))
|
calc_height = max(68, min(400, estimated_lines * 24))
|
||||||
|
|
||||||
item_description = st.text_area("Zusatzbeschreibung (BT-154)", value=desc_text, key=f"item_desc_{idx}", height=calc_height)
|
item_description = st.text_area("Zusatzbeschreibung (BT-154)", value=desc_text, key=f"item_desc_{inv_id}_{idx}", height=calc_height)
|
||||||
|
|
||||||
c_qty, c_unit, c_price, c_total = st.columns(4)
|
c_qty, c_unit, c_price, c_total = st.columns(4)
|
||||||
with c_qty:
|
with c_qty:
|
||||||
# 🔥 REPARATUR: 'step=0.1' hinzugefügt, damit die + / - Tasten exakt um 0.1 springen
|
item_quantity = st.number_input("Menge", value=float(item.get("quantity") or 0.0), format="%.1f", step=0.1, key=f"item_qty_{inv_id}_{idx}")
|
||||||
item_quantity = st.number_input("Menge", value=float(item.get("quantity") or 0.0), format="%.1f", step=0.1, key=f"item_qty_{idx}")
|
|
||||||
with c_unit:
|
with c_unit:
|
||||||
item_unit = st.text_input("Einheit", value=item.get("unit", "Stk."), key=f"item_unit_{idx}")
|
item_unit = st.text_input("Einheit", value=item.get("unit", "Stk."), key=f"item_unit_{inv_id}_{idx}")
|
||||||
with c_price:
|
with c_price:
|
||||||
item_price = st.number_input("Einzelpreis (€)", value=float(item.get("unit_price") or 0.0), format="%.2f", key=f"item_price_{idx}")
|
item_price = st.number_input("Einzelpreis (€)", value=float(item.get("unit_price") or 0.0), format="%.2f", key=f"item_price_{inv_id}_{idx}")
|
||||||
with c_total:
|
with c_total:
|
||||||
raw_item_total = item_quantity * item_price
|
raw_item_total = item_quantity * item_price
|
||||||
item_total_amount = kaufmaennisches_runden(raw_item_total)
|
item_total_amount = kaufmaennisches_runden(raw_item_total)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue