feat(erp): erpsetup for live ERPNext, reserved tenant slugs #32

Merged
sharang merged 1 commits from feat/live-erpnext into main 2026-09-23 17:16:25 +00:00
Owner

Production go-live, Track B (plan 2026-09-23).

cmd/erpsetup (image path /erpsetup)

Applies the live-ERPNext configuration the registry relies on. Each step checks first and creates only what is missing; -dry-run only reports. It never submits, cancels or deletes an ERP document.

  • Custom fields Customer.tenant_id (unique) and Customer.tenant_slug, <Lead>.tenant_id and <Lead>.requested_product (-lead-doctype "CRM Lead" for Frappe CRM).
  • Custom DocType Usage Record (module Selling; customer, tenant_id, product, metric, qty, occurred_at, idempotency_key unique).
  • Frappe Webhooks, security on (X-Frappe-Webhook-Signature, base64 HMAC-SHA256, which the receiver already verifies), with JSON bodies in the erp.WebhookEvent shape. modified goes into the fallback event id, because live Frappe sends no X-Frappe-Event-Id:
    • Sales Order on_submit → sales_order.submit
    • Sales Invoice on_update_after_submit when Overdue → sales_invoice.overdue (days via frappe.utils.date_diff)
    • Payment Entry on_submit (party Customer) → payment_entry.submit
    • Subscription on_update when Cancelled → subscription.cancel

Caveat to verify on the live ERP: ERPNext sets invoices to Overdue from a scheduled job, which may not fire on_update_after_submit. The 15-minute reconcile over Subscriptions remains the safety net for the ladder.

Run (after review, dry run first):

ERP_BASE_URL=https://erp.breakpilot.com ERP_API_KEY=… ERP_API_SECRET=… ERP_WEBHOOK_SECRET=… \
  go run ./cmd/erpsetup -webhook-url https://registry.breakpilot.com/v1/internal/erp/webhook -dry-run

Reserved slugs

POST /v1/tenants answers 400 reserved_slug for paths the portal serves (admin, start, install, docs, …). This mirrors portal#40. demo stays allowed because the sales demo tenant uses it.

Tests: fake Frappe (create, then idempotent second run, dry run, CRM Lead, auth and 5xx errors); go test -short ./... green.

🤖 Generated with Claude Code

https://claude.ai/code/session_01DmXxNULoSNPvjF7buKipsB

Production go-live, Track B (plan 2026-09-23). ## `cmd/erpsetup` (image path `/erpsetup`) Applies the live-ERPNext configuration the registry relies on. Each step checks first and creates only what is missing; `-dry-run` only reports. It never submits, cancels or deletes an ERP document. - Custom fields `Customer.tenant_id` (unique) and `Customer.tenant_slug`, `<Lead>.tenant_id` and `<Lead>.requested_product` (`-lead-doctype "CRM Lead"` for Frappe CRM). - Custom DocType **Usage Record** (module Selling; customer, tenant_id, product, metric, qty, occurred_at, idempotency_key unique). - Frappe **Webhooks**, security on (`X-Frappe-Webhook-Signature`, base64 HMAC-SHA256, which the receiver already verifies), with JSON bodies in the `erp.WebhookEvent` shape. `modified` goes into the fallback event id, because live Frappe sends no `X-Frappe-Event-Id`: - Sales Order `on_submit` → `sales_order.submit` - Sales Invoice `on_update_after_submit` when Overdue → `sales_invoice.overdue` (days via `frappe.utils.date_diff`) - Payment Entry `on_submit` (party Customer) → `payment_entry.submit` - Subscription `on_update` when Cancelled → `subscription.cancel` **Caveat to verify on the live ERP:** ERPNext sets invoices to Overdue from a scheduled job, which may not fire `on_update_after_submit`. The 15-minute reconcile over Subscriptions remains the safety net for the ladder. Run (after review, dry run first): ``` ERP_BASE_URL=https://erp.breakpilot.com ERP_API_KEY=… ERP_API_SECRET=… ERP_WEBHOOK_SECRET=… \ go run ./cmd/erpsetup -webhook-url https://registry.breakpilot.com/v1/internal/erp/webhook -dry-run ``` ## Reserved slugs `POST /v1/tenants` answers `400 reserved_slug` for paths the portal serves (admin, start, install, docs, …). This mirrors portal#40. `demo` stays allowed because the sales demo tenant uses it. Tests: fake Frappe (create, then idempotent second run, dry run, CRM Lead, auth and 5xx errors); `go test -short ./...` green. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01DmXxNULoSNPvjF7buKipsB
sharang added 1 commit 2026-09-23 16:18:15 +00:00
feat(erp): erpsetup for live ERPNext, reserved tenant slugs
ci / shared (pull_request) Successful in 12s
ci / test (pull_request) Successful in 23m1s
ci / image (pull_request) Skipped
bcb0895480
cmd/erpsetup applies what the registry expects in a live ERPNext:
tenant_id/tenant_slug custom fields on Customer and Lead, the Usage
Record doctype, and Frappe Webhooks (Sales Order submit, Sales
Invoice overdue, Payment Entry submit, Subscription cancelled) signed
with the registry's webhook secret. It checks before it creates, so it
can run again at any time, and -dry-run only reports. It ships in the
image as /erpsetup.

Tenant creation refuses slugs the portal serves itself (admin, start,
install, docs, …), mirroring the portal's signup check.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DmXxNULoSNPvjF7buKipsB
sharang merged commit ceeff16f26 into main 2026-09-23 17:16:25 +00:00
Sign in to join this conversation.