Wire fulfillment alerts to Telegram + surface order progress in portal + even out ERPNext sync

Telegram notifications:
- Add shared scripts/workers/telegram_notify.py (send_telegram, notify_fulfillment_todo,
  create_admin_todo) so every worker alerts the operator the same way; fire-and-forget.
- Fire notify_fulfillment_todo after each admin_todos insert across all 8 service
  handlers (9 sites) so no fulfillment task waits unseen.
  (Orders + quotes + tickets already notified via checkout/quotes/tickets routes.)

Client portal order progress:
- order-timeline: derive real per-step status from live signals (payment paid,
  e-signature signed, fulfillment_status) instead of a static template; add
  current_step to the response.
- Extract pure applyLiveStatus into order-timeline-status.ts (DB-free) + unit test
  (api/test/test_timeline_status.ts, 8 cases).
- portal /me now returns compliance_orders.fulfillment_status.
- Dashboard renders a client-safe Progress badge (In progress / Action needed /
  Filed-awaiting-confirmation / Completed); batches show the most actionable status.
  No back-office mechanics exposed.

ERPNext sync parity:
- Create a Sales Order for formation and fcc_carrier_registration orders (previously
  only canada_crtc + compliance synced); write erpnext_sales_order back to each table.
  Non-blocking, matches existing pattern.

Verified: API tsc clean, timeline unit tests 8/8, Astro build 58 pages,
cms10114/ink/paper_batch Python tests still green, no mechanics leaks.
This commit is contained in:
justin 2026-06-07 03:17:46 -05:00
parent 41df4d9553
commit 28b1af341d
15 changed files with 706 additions and 73 deletions

View file

@ -41,6 +41,8 @@ import logging
import os
from datetime import datetime
from scripts.workers.telegram_notify import notify_fulfillment_todo
LOG = logging.getLogger("workers.services.boc3_filing")
# Process agent partner: Registered Agents Inc / Process Agent LLC
@ -229,6 +231,20 @@ class BOC3FilingHandler:
try:
import psycopg2
conn = psycopg2.connect(os.environ.get("DATABASE_URL", ""))
todo_title = f"BOC-3 Filing — {entity_name} (DOT {dot_number})"
todo_description = (
f"File BOC-3 process agent designation for {entity_name}.\n"
f"DOT: {dot_number}\n"
f"MC/Docket: {docket_number}\n"
f"Type: {entity_type}\n"
f"Authority status: {boc3_status}\n"
f"Customer: {customer_email}\n\n"
+ ("Recommended follow-ups (upsell-approve, not auto-charged):\n"
+ "\n".join(f" - {f['title']}: {f['reason']}"
for f in recommended_followups) + "\n\n"
if recommended_followups else "")
+ f"Submit to process agent partner for electronic filing with FMCSA."
)
with conn.cursor() as cur:
cur.execute("""
INSERT INTO admin_todos (
@ -236,25 +252,22 @@ class BOC3FilingHandler:
description, data, status
) VALUES (%s, %s, %s, %s, %s, %s, %s, 'pending')
""", (
f"BOC-3 Filing — {entity_name} (DOT {dot_number})",
todo_title,
"filing",
"high",
order_number,
self.SERVICE_SLUG,
f"File BOC-3 process agent designation for {entity_name}.\n"
f"DOT: {dot_number}\n"
f"MC/Docket: {docket_number}\n"
f"Type: {entity_type}\n"
f"Authority status: {boc3_status}\n"
f"Customer: {customer_email}\n\n"
+ ("Recommended follow-ups (upsell-approve, not auto-charged):\n"
+ "\n".join(f" - {f['title']}: {f['reason']}"
for f in recommended_followups) + "\n\n"
if recommended_followups else "")
+ f"Submit to process agent partner for electronic filing with FMCSA.",
todo_description,
json.dumps(todo_data),
))
conn.commit()
notify_fulfillment_todo(
title=todo_title,
order_number=order_number,
service_slug=self.SERVICE_SLUG,
priority="high",
description=todo_description,
)
conn.close()
LOG.info("[%s] Admin todo created for BOC-3 filing", order_number)
except Exception as exc: