Repository navigation
fix(imports): persist the statement's amount sign convention - #14
Merged
Merged
Conversation
`PATCH /imports/{id}` accepted `amount_sign` and applied it to the candidate
rows, then threw the answer away. Nothing recorded it and nothing returned it,
which broke the feature in two directions.
The browser was the visible half. `renderSignSelector` restores the selector
from `batch.amount_sign`, a field the API never sent, so the guard could never
fire: any re-render of the preview reset the control to unanswered and re-blocked
commit, even though the directions on screen were already correct. The user had
to re-answer a question they had answered, with no way to tell from the page
which convention the rows in front of them were actually read under.
The other half is provenance. A committed batch drops its staged rows and keeps
only the counts and the committed transaction ids as its receipt. If a
credit-card export was booked the wrong way round - every purchase filed as
income - there was nothing on the batch to say which convention produced it, so
an audit had to guess from the resulting signs.
The column is nullable: batches created before this migration, and any batch
whose owner never stated a convention, genuinely have no answer, and `as_written`
is the default behaviour rather than a recorded choice.
The stored convention is now also re-applied on every later patch, not only on
the patch that set it. Directions do survive in the candidate blob today, but
only because `validate()` skips rows whose amount it has already parsed - a
coupling nothing states and nothing tests. Re-applying makes the persisted value
the authority. `_apply_amount_sign` re-derives direction from the raw amount text
instead of flipping a sign, so repeating it is free; the call stays between
`validate()` (which sets direction) and `resolve_duplicates()` (whose fingerprint
covers the signed amount).
Gate: ruff, ruff format, mypy, 103 tests. Migration verified on a fresh database
through `pfa db migrate`, which honours PFA_DATABASE_URL where a direct alembic
invocation does not.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RYgbBDgmuiRTGt5QNo6313
fix(imports): persist the statement's amount sign convention
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Forwards PR #12 into
main.#12 was merged into
fix/phase-0-ui-honest(its stacked base) rather thanmain, because #11 was merged without deleting its branch, so GitHub never retargeted it. The commits are identical and already reviewed in #12; this just carries them the last hop.Contents:
amount_signcolumn onImportBatchModel, migration0003_batch_amount_sign, persistence and sticky re-application inapply_patch, and the field onImportBatchResponse— which is what makes the preview UI's sign-convention selector survive a refresh, and gives a committed batch a record of how it read its amounts.Gate on this branch: ruff, ruff format, mypy, 103 tests passing.
🤖 Generated with Claude Code
https://claude.ai/code/session_01RYgbBDgmuiRTGt5QNo6313