fix(bot): strip html tags for Bale, fallback to direct DB catalogs, align validation strictly with DB schema

This commit is contained in:
2026-09-29 01:49:42 +03:30
parent 17458d8697
commit da68fc683f
6 changed files with 217 additions and 99 deletions
+1 -1
View File
@@ -79,4 +79,4 @@ async def _whoami(ctx, chat_id: int) -> None:
await ctx.send(chat_id, UNLINKED)
return
role = ROLE_FA.get(link.role or "", link.role or "بدون نقش")
await ctx.send(chat_id, f"اتصال: <b>{esc(link.display_name)}</b> — {role}")
await ctx.send(chat_id, f"اتصال: {esc(link.display_name)} — {role}")
+5 -5
View File
@@ -103,9 +103,9 @@ def _flow_user(flow):
def _accept_summary(quote: dict, chosen: int) -> str:
lines = [
f"✔️ <b>پذیرش استعلام</b> #{esc(str(quote.get('id'))[:8])} — {esc((quote.get('supplier') or {}).get('name') or '—')}",
f"✔️ پذیرش استعلام #{esc(str(quote.get('id'))[:8])} — {esc((quote.get('supplier') or {}).get('name') or '—')}",
"",
"<b>اقلام:</b>",
"اقلام:",
]
for li in quote.get("line_items") or []:
mat = (li.get("material") or {}).get("name") or li.get("material_id") or "?"
@@ -116,7 +116,7 @@ def _accept_summary(quote: dict, chosen: int) -> str:
parts.append(f"قیمت {esc(price)}")
lines.append(" — ".join(parts))
lines.append("")
lines.append("<b>شرایط پرداخت:</b>")
lines.append("شرایط پرداخت:")
for i, ts in enumerate(quote.get("termsheets") or []):
mark = "👉" if i == chosen else " "
discount = f" (تخفیف {esc(ts.get('discount_value'))})" if ts.get("discount_value") else ""
@@ -276,7 +276,7 @@ async def handle_flow_text(ctx, chat_id, flow, text: str) -> bool:
# ---------------------------------------------------------------------------
def _arrive_summary(items: list[dict], quantities: dict[str, float] | None = None) -> str:
lines = ["🚚 <b>اعلام رسیدن اقلام</b>", ""]
lines = ["🚚 اعلام رسیدن اقلام", ""]
for li in items:
mat = (li.get("material") or {}).get("name") or "?"
ordered = li.get("quantity") or 0
@@ -284,7 +284,7 @@ def _arrive_summary(items: list[dict], quantities: dict[str, float] | None = Non
unit = ((li.get("unit") or {}).get("name_fa")) or ""
got = ""
if quantities and li["id"] in quantities:
got = f" → <b>الان: {esc(quantities[li['id']])} {unit}</b>"
got = f" → الان: {esc(quantities[li['id']])} {unit}"
lines.append(f"• {esc(mat)} — سفارش {esc(ordered)} {unit} — تاکنون {esc(received)}{got}")
return "\n".join(lines)