Spaces:
Sleeping
Sleeping
hotfix: budget parser + defensive readback (TypeError str>int)
Browse files- backend/needs_finder.py +17 -3
backend/needs_finder.py
CHANGED
|
@@ -94,6 +94,14 @@ GRAPH: list[Question] = [
|
|
| 94 |
prompt_hi="पहले से कोई health insurance है — employer का या personal? Sum insured कितना? (Top-up plan ज़्यादा सही हो सकता है।)",
|
| 95 |
field="existing_cover_inr",
|
| 96 |
is_core=True,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
),
|
| 98 |
Question(
|
| 99 |
id="primary_goal",
|
|
@@ -191,10 +199,16 @@ def readback_summary(profile: Profile) -> str:
|
|
| 191 |
bits.append(f"covering {profile.dependents}")
|
| 192 |
if profile.income_band:
|
| 193 |
bits.append(f"income {profile.income_band}")
|
| 194 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 195 |
bits.append(
|
| 196 |
-
f"existing cover ₹{
|
| 197 |
-
if
|
| 198 |
else "no existing cover"
|
| 199 |
)
|
| 200 |
if profile.primary_goal:
|
|
|
|
| 94 |
prompt_hi="पहले से कोई health insurance है — employer का या personal? Sum insured कितना? (Top-up plan ज़्यादा सही हो सकता है।)",
|
| 95 |
field="existing_cover_inr",
|
| 96 |
is_core=True,
|
| 97 |
+
parser=lambda s: (
|
| 98 |
+
0 if any(k in str(s).lower() for k in ("no", "none", "nothing", "zero", "not"))
|
| 99 |
+
else (
|
| 100 |
+
(int("".join(c for c in str(s) if c.isdigit())[:6] or 0) *
|
| 101 |
+
(100000 if any(k in str(s).lower() for k in ("l", "lakh", "lac")) else 1))
|
| 102 |
+
or None
|
| 103 |
+
)
|
| 104 |
+
),
|
| 105 |
),
|
| 106 |
Question(
|
| 107 |
id="primary_goal",
|
|
|
|
| 199 |
bits.append(f"covering {profile.dependents}")
|
| 200 |
if profile.income_band:
|
| 201 |
bits.append(f"income {profile.income_band}")
|
| 202 |
+
ec = profile.existing_cover_inr
|
| 203 |
+
if isinstance(ec, str):
|
| 204 |
+
try:
|
| 205 |
+
ec = int("".join(c for c in ec if c.isdigit())[:8] or 0)
|
| 206 |
+
except Exception:
|
| 207 |
+
ec = None
|
| 208 |
+
if isinstance(ec, (int, float)):
|
| 209 |
bits.append(
|
| 210 |
+
f"existing cover ₹{int(ec):,}"
|
| 211 |
+
if ec > 0
|
| 212 |
else "no existing cover"
|
| 213 |
)
|
| 214 |
if profile.primary_goal:
|