payslip-ingest/alembic/versions
Viktor Barzin 3b9c69bfd3 backfill: cash_income_tax back-fill for variant-A NULL rows
Phase B of RSU tax spike fix. Vest-month spikes on the dashboard trace to
variant-A slips (2019–mid-2022) where `cash_income_tax` is NULL — the
dashboard's COALESCE fallback returns full PAYE, masquerading as cash tax.

Three changes:

1. Widen variant-A Taxable Pay regex. Original pattern only matched
   `Taxable Pay : This Period £...`; add case-insensitive variants that
   tolerate missing/different colons, elided "This", and uppercase labels.
   Covers older 2019-2020 templates that failed the previous match.

2. New `backfill_cash_income_tax` module — walks every NULL-cash-tax row
   with rsu_vest > 0, re-downloads the PDF from Paperless, runs the
   widened regex parser, falls back to Claude for taxable_pay extraction
   if regex still misses, and derives cash_income_tax pro-rata. Records
   provenance in new `cash_income_tax_source` column (regex/claude/
   fallback_null). Idempotent — only touches NULL rows.

3. Migration 0006 adds the `cash_income_tax_source` audit column.

CLI: `python -m payslip_ingest backfill-cash-tax [--limit N]`. Meant to
run as a one-shot K8s Job after `alembic upgrade head`.

Part of: code-860
2026-04-19 18:15:18 +00:00
..
0001_initial.py v2: regex parser for Meta UK template + accurate RSU tax attribution 2026-04-19 10:53:52 +00:00
0002_add_rsu_columns.py alembic 0002: fix down_revision to '0001' (matches 0001_initial's id) 2026-04-18 23:41:29 +00:00
0003_earnings_breakdown.py v2: regex parser for Meta UK template + accurate RSU tax attribution 2026-04-19 10:53:52 +00:00
0004_cash_income_tax.py parser + P60 ingest: split income_tax cash/RSU, add P60 ground-truth 2026-04-19 15:23:05 +00:00
0005_p60_reference.py parser + P60 ingest: split income_tax cash/RSU, add P60 ground-truth 2026-04-19 15:23:05 +00:00
0006_cash_income_tax_source.py backfill: cash_income_tax back-fill for variant-A NULL rows 2026-04-19 18:15:18 +00:00