# Polleo Demand — Roadmap to Next Level

Companion to `AUDIT_REPORT.md`. The audit says *what's wrong*; this says *what to do
next and in what order*. Philosophy: the app already has plenty of breadth (6 modules,
31 pages). The leverage now is **depth and trust** — make what exists correct, tested,
and dependable — **not more features**.

Progress is tracked with checkboxes. `[x]` = done (with the commit/PR or file noted),
`[~]` = in progress, `[ ]` = not started.

---

## Tier 1 — Make it trustworthy
*A planning tool nobody trusts is worthless, regardless of model quality.*

- [x] **Extract the duplicated roll-forward calculation** into one tested helper.
  `_roll_forward()` in `backend/services/supply_service.py` now backs the supply
  dashboard, stock projection, and coverage grid. Behavior-parity verified against the
  old inline logic (no-exclusion / with-exclusion / per-cell coverage all identical).
  *Note: the stockout-detector (finance/wholesale) and ATP-walk variants were left
  separate on purpose — they compute different things and merging them would change
  behavior.*

- [x] **Test harness around the pure math.**
  `backend/tests/` with pytest (`pytest.ini` at root). 49 golden tests pinning current
  behavior of the calculation core so future refactors can't silently move a number.
  Verified the suite has teeth (a deliberately broken threshold fails the right test).
  Run: `python -m pytest backend/tests -q`.
  - [x] `coverage_classifier.classify_coverage` + `incoming_within_lt` (canonical
    LT-relative classifier — every branch + boundaries)
  - [x] `supply_service._roll_forward` / `_classify` / `_safe_float`
  - [x] `scenario_service` (`classify`, `real_weeks_cover`, `week_step`/`week_series`)
  - [x] `time_utils` (ISO-week → month splitting)

- [~] **One source of truth per computed concept.** The audit found *three* coverage
  classifiers giving the same SKU different answers on different pages, plus two parallel
  bridge implementations.
  - [x] Coverage: **decision (Lovro, 2026-05-29) — keep Supply's absolute-weeks numbers
    stable; do NOT unify.** `coverage_classifier` docstring corrected to state its real
    scope (Executive + Finance only) and to document the accepted Supply divergence so
    nobody "fixes" it by accident. The golden tests make a future unification safe if the
    call is ever reversed.
  - [ ] Bridge: delete legacy `finance_service.report_bridge` once `report_bridge_monthly`
    fully supersedes it (two implementations *will* drift).
  - [ ] FA: one shared FA aggregation, consumed by demand + executive (currently
    duplicated).

- [ ] **Close the security + secrets gaps** (from audit §2.1–2.3, §8 Tier 1):
  - [ ] Rotate the committed Slack token, then `git rm --cached .env`. *(token rotation
    needs Slack admin — Lovro)*
  - [ ] Remove the default password from `deploy/smoke_test.sh`.
  - [ ] Wire `require_section()` into the 73 unprotected demand/supply/promo endpoints.

## Tier 2 — Make it survivable without you
*Today Lovro is a single point of failure.*

- [ ] **Deployment + backups + runbook.** Run on IT's Docker host with automated Postgres
  backups and a one-page "what to do when X breaks".
- [ ] **Hands-off data ingestion.** Email-triggered ingestion pipeline (ERP sends files on
  schedule) feeding the existing `UploadService` — with sender allowlist, idempotency,
  a row-count sanity gate before any delete, and result notifications.
- [ ] **Generate frontend types from the backend OpenAPI schema** (`openapi-typescript`).
  Kills drift between the 1,487-line hand-maintained `types/demand.ts` and the Pydantic
  schemas.

## Tier 3 — Make the forecasting actually better
*The real product value.*

- [ ] **Finish the ERP promo calendar integration** — highest-leverage accuracy win per
  `CLAUDE.md`; Gold-tier SKUs benefit most.
- [ ] **Lifecycle (not statistical) forecasting for non-food / NPD** — StatsForecast fails
  on these; needs a different model class.
- [ ] **Shift from reporting to deciding.** Turn order proposals / promo P&L / scenarios
  into "here's the recommended action — approve or adjust" workflows, closing the S&OP
  loop (recommend → approve → track outcome → feed back into accuracy).

## Explicitly NOT doing
- No 7th module, no new pages. Breadth is already high for a two-person team; every new
  page is more untested math and more drift. Deepen and harden what exists.

---

### Changelog
- *2026-06-02* — Sales upload now persists the **full** Rekapitulacija per row
  (partner_id, store_id, sales_rep, document, all financials) — previously only 6
  cols, dropping partner so buyer-level was empty for app-uploaded weeks. Partner/store
  auto-discover; codes matched zero-stripped (Excel depads `05770`→`5770`). **RAC**
  reclassified webshop→**wholesale** and **RPE** added, applied everywhere
  (`lookup_channel_map`, `WS_CHANNEL_MAP_IDS`, `demand_repo`, `update_sales.py`,
  both channel-map seeds). Upload is append-only — backfill by deleting the ISO-week
  range first (W21/W22 cleared, pending re-upload).
- *2026-05-29* — Roadmap created. Roll-forward extraction landed + verified. Test harness
  landed: 49 pure-math golden tests in `backend/tests/`, all green, teeth-verified.
  Coverage SoT decision: keep Supply numbers stable; `coverage_classifier` docstring
  corrected to reflect real scope + documented divergence.
