Update src/streamlit_app.py
Browse files453 unmodified lines4544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874887 unmodified lines4964974984995005015025035045055065075085095105115125135145155165175185195205215225235242 unmodified lines527528529530531532533453 unmodified lines"""Converts nested invoice data into a flat list of rows (one per line item),with invoice-level and sender/recipient/bank fields repeated in each row."""rows = []line_items = invoice_data.get("Itemized Data", [])if not line_items:# If no line items, create one row with invoice info onlyrow = {"Invoice Number": invoice_data.get("Invoice Number", ""),"Invoice Date": invoice_data.get("Invoice Date", ""),"Due Date": invoice_data.get("Due Date", ""),"Currency": invoice_data.get("Currency", ""),"Subtotal": invoice_data.get("Subtotal", 0.0),"Tax Percentage": invoice_data.get("Tax Percentage", 0.0),"Total Tax": invoice_data.get("Total Tax", 0.0),"Total Amount": invoice_data.get("Total Amount", 0.0),"Sender Name": invoice_data.get("Sender", {}).get("Name", ""),"Sender Address": invoice_data.get("Sender", {}).get("Address", ""),"Recipient Name": invoice_data.get("Recipient", {}).get("Name", ""),"Recipient Address": invoice_data.get("Recipient", {}).get("Address", ""),}# Flatten bank detailsbank = invoice_data.get("Bank Details", {})for k, v in bank.items():# Avoid double-prefixing if key already contains 'bank_'key_name = k if str(k).startswith("bank_") else f"bank_{k}"row[key_name] = v# Add empty line item fieldsrow.update({"Item Description": "","Item Quantity": 0,7 unmodified lines# For each line item, create a row with all invoice contextfor item in line_items:row = {"Invoice Number": invoice_data.get("Invoice Number", ""),"Invoice Date": invoice_data.get("Invoice Date", ""),"Due Date": invoice_data.get("Due Date", ""),"Currency": invoice_data.get("Currency", ""),"Subtotal": invoice_data.get("Subtotal", 0.0),"Tax Percentage": invoice_data.get("Tax Percentage", 0.0),"Total Tax": invoice_data.get("Total Tax", 0.0),"Total Amount": invoice_data.get("Total Amount", 0.0),"Sender Name": invoice_data.get("Sender", {}).get("Name", ""),"Sender Address": invoice_data.get("Sender", {}).get("Address", ""),"Recipient Name": invoice_data.get("Recipient", {}).get("Name", ""),"Recipient Address": invoice_data.get("Recipient", {}).get("Address", ""),}# Flatten bank detailsbank = invoice_data.get("Bank Details", {})for k, v in bank.items():# Avoid double-prefixing if key already contains 'bank_'key_name = k if str(k).startswith("bank_") else f"bank_{k}"row[key_name] = v# Add line item fieldsrow.update({"Item Description": item.get("Description", ""),"Item Quantity": item.get("Quantity", 0),2 unmodified lines"Item Tax": item.get("Tax", 0.0),"Item Line Total": item.get("Line Total", item.get("Amount", 0.0)),})rows.append(row)return rows453 unmodified lines4544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055067 unmodified lines5145155165175185195202 unmodified lines523524525526527528453 unmodified lines"""Converts nested invoice data into a flat list of rows (one per line item),with invoice-level and sender/recipient/bank fields repeated in each row.Ensures all expected bank fields are present, even if empty."""# Define all expected bank fields (must match UI keys)EXPECTED_BANK_FIELDS = ["bank_name","bank_account_number","bank_acc_name","bank_iban","bank_swift","bank_routing","bank_branch"]rows = []line_items = invoice_data.get("Itemized Data", [])# Prepare base invoice infobase_row = {"Invoice Number": invoice_data.get("Invoice Number", ""),"Invoice Date": invoice_data.get("Invoice Date", ""),"Due Date": invoice_data.get("Due Date", ""),"Currency": invoice_data.get("Currency", ""),"Subtotal": invoice_data.get("Subtotal", 0.0),"Tax Percentage": invoice_data.get("Tax Percentage", 0.0),"Total Tax": invoice_data.get("Total Tax", 0.0),"Total Amount": invoice_data.get("Total Amount", 0.0),"Sender Name": invoice_data.get("Sender", {}).get("Name", ""),"Sender Address": invoice_data.get("Sender", {}).get("Address", ""),"Recipient Name": invoice_data.get("Recipient", {}).get("Name", ""),"Recipient Address": invoice_data.get("Recipient", {}).get("Address", ""),}# Initialize all expected bank fields to empty stringbank_row = {field: "" for field in EXPECTED_BANK_FIELDS}# Override with actual values if presentbank_details = invoice_data.get("Bank Details", {}) or {}for k, v in bank_details.items():key_name = k if str(k).startswith("bank_") else f"bank_{k}"if key_name in bank_row:bank_row[key_name] = str(v).strip() if v is not None else ""base_row.update(bank_row)if not line_items:# If no line items, create one row with invoice info onlyrow = base_row.copy()row.update({"Item Description": "","Item Quantity": 0,7 unmodified lines# For each line item, create a row with all invoice contextfor item in line_items:row = base_row.copy()row.update({"Item Description": item.get("Description", ""),"Item Quantity": item.get("Quantity", 0),2 unmodified lines"Item Tax": item.get("Tax", 0.0),"Item Line Total": item.get("Line Total", item.get("Amount", 0.0)),})rows.append(row)return rows
src/streamlit_app.py+42-47