Tabelle anpassen

This commit is contained in:
dfuhrmann3 2026-07-03 10:09:30 +02:00
parent 4a6d265a7d
commit 0c5dbf5d92
1 changed files with 61 additions and 61 deletions

122
main.py
View File

@ -320,7 +320,7 @@ def generate_compliant_xrechnung(data):
ET.SubElement(monetary_total, f"{{{CBC}}}TaxInclusiveAmount", {"currencyID": "EUR"}).text = f"{data['total_gross_amount']:.2f}" ET.SubElement(monetary_total, f"{{{CBC}}}TaxInclusiveAmount", {"currencyID": "EUR"}).text = f"{data['total_gross_amount']:.2f}"
ET.SubElement(monetary_total, f"{{{CBC}}}PayableAmount", {"currencyID": "EUR"}).text = f"{data['total_gross_amount']:.2f}" ET.SubElement(monetary_total, f"{{{CBC}}}PayableAmount", {"currencyID": "EUR"}).text = f"{data['total_gross_amount']:.2f}"
# --- POSITIONEN SCHLEIFE (UMGEBAUT FÜR BT-153 & BT-154) --- # --- POSITIONEN SCHLEIFE ---
for index, item in enumerate(data["items"], start=1): for index, item in enumerate(data["items"], start=1):
line = ET.SubElement(root, f"{{{CAC}}}InvoiceLine") line = ET.SubElement(root, f"{{{CAC}}}InvoiceLine")
ET.SubElement(line, f"{{{CBC}}}ID").text = str(index) ET.SubElement(line, f"{{{CBC}}}ID").text = str(index)
@ -335,10 +335,10 @@ def generate_compliant_xrechnung(data):
item_elem = ET.SubElement(line, f"{{{CAC}}}Item") item_elem = ET.SubElement(line, f"{{{CAC}}}Item")
# BT-153: Der prägnante Name der Dienstleistung/Ware (Erste Zeile) # BT-153: Der prägnante Name der Dienstleistung/Ware
ET.SubElement(item_elem, f"{{{CBC}}}Name").text = str(item.get("name", "Dienstleistung")) ET.SubElement(item_elem, f"{{{CBC}}}Name").text = str(item.get("name", "Dienstleistung"))
# BT-154: Die detaillierte Zusatzbeschreibung (Seriennummern, Laufzeiten etc., falls vorhanden) # BT-154: Die detaillierte Zusatzbeschreibung
if item.get("description") and str(item["description"]).strip() != "": if item.get("description") and str(item["description"]).strip() != "":
ET.SubElement(item_elem, f"{{{CBC}}}Description").text = str(item["description"]).strip() ET.SubElement(item_elem, f"{{{CBC}}}Description").text = str(item["description"]).strip()
@ -508,65 +508,65 @@ with col2:
r_street = st.text_input("Straße (Kunde)", value=data.get("recipient_street", "")) r_street = st.text_input("Straße (Kunde)", value=data.get("recipient_street", ""))
r_zip = st.text_input("PLZ (Kunde)", value=data.get("recipient_zip", "")) r_zip = st.text_input("PLZ (Kunde)", value=data.get("recipient_zip", ""))
r_city = st.text_input("Stadt (Kunde)", value=data.get("recipient_city", "")) r_city = st.text_input("Stadt (Kunde)", value=data.get("recipient_city", ""))
st.markdown("**3. Positionen:**")
# Vorab-Berechnung der Zeilensummen für die UI-Spaltenkonfiguration (nutzt exakt deine Struktur!)
items_to_show = data.get("items", [])
for item in items_to_show:
if "total_amount" not in item:
raw_total = float(item.get("quantity") or 0.0) * float(item.get("unit_price") or 0.0)
item["total_amount"] = kaufmaennisches_runden(raw_total)
# 🔥 REPARATUR-UI: Nutzt exakt deine internen Dictionary-Keys ("name" und "description") # ==========================================
# Erzwingt die volle Breite und legt feste proportionale Spaltenbreiten fest, um das Scrollen zu verhindern. # 6. ENTKOPPELTES POSITIONEN FRONTEND (VOLLBREITE)
edited_items = st.data_editor( # ==========================================
items_to_show, # Wir verlassen hier die Spalten-Einschränkung (col2) komplett, damit die Tabelle 100% Breite bekommt.
num_rows="dynamic", if st.session_state.extracted_data:
use_container_width=True, # Füllt die volle Bildschirmbreite aus data = st.session_state.extracted_data
column_config={
"name": st.column_config.TextColumn("Artikelname (BT-153)", width="medium", required=True), st.markdown("### 3. Positionen")
"description": st.column_config.TextColumn("Zusatzbeschreibung (BT-154)", width="large"),
"quantity": st.column_config.NumberColumn("Menge", width="small", format="%.4f"), # 🔥 NEU: Volle Container-Breite und saubere Spaltenskalierung ohne horizontales Quetschen
"unit": st.column_config.TextColumn("Einheit", width="small"), edited_items = st.data_editor(
"unit_price": st.column_config.NumberColumn("Einzelpreis (€)", width="small", format="%.2f"), data.get("items", []),
"total_amount": st.column_config.NumberColumn("Gesamtbetrag (€)", width="small", format="%.2f", disabled=True) num_rows="dynamic",
} use_container_width=True, # Nutzt die komplette Bildschirmbreite (Wide-Layout)
) column_config={
vat_rate = st.number_input("Steuersatz (%)", value=float(data.get("vat_rate_percent") or 19.0)) "name": st.column_config.TextColumn("Artikelname (BT-153)", width="medium", required=True),
"description": st.column_config.TextColumn("Zusatzbeschreibung (BT-154)", width="large"),
"quantity": st.column_config.NumberColumn("Menge", width="small", format="%.4f"),
"unit": st.column_config.TextColumn("Einheit", width="small"),
"unit_price": st.column_config.NumberColumn("Einzelpreis (€)", width="small", format="%.2f"),
"total_amount": st.column_config.NumberColumn("Gesamtbetrag (€)", width="small", format="%.2f", disabled=True)
}
)
vat_rate = st.number_input("Steuersatz (%)", value=float(data.get("vat_rate_percent") or 19.0))
for item in edited_items:
raw_total = float(item.get("quantity") or 0.0) * float(item.get("unit_price") or 0.0)
item["total_amount"] = kaufmaennisches_runden(raw_total)
for item in edited_items: computed_net_amount = sum(item["total_amount"] for item in edited_items)
raw_total = float(item.get("quantity") or 0.0) * float(item.get("unit_price") or 0.0) raw_vat_amount = computed_net_amount * (vat_rate / 100.0)
item["total_amount"] = kaufmaennisches_runden(raw_total) computed_vat_amount = kaufmaennisches_runden(raw_vat_amount)
computed_gross_amount = kaufmaennisches_runden(computed_net_amount + computed_vat_amount)
computed_net_amount = sum(item["total_amount"] for item in edited_items)
raw_vat_amount = computed_net_amount * (vat_rate / 100.0) st.markdown("**Berechnete Summen:**")
computed_vat_amount = kaufmaennisches_runden(raw_vat_amount) c_net_ui, c_vat_ui, c_gross_ui = st.columns(3)
computed_gross_amount = kaufmaennisches_runden(computed_net_amount + computed_vat_amount) with c_net_ui: st.metric("Netto-Gesamt (€)", f"{computed_net_amount:.2f}")
with c_vat_ui: st.metric("MwSt-Gesamt (€)", f"{computed_vat_amount:.2f}")
st.markdown("**Berechnete Summen:**") with c_gross_ui: st.metric("Brutto-Zahlbetrag (€)", f"{computed_gross_amount:.2f}")
c_net_ui, c_vat_ui, c_gross_ui = st.columns(3)
with c_net_ui: st.metric("Netto-Gesamt (€)", f"{computed_net_amount:.2f}") st.markdown("---")
with c_vat_ui: st.metric("MwSt-Gesamt (€)", f"{computed_vat_amount:.2f}") if st.button("🔒 XRechnung exportieren", type="primary", width="stretch"):
with c_gross_ui: st.metric("Brutto-Zahlbetrag (€)", f"{computed_gross_amount:.2f}") final_invoice_dict = {
"invoice_type_code": selected_type_code,
st.markdown("---") "invoice_number": inv_num, "invoice_date": inv_date, "delivery_date": inv_delivery,
if st.button("🔒 XRechnung exportieren", type="primary", width="stretch"): "buyer_reference": buyer_ref, "recipient_name": r_name, "recipient_email": r_email,
final_invoice_dict = { "recipient_street": r_street, "recipient_zip": r_zip, "recipient_city": r_city,
"invoice_type_code": selected_type_code, "items": edited_items, "total_net_amount": computed_net_amount, "total_vat_amount": computed_vat_amount,
"invoice_number": inv_num, "invoice_date": inv_date, "delivery_date": inv_delivery, "vat_rate_percent": vat_rate, "total_gross_amount": computed_gross_amount, "iban": "DE06120700240456207000",
"buyer_reference": buyer_ref, "recipient_name": r_name, "recipient_email": r_email, "delivery_note_id": dn_id,
"recipient_street": r_street, "recipient_zip": r_zip, "recipient_city": r_city, "order_id": o_id,
"items": edited_items, "total_net_amount": computed_net_amount, "total_vat_amount": computed_vat_amount, "contract_id": c_id,
"vat_rate_percent": vat_rate, "total_gross_amount": computed_gross_amount, "iban": "DE06120700240456207000", "service_start_date": s_start,
"delivery_note_id": dn_id, "service_end_date": s_end,
"order_id": o_id, "invoice_note": i_note
"contract_id": c_id, }
"service_start_date": s_start, st.download_button(label="📥 Download XML", data=generate_compliant_xrechnung(final_invoice_dict), file_name=f"XRechnung_{inv_num}.xml", mime="text/xml")
"service_end_date": s_end,
"invoice_note": i_note
}
st.download_button(label="📥 Download XML", data=generate_compliant_xrechnung(final_invoice_dict), file_name=f"XRechnung_{inv_num}.xml", mime="text/xml")
# ========================================== # ==========================================
# DYNAMISCHER FOOTER # DYNAMISCHER FOOTER
@ -575,7 +575,7 @@ st.markdown("---")
st.caption( st.caption(
"📝 **Hinweise:**\n\n" "📝 **Hinweise:**\n\n"
"**Human-in-the-Loop:** " "**Human-in-the-Loop:** "
"Das Tool dient als Automations-Assistent. Vor dem finalen XML-Export ist eine visuelle Endkontrolle der extrahierten Daten " "Das Tool dient als Automation-Assistent. Vor dem finalen XML-Export ist eine visuelle Endkontrolle der extrahierten Daten "
"(insbesondere Rechnungsnummer und Empfängeradresse) durch den Sachbearbeiter zwingend erforderlich.\n\n" "(insbesondere Rechnungsnummer und Empfängeradresse) durch den Sachbearbeiter zwingend erforderlich.\n\n"
"**GoBD-Konformität:** " "**GoBD-Konformität:** "
"Das Tool generiert ausschließlich das strukturierte XML-Format. Für die Einhaltung der GoBD-Richtlinien " "Das Tool generiert ausschließlich das strukturierte XML-Format. Für die Einhaltung der GoBD-Richtlinien "