01Layer algebra has no home
rendering_service.py:177 (private) extract_plan.py:41 databook.py:45 |
The reported→mgmt→bdo cumulation rule is written three times. Two copies
carry docstrings admitting they mirror a private function. A fourth layer means
finding and editing all three. |
Promote the private function to a module. A
services/layer_algebra.py owning the layer vocabulary, returning a
LayerExpansion value object. Re-express kind_buckets and
_KIND_TARGET as thin projections, then delete both "mirrors…" comments.
≈ half a day. One table test replaces coverage across three suites. |
Strong |
02BS-movement rule copied as SQL
rendering_service.py:741, :970 queries.py:517, :546 routes/adjustments.py:212 |
Five hand-written copies of one correctness-critical rule — "current sum −
prior sum, prior matched on period.kind". It produces the quality-of-earnings
figure a deal team signs off on, and the copies can silently drift apart. |
Give the rule one composable home. A
services/bs_movement.py exposing prior_period_id(...) and an
effective_amount_sql(line_alias, period_alias) fragment. Callers keep their own
SELECTs but stop re-typing the arithmetic.
Alternative worth weighing: a Postgres VIEW or generated column, which also
covers the CLI and any future reporting path. |
Strong |
03Domain logic living in a route
web/routes/adjustments.py 1,605 lines · 15 endpoints 20 private helpers |
Intercompany elimination, provenance drift, split logic and a formula grammar all sit behind
HTTP handlers — so the only way to exercise them is to POST a form. Largest file in
src/, and still growing. |
Extract a read model; leave transport behind. One
build_adjustments_view(...) returning the page's whole view state as a typed
value. Move _parse_cell_formula into the amount_expr module it
duplicates. Handlers shrink to parse → call → commit → redirect.
Sequence after #2 — a third of the helper mass is the duplicated
movement rule. |
Strong |
04queries.py is shallow and untyped
web/queries.py · 759 lines 25 pass-throughs · 21 Any 27 template call sites |
Rows leave as list[Any], so row.acount_number type-checks, renders
empty, and ships. mypy gates CI but is vacuous exactly where the code changes
fastest. |
Type the rows, then split by concept. (a) A
NamedTuple per query — zero runtime cost, and the mypy gate starts biting at all
27 call sites. (b) Split the 759 lines along the concepts its comments already group by.
(a) pays off even if (b) never happens. Don't delete this module — that
spreads complexity into handlers. |
Worth it |
05No schema seam
~350 text() sites 30 modules with 5+ mapping_service 26 · queries 25 |
Table and column names exist only as substrings of Python strings. One machine-readable
schema description exists — the 1,932-line Alembic baseline — and nothing links it to the 350
places depending on it. A rename is grep-and-pray. |
Declare the schema once; let CI hold it. A
schema.py of Core Table objects plus an Alembic
compare_metadata check, so the declaration cannot drift from the migrations.
Existing text() queries keep working untouched.
Largest item here, least urgent. Give it its own decision entry. |
Worth it |
06Presentation assembled four times
routes/render.py:372 extract_data.py:80 databook.py:189 cli/commands/statement.py |
All four call render_statement, then each independently orders roots, labels
them and applies buckets. Section order is user-configurable, so screen, extract and workbook
can drift apart. |
Move the seam one step outward. A pure
statement_layout module taking a RenderResult plus display settings
and returning ordered, labelled sections. Each surface keeps its own rendering but shares the
ordering.
No session argument, so the WYSIWYG promise becomes assertable without
Postgres. |
Worth it |
07The test surface is Postgres
tests/conftest.py 63 of 80 files DB-bound 1,030 tests · 27k lines |
A rule expressed in SQL can only be tested by executing SQL. So "does a first-period derived
line carry the full balance?" — pure arithmetic — costs a container, a transaction and a
seeded project. |
Do not act on this directly. Mocking the session would make
the tests worse; the transactional-rollback fixture is well built and should stay. It resolves
as a side effect of 1, 2 and 6.
Watch "test files that don't take the session fixture" (17/80 today) as the
metric that deepening is working. |
Speculative |