fix(bot): strip html tags for Bale, fallback to direct DB catalogs, align validation strictly with DB schema
This commit is contained in:
@@ -281,29 +281,37 @@ def merge_quote_patch(payload: dict, patch: dict) -> bool:
|
||||
|
||||
|
||||
def compute_quote_missing(payload: dict) -> list[dict]:
|
||||
"""What is still empty — the user's explicit ask («یادآوری چیزهای خالی»)."""
|
||||
"""What is still empty — strictly aligned with DB schema requirements."""
|
||||
out: list[dict] = []
|
||||
|
||||
def add(key: str, label: str, ok: bool, blocking: bool) -> None:
|
||||
out.append({"key": key, "label": label, "ok": ok, "blocking": blocking})
|
||||
|
||||
sup_ok = bool(payload.get("supplier_id"))
|
||||
# In DB: supplier_id is NOT NULL in quotes table.
|
||||
sup_ok = bool(payload.get("supplier_id") or payload.get("supplier_name"))
|
||||
add("supplier", "تأمینکننده", sup_ok, True)
|
||||
|
||||
# In DB: project_id is nullable (optional)
|
||||
add("project", "پروژه", bool(payload.get("project_id") or payload.get("project_ids")), False)
|
||||
|
||||
# In DB: expiry_date is nullable (optional)
|
||||
add("expiry", "تاریخ اعتبار", bool(payload.get("expiry_date")), False)
|
||||
|
||||
items = payload.get("items") or []
|
||||
add("items", "قلم (کالا/مقدار)", bool(items), True)
|
||||
for i, item in enumerate(items, start=1):
|
||||
name = item.get("material_name") or f"قلم {i}"
|
||||
if not item.get("material_id"):
|
||||
add(f"item:{i}:material", f"شناسه کالا برای «{name}»", False, True)
|
||||
has_mat = bool(item.get("material_id") or item.get("material_name"))
|
||||
if not has_mat:
|
||||
add(f"item:{i}:material", f"نام کالا برای قلم {i}", False, True)
|
||||
|
||||
if not item.get("quantity"):
|
||||
add(f"item:{i}:qty", f"مقدار «{name}»", False, True)
|
||||
if not item.get("unit_id"):
|
||||
if not item.get("unit_id") and not item.get("unit_name"):
|
||||
add(f"item:{i}:unit", f"واحد کالا برای «{name}»", False, True)
|
||||
if not item.get("unit_price"):
|
||||
add(f"item:{i}:price", f"قیمت واحد برای «{name}»", False, False)
|
||||
|
||||
if items and not payload.get("termsheets"):
|
||||
add("terms", "شرایط پرداخت", False, False)
|
||||
if not payload.get("notes"):
|
||||
|
||||
Reference in New Issue
Block a user