From 0c5dbf5d92b0aa6d15b6eedc7974903f5a571bd1 Mon Sep 17 00:00:00 2001 From: dfuhrmann3 Date: Fri, 3 Jul 2026 10:09:30 +0200 Subject: [PATCH] Tabelle anpassen --- main.py | 122 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 61 insertions(+), 61 deletions(-) diff --git a/main.py b/main.py index 6495950..eb52f51 100644 --- a/main.py +++ b/main.py @@ -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}}}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): line = ET.SubElement(root, f"{{{CAC}}}InvoiceLine") 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") - # 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")) - # BT-154: Die detaillierte Zusatzbeschreibung (Seriennummern, Laufzeiten etc., falls vorhanden) + # BT-154: Die detaillierte Zusatzbeschreibung if item.get("description") and 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_zip = st.text_input("PLZ (Kunde)", value=data.get("recipient_zip", "")) 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. - edited_items = st.data_editor( - items_to_show, - num_rows="dynamic", - use_container_width=True, # Füllt die volle Bildschirmbreite aus - column_config={ - "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)) +# ========================================== +# 6. ENTKOPPELTES POSITIONEN FRONTEND (VOLLBREITE) +# ========================================== +# Wir verlassen hier die Spalten-Einschränkung (col2) komplett, damit die Tabelle 100% Breite bekommt. +if st.session_state.extracted_data: + data = st.session_state.extracted_data + + st.markdown("### 3. Positionen") + + # 🔥 NEU: Volle Container-Breite und saubere Spaltenskalierung ohne horizontales Quetschen + edited_items = st.data_editor( + data.get("items", []), + num_rows="dynamic", + use_container_width=True, # Nutzt die komplette Bildschirmbreite (Wide-Layout) + column_config={ + "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: - raw_total = float(item.get("quantity") or 0.0) * float(item.get("unit_price") or 0.0) - item["total_amount"] = kaufmaennisches_runden(raw_total) - - computed_net_amount = sum(item["total_amount"] for item in edited_items) - raw_vat_amount = computed_net_amount * (vat_rate / 100.0) - computed_vat_amount = kaufmaennisches_runden(raw_vat_amount) - computed_gross_amount = kaufmaennisches_runden(computed_net_amount + computed_vat_amount) - - st.markdown("**Berechnete Summen:**") - 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}") - with c_vat_ui: st.metric("MwSt-Gesamt (€)", f"{computed_vat_amount:.2f}") - with c_gross_ui: st.metric("Brutto-Zahlbetrag (€)", f"{computed_gross_amount:.2f}") - - st.markdown("---") - if st.button("🔒 XRechnung exportieren", type="primary", width="stretch"): - final_invoice_dict = { - "invoice_type_code": selected_type_code, - "invoice_number": inv_num, "invoice_date": inv_date, "delivery_date": inv_delivery, - "buyer_reference": buyer_ref, "recipient_name": r_name, "recipient_email": r_email, - "recipient_street": r_street, "recipient_zip": r_zip, "recipient_city": r_city, - "items": edited_items, "total_net_amount": computed_net_amount, "total_vat_amount": computed_vat_amount, - "vat_rate_percent": vat_rate, "total_gross_amount": computed_gross_amount, "iban": "DE06120700240456207000", - "delivery_note_id": dn_id, - "order_id": o_id, - "contract_id": c_id, - "service_start_date": s_start, - "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") + computed_net_amount = sum(item["total_amount"] for item in edited_items) + raw_vat_amount = computed_net_amount * (vat_rate / 100.0) + computed_vat_amount = kaufmaennisches_runden(raw_vat_amount) + computed_gross_amount = kaufmaennisches_runden(computed_net_amount + computed_vat_amount) + + st.markdown("**Berechnete Summen:**") + 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}") + with c_vat_ui: st.metric("MwSt-Gesamt (€)", f"{computed_vat_amount:.2f}") + with c_gross_ui: st.metric("Brutto-Zahlbetrag (€)", f"{computed_gross_amount:.2f}") + + st.markdown("---") + if st.button("🔒 XRechnung exportieren", type="primary", width="stretch"): + final_invoice_dict = { + "invoice_type_code": selected_type_code, + "invoice_number": inv_num, "invoice_date": inv_date, "delivery_date": inv_delivery, + "buyer_reference": buyer_ref, "recipient_name": r_name, "recipient_email": r_email, + "recipient_street": r_street, "recipient_zip": r_zip, "recipient_city": r_city, + "items": edited_items, "total_net_amount": computed_net_amount, "total_vat_amount": computed_vat_amount, + "vat_rate_percent": vat_rate, "total_gross_amount": computed_gross_amount, "iban": "DE06120700240456207000", + "delivery_note_id": dn_id, + "order_id": o_id, + "contract_id": c_id, + "service_start_date": s_start, + "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 @@ -575,7 +575,7 @@ st.markdown("---") st.caption( "📝 **Hinweise:**\n\n" "**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" "**GoBD-Konformität:** " "Das Tool generiert ausschließlich das strukturierte XML-Format. Für die Einhaltung der GoBD-Richtlinien "