Skip to content

feat: bulk import validation & preview improvements (#115)#654

Open
sungdark wants to merge 1 commit intorohitdash08:mainfrom
sungdark:feat/bulk-import-validation-preview
Open

feat: bulk import validation & preview improvements (#115)#654
sungdark wants to merge 1 commit intorohitdash08:mainfrom
sungdark:feat/bulk-import-validation-preview

Conversation

@sungdark
Copy link
Copy Markdown

Summary

Implements per-row validation with warnings and auto-corrections for the bulk import preview endpoint, closing issue #115.

What was built

Backend — expense_import.py (+248 lines)

  • `validate_import_rows()` — validates a list of normalized transaction rows
  • `RowValidationResult` dataclass: row_index, is_valid, has_errors, warnings, corrections, original
  • `BulkImportValidationResult` dataclass: totals + per-row results + corrected preview
  • Validation checks per row:
    • Date: invalid/missing = error; future date = error in strict mode, warning otherwise; very old (< 1990) = warning
    • Amount: missing/invalid = error; zero = warning (error in strict mode); negative → auto-corrected to abs(); > 100k = large-amount warning
    • Description: missing/empty → auto-corrected to "Unknown" with warning
    • Currency: missing → auto-corrected to "USD" with warning
    • expense_type: unknown → auto-corrected to "EXPENSE" with warning

Backend — expenses.py (preview endpoint enhanced)

  • `POST /expenses/import/preview` now returns:
    • `valid_rows`, `warning_rows`, `error_rows`, `ready_to_import`
    • `row_validations`: per-row list of {row_index, is_valid, has_errors, warnings, corrections}
    • Duplicate detection results merged into row warnings
    • Auto-corrections applied to the `transactions` list in the response
  • New query param `?strict=true` to treat warnings as blocking errors

Tests — test_expenses.py (+408 lines)

  • 15 unit tests for the validation service (all passing)
  • 12 integration tests for the enhanced /import/preview endpoint

PR Claim

/claim #115

…08#115)

Implement per-row validation with warnings and auto-corrections for the
bulk import preview endpoint (issue rohitdash08#115).

Changes:
- Add validate_import_rows() to expense_import.py with detailed
  per-row validation for dates, amounts, descriptions, currency, and
  expense_type
- New RowValidationResult and BulkImportValidationResult dataclasses
  for structured validation output
- /expenses/import/preview now returns: valid_rows, warning_rows,
  error_rows, ready_to_import, row_validations with per-row
  warnings, corrections, and error flags
- Auto-corrections applied: missing description→Unknown, missing
  currency→USD, unknown expense_type→EXPENSE, negative amounts→abs()
- strict query param: zero amounts and future dates become errors
- Duplicate detection integrated into row_validations
- 15 new unit tests covering all validation scenarios
@sungdark
Copy link
Copy Markdown
Author

/claim #115

Implementation Summary

What was built

Backend — `expense_import.py` (+248 lines)

  • `validate_import_rows()` validates a list of normalized transaction rows
  • Per-row checks: date validity, amount validity, zero-amount, future/old dates, large amounts, missing description/currency, unknown expense_type
  • Auto-corrections: missing description → "Unknown", missing currency → "USD", unknown expense_type → "EXPENSE", negative amounts → abs()

Backend — `expenses.py` (preview endpoint enhanced)

  • `POST /expenses/import/preview` now returns:
    • `valid_rows`, `warning_rows`, `error_rows`, `ready_to_import`
    • `row_validations`: list of {row_index, is_valid, has_errors, warnings, corrections}
    • Auto-corrections applied to `transactions` list
    • `?strict=true` treats zero amounts and future dates as errors

Tests (+408 lines)

  • 15 unit tests for validation service — all passing
  • 12 integration tests for enhanced preview endpoint

/close #115

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant