Skip to content

fix: update header_results with corrected opening balance - #216

Merged
boscorat merged 2 commits into
masterfrom
215-bug-halifax-gap-reporting-false-positives
Sep 15, 2026
Merged

boscorat merged 2 commits into
masterfrom
215-bug-halifax-gap-reporting-false-positives

Conversation

@boscorat

Copy link
Copy Markdown
Owner

Summary

_apply_opening_balance_correction() in statements.py correctly updated checks_and_balances, lines_results, and the scalar std_opening_balance — but did not update header_results. Since StatementHeads reads STD_OPENING_BALANCE from header_results to write to parquet/SQLite, the corrected opening balance never reached the database.

This caused the GapReport VIEW to compare the uncorrected (wrong) opening balance against the previous statement's closing balance, producing false GAP flags for Halifax current account statements.

Changes

  • statements.py: Update header_results with corrected STD_OPENING_BALANCE in _apply_opening_balance_correction(). Remove redundant scalar assignment (it's derived from header_results at line 560). Add diagnostic print on correction.
  • test_opening_balance_correction.py: Add test_correction_updates_header_results. Add header_results to test helper. Update existing tests to derive scalar from header_results post-correction.

Closes

Closes #215

_apply_opening_balance_correction() corrected checks_and_balances,
lines_results, and the scalar, but did not update header_results.
This caused the corrected opening balance to never reach parquet/SQLite,
leading to false GAP flags in the GapReport VIEW.

Changes:
- Update header_results with corrected STD_OPENING_BALANCE
- Remove redundant scalar assignment (derived from header_results at
  line 560 anyway)
- Add diagnostic print on correction
- Add test_correction_updates_header_results
- Update existing tests to derive scalar from header_results

Closes #215

Signed-off-by: Jason Farrar <stillwaters.technology@gmail.com>
@boscorat boscorat added the bug Something isn't working label Sep 15, 2026
@boscorat boscorat linked an issue Sep 15, 2026 that may be closed by this pull request
@boscorat boscorat self-assigned this Sep 15, 2026
@boscorat
boscorat requested a lite review from Copilot September 15, 2026 16:09

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The fix is narrowly scoped to the persistence pathway for corrected opening balances and is backed by targeted tests, with only minor non-blocking nits identified.

Pull request overview

This PR fixes an end-to-end data propagation bug where _apply_opening_balance_correction() corrected the opening balance in internal validation/line results but did not update header_results, so StatementHeads persisted the wrong STD_OPENING_BALANCE to Parquet/SQLite and caused false GAP flags (notably for Halifax statements).

Changes:

  • Update _apply_opening_balance_correction() to overwrite header_results.STD_OPENING_BALANCE so downstream persistence uses the corrected value.
  • Remove the redundant std_opening_balance scalar assignment (since it is derived from header_results later in Statement.__init__).
  • Add/extend tests to ensure header_results and the derived scalar reflect the corrected opening balance.
File summaries
File Description
src/bank_statement_parser/modules/statements.py Persist corrected opening balance into header_results so StatementHeads writes the corrected value to Parquet/SQLite; add a diagnostic print.
tests/test_opening_balance_correction.py Extend helper and add a test to verify the correction updates header_results, and adjust scalar expectations to derive from header_results.
Review details

Suppressed comments (1)

tests/test_opening_balance_correction.py:185

  • This test comment references an exact line number in Statement.__init__ ("line 560"), which will drift as the file changes and becomes misleading. Prefer describing the behavior without hard-coding line numbers.
        # Simulate Statement.__init__ line 560: scalar derived from header_results
  • Files reviewed: 2/2 changed files
  • Comments generated: 2
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/bank_statement_parser/modules/statements.py
Comment thread tests/test_opening_balance_correction.py Outdated
Addresses PR review feedback: remove line-number reference that will
drift, replace with behavioral description.

Signed-off-by: Jason Farrar <stillwaters.technology@gmail.com>
@boscorat
boscorat merged commit 19c0f46 into master Sep 15, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: Halifax GAP reporting false positives

2 participants