Wire CPNI, CALEA, 499-A engagement, and discontinuance to generic eSign

Each handler now pauses for officer signature via the eSign portal
before filing/submitting. esign_completed callback re-dispatches
through standard pipeline with client_approved=true.

- CPNI: officer signs certification before ECFS submission (perjury)
- CALEA SSI: officer signs plan before delivery
- 499-A engagement: replaced custom JWT/email with request_esign()
- Discontinuance: officer signs deactivation letter before USAC email
- job_server: injects client_approved + order_number into order_data

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
justin 2026-05-04 10:53:59 -05:00
parent 40844b2aff
commit ff47f47a37
5 changed files with 161 additions and 74 deletions

View file

@ -1136,6 +1136,19 @@ def handle_process_compliance_service(payload: dict) -> dict:
order.get("entity", {}).get("frn"), exc)
handler = handler_cls()
# Ensure order_number is always available (some handlers use it instead of name)
if order_number:
order["order_number"] = order_number
# Inject eSign approval flags from payload (set by handle_esign_completed)
if payload.get("client_approved"):
order["client_approved"] = True
if payload.get("esign_document_type"):
order["esign_document_type"] = payload["esign_document_type"]
if payload.get("esign_signer_email"):
order["esign_signer_email"] = payload["esign_signer_email"]
# Final entity check before dispatch
ent = order.get("entity", {})
LOG.info(
@ -1562,9 +1575,9 @@ def handle_esign_completed(payload: dict) -> dict:
Called by portal-esign-generic.ts after a client signs any document.
Payload: { order_number, document_type, esign_record_id, signer_email }
Looks up the compliance order for this order_number and re-dispatches
the service handler with client_approved=true so it continues past
the signing checkpoint.
Re-dispatches through the standard handle_process_compliance_service
path with client_approved=true injected into the payload so the handler
skips past its signing checkpoint on the second run.
"""
order_number = payload.get("order_number", "")
document_type = payload.get("document_type", "")
@ -1578,7 +1591,7 @@ def handle_esign_completed(payload: dict) -> dict:
conn = psycopg2.connect(os.environ.get("DATABASE_URL", ""))
with conn.cursor() as cur:
cur.execute(
"SELECT service_slug FROM compliance_orders WHERE order_number = %s",
"SELECT service_slug, erpnext_sales_order FROM compliance_orders WHERE order_number = %s",
(order_number,),
)
row = cur.fetchone()
@ -1589,22 +1602,20 @@ def handle_esign_completed(payload: dict) -> dict:
return {"warning": f"No compliance order for {order_number}"}
service_slug = row[0]
erpnext_so = row[1] or order_number
# Re-dispatch the service handler with approval flag
from scripts.workers.services import SERVICE_HANDLERS
handler_cls = SERVICE_HANDLERS.get(service_slug)
if handler_cls:
LOG.info("[esign_completed] Re-dispatching %s for %s", service_slug, order_number)
handler = handler_cls()
handler.process(order_number, {
"client_approved": True,
"esign_document_type": document_type,
"esign_signer_email": payload.get("signer_email", ""),
})
else:
LOG.warning("[esign_completed] No handler for slug=%s", service_slug)
LOG.info("[esign_completed] Re-dispatching %s for %s via standard pipeline", service_slug, order_number)
return {"success": True, "order_number": order_number, "document_type": document_type}
# Re-dispatch through the standard compliance service handler.
# client_approved is injected and will be merged into order_data.
return handle_process_compliance_service({
"order_name": erpnext_so,
"order_number": order_number,
"service_slug": service_slug,
"client_approved": True,
"esign_document_type": document_type,
"esign_signer_email": payload.get("signer_email", ""),
})
except Exception as exc:
LOG.error("[esign_completed] Error for %s: %s", order_number, exc)
return {"error": str(exc)}