DC Agent: don't send acceptance letter until NW order is placed
The handler was returning the acceptance letter as an artifact, which triggered the instant-delivery email to the client before the admin placed the wholesale order with Northwest. Now uploads to MinIO but returns empty artifacts. Admin todo includes the MinIO path to send the letter after confirming the NW order. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
98a4c90e3a
commit
99bdfdfd91
1 changed files with 22 additions and 11 deletions
|
|
@ -58,25 +58,33 @@ class DCAgentHandler(BaseServiceHandler):
|
|||
entity = order_data.get("entity", {})
|
||||
entity_id = entity.get("id")
|
||||
|
||||
generated: list[str] = []
|
||||
# Generate the acceptance letter and upload to MinIO for later delivery.
|
||||
# Do NOT return as artifacts — the client should only receive it AFTER
|
||||
# the admin places the wholesale order with Northwest.
|
||||
acceptance = self._write_acceptance_letter(order_number, entity, work_dir)
|
||||
minio_path = None
|
||||
if acceptance:
|
||||
generated.append(acceptance)
|
||||
try:
|
||||
generated.append(self._convert_to_pdf(acceptance))
|
||||
pdf_path = self._convert_to_pdf(acceptance)
|
||||
from scripts.document_gen import MinioStorage
|
||||
storage = MinioStorage()
|
||||
minio_key = f"compliance/{order_number}/dc_agent_acceptance.pdf"
|
||||
storage.upload_file(pdf_path or acceptance, minio_key)
|
||||
minio_path = minio_key
|
||||
logger.info("DCAgentHandler: acceptance letter uploaded to %s", minio_key)
|
||||
except Exception as exc:
|
||||
logger.warning("DC agent acceptance PDF conversion failed: %s", exc)
|
||||
logger.warning("DC agent letter upload failed: %s", exc)
|
||||
|
||||
# Persist the NWRA D.C. Agent address on the telecom_entity so the
|
||||
# Form 499-A checklist generator can read it for Lines 209-213
|
||||
# without re-computing. Columns default to NWRA values via
|
||||
# migration 048, so a new order does not need this; but an older
|
||||
# entity created before migration 048 will still get them written.
|
||||
# without re-computing.
|
||||
if entity_id:
|
||||
self._persist_dc_agent(entity_id)
|
||||
|
||||
self._create_wholesale_order_todo(order_number, entity)
|
||||
return generated
|
||||
self._create_wholesale_order_todo(order_number, entity, minio_path)
|
||||
# Return empty — no instant delivery email. The admin sends the
|
||||
# acceptance letter after placing the NW wholesale order.
|
||||
return []
|
||||
|
||||
# ------------------------------------------------------------------ #
|
||||
# Persist NWRA D.C. agent address on the telecom_entity
|
||||
|
|
@ -177,7 +185,7 @@ class DCAgentHandler(BaseServiceHandler):
|
|||
# Admin ToDo for wholesale order placement
|
||||
# ------------------------------------------------------------------ #
|
||||
|
||||
def _create_wholesale_order_todo(self, order_number: str, entity: dict) -> None:
|
||||
def _create_wholesale_order_todo(self, order_number: str, entity: dict, minio_path: str | None = None) -> None:
|
||||
try:
|
||||
from scripts.workers.erpnext_client import ERPNextClient
|
||||
|
||||
|
|
@ -196,7 +204,10 @@ class DCAgentHandler(BaseServiceHandler):
|
|||
f" Contact email: {entity.get('contact_email', '')}\n"
|
||||
f" Contact phone: {entity.get('contact_phone', '')}\n"
|
||||
f" Carrier category: {entity.get('carrier_category', '')}\n\n"
|
||||
f"Billing: use the Relay virtual debit card (SID-0002, filing fees)."
|
||||
f"Billing: use the Relay virtual debit card (SID-0002, filing fees).\n\n"
|
||||
f"After placing the NW order, send the client the acceptance letter"
|
||||
f"{(' (MinIO: ' + minio_path + ')') if minio_path else ''} "
|
||||
f"confirming their D.C. agent is active."
|
||||
)
|
||||
ERPNextClient().create_resource(
|
||||
"ToDo",
|
||||
|
|
|
|||
Loading…
Reference in a new issue