Implement document reconciliation v2
This commit is contained in:
@@ -378,14 +378,11 @@ def _load_task_context(task_id: str) -> Dict[str, Any]:
|
||||
|
||||
def _doc_counts(conn, opportunity_id: str) -> Dict[str, int]:
|
||||
try:
|
||||
row = conn.execute(text("""
|
||||
SELECT
|
||||
COUNT(*) FILTER (WHERE document_kind IN ('quotation','proforma'))::int AS quotes,
|
||||
COUNT(*) FILTER (WHERE document_kind = 'invoice')::int AS invoices
|
||||
FROM commercial_documents
|
||||
WHERE opportunity_id = CAST(:opportunity_id AS UUID)
|
||||
"""), {"opportunity_id": opportunity_id}).mappings().first()
|
||||
return {"quotes": int((row or {}).get("quotes") or 0), "invoices": int((row or {}).get("invoices") or 0)}
|
||||
from app.document_reconciliation_service import resolve_document_links
|
||||
rows = [row for row in resolve_document_links(opportunity_id, conn=conn)
|
||||
if row.get("relationship") == "PRIMARY"]
|
||||
return {"quotes": sum(row.get("document_kind") in {"quotation", "proforma"} for row in rows),
|
||||
"invoices": sum(row.get("document_kind") == "invoice" for row in rows)}
|
||||
except Exception:
|
||||
return {"quotes": 0, "invoices": 0}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user