Pipeline funnel v2: 4-stage enum + migration 0007 + derived grid signals
Collapse the inherited 6-stage opportunity funnel to the locked 4-stage
per-investor funnel (lead -> engaged -> diligence -> commitment), terminal at
commitment. Migration 0007 remaps existing stage values (outreach/meeting ->
engaged, due_diligence -> diligence, committed/funded -> commitment) and
archives the stray 'lost' value (the grid row is left intact). Inject read-only
existing_investor (total_invested>0), last_activity_at, and staleness
(''/'aging'>=30d/'stale'>=60d) into the grid GET, stripped on write. Frontend:
4-stage chip tints + Pipeline board / opp-form / mock on the new enum.
The visible desktop existing-investor star + staleness recency column + the
Stale saved view are deferred to mobile Phase 3 (data is injected + test-locked
now, so that phase stays pure-frontend). Longshot was already retired by prior
cleanup -- no-op.
Tests: test_pipeline_stages_v2.py (migration remap + derivation boundaries) +
updated grid-pipeline-link / soft-delete / nl_query; 36/36 green, render-smoke
green, fresh-DB migrate clean.
This commit is contained in:
@@ -28,13 +28,13 @@ from datetime import datetime, timedelta
|
||||
# scan flooding a response. A list intent past this is reported truncated, never silently cut.
|
||||
MAX_ROWS = 500
|
||||
|
||||
# Live, non-terminal pipeline stages in funnel order (mirrors server.PIPELINE_STAGES; 'lost'
|
||||
# is the terminal drop). Kept here so the pipeline intents have a stable rank without importing
|
||||
# the server module (helpers take a conn; they never import server — house convention).
|
||||
_STAGE_ORDER = ['lead', 'outreach', 'meeting', 'due_diligence', 'committed', 'funded']
|
||||
# 4-stage per-investor funnel in order, terminal at 'commitment' (mirrors server.PIPELINE_STAGES).
|
||||
# Kept here so the pipeline intents have a stable rank without importing the server module
|
||||
# (helpers take a conn; they never import server — house convention).
|
||||
_STAGE_ORDER = ['lead', 'engaged', 'diligence', 'commitment']
|
||||
_STAGE_RANK_SQL = (
|
||||
"CASE stage WHEN 'lead' THEN 1 WHEN 'outreach' THEN 2 WHEN 'meeting' THEN 3 "
|
||||
"WHEN 'due_diligence' THEN 4 WHEN 'committed' THEN 5 WHEN 'funded' THEN 6 ELSE 0 END")
|
||||
"CASE stage WHEN 'lead' THEN 1 WHEN 'engaged' THEN 2 "
|
||||
"WHEN 'diligence' THEN 3 WHEN 'commitment' THEN 4 ELSE 0 END")
|
||||
|
||||
|
||||
# ── helpers ────────────────────────────────────────────────────────────────────────────
|
||||
@@ -237,7 +237,7 @@ def run_pipeline_top(conn, slots):
|
||||
"o.probability, u.full_name AS owner FROM opportunities o "
|
||||
"LEFT JOIN fundraising_investors i ON i.id = o.fundraising_investor_id "
|
||||
"LEFT JOIN users u ON u.id = o.owner_id "
|
||||
"WHERE o.deleted_at IS NULL AND o.stage != 'lost' "
|
||||
"WHERE o.deleted_at IS NULL "
|
||||
f"ORDER BY {_STAGE_RANK_SQL} DESC, o.expected_amount DESC LIMIT ?", (n,)))
|
||||
for r in rows:
|
||||
r["last_activity_at"] = last.get(r.pop("inv_id"))
|
||||
@@ -248,11 +248,11 @@ def run_pipeline_top(conn, slots):
|
||||
|
||||
|
||||
def run_pipeline_totals(conn, slots):
|
||||
"""Total pipeline dollars and the split across each stage (excludes lost)."""
|
||||
"""Total pipeline dollars and the split across each stage."""
|
||||
rows = _rows(conn.execute(
|
||||
"SELECT stage, COUNT(*) AS count, COALESCE(SUM(expected_amount),0) AS expected_total, "
|
||||
"COALESCE(SUM(commitment_amount),0) AS committed_total FROM opportunities "
|
||||
f"WHERE deleted_at IS NULL AND stage != 'lost' GROUP BY stage ORDER BY {_STAGE_RANK_SQL}"))
|
||||
f"WHERE deleted_at IS NULL GROUP BY stage ORDER BY {_STAGE_RANK_SQL}"))
|
||||
total = sum(r["expected_total"] for r in rows)
|
||||
count = sum(r["count"] for r in rows)
|
||||
return {"columns": ["stage", "count", "expected_total", "committed_total"],
|
||||
|
||||
Reference in New Issue
Block a user