Skip to content

Feat/invoice processing#10

Open
DanPace725 wants to merge 12 commits intomainfrom
feat/invoice-processing
Open

Feat/invoice processing#10
DanPace725 wants to merge 12 commits intomainfrom
feat/invoice-processing

Conversation

@DanPace725
Copy link
Copy Markdown
Owner

Test updates

google-labs-jules bot and others added 10 commits July 30, 2025 17:28
…roring the capabilities of your original Python script.

Here are the key changes I made:
- **Invoice Analysis**: I enabled the `document-processor` service to call the Azure "prebuilt-invoice" model to extract invoice details and line items.
- **Excel Generation**: The service can now generate multi-sheet Excel files for invoices, containing "Invoice Details" and "Line Items" sheets.
- **Multi-Page Aggregation**: I added a feature to aggregate line items from all pages of a multi-page invoice into a single Excel sheet.
- **UI Integration**: I updated the main application page to handle the new invoice processing and aggregation logic based on your settings.
- **Testing**: I also added unit tests for the new invoice analysis and Excel generation logic to the `document-processor.test.ts` file.

The existing purchase order processing functionality remains unchanged.
…nd Total fields were not being extracted correctly.

The root cause was that fields of type 'currency' were being treated as simple numbers, but the Azure SDK returns a complex object containing `amount` and `symbol` properties.

The `extractInvoiceData` function has been updated with a more robust `getFieldValue` helper that now correctly identifies 'currency' type fields and extracts the numerical `amount` from them. This ensures that `UnitPrice` and `Amount` on line items, as well as `SubTotal` and `InvoiceTotal` in the details, are parsed correctly.
… Excel file was blank for invoices.

The previous logic was too strict when checking for the existence of the line items array in the Azure API response. The condition has been updated to be more resilient, checking for the presence of the `.values` property and ensuring it is an array before attempting to process it.

This change ensures that line items are correctly extracted and populated in the final output.
The invoice processing logic is failing to extract line items. To diagnose this, I simplified the data extraction and Excel generation to dump the raw data returned by the Azure AI service directly into an Excel file.

- `extractInvoiceData` now returns the raw `fields` object.
- `generateExcelOutput` now creates two sheets, "Raw Details" and "Raw Line Items", to show the unprocessed data structure.

This will allow me to inspect the exact data being returned by the service to identify the root cause of the issue.
…ctly extracted, leading to missing data for Price and Total, and sometimes a completely blank "Line Items" sheet.

The root causes were identified after analyzing the raw API response:
1. Currency fields (`UnitPrice`, `Amount`, etc.) were being returned with their value as a JSON string, which required an extra parsing step.
2. The logic to find the line items array was too strict.
3. The quantity was sometimes being returned as `OrderQuantity` instead of `Quantity`.

The `extractInvoiceData` function has been rewritten to be more robust:
- It now correctly parses the nested JSON string for currency fields.
- It uses a more resilient method to locate the line items array.
- It checks for both `Quantity` and `OrderQuantity` to ensure the quantity is always extracted.

This also reverts the temporary debugging code that was previously committed.
…-for-field-kind

Handle invoice fields by kind and guard item extraction
…processor-tests

Update invoice test mocks and assertions
@vercel
Copy link
Copy Markdown

vercel bot commented Sep 17, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
docflow Ready Ready Preview Comment Sep 18, 2025 5:34pm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant