Files
tenant-registry/cmd/erpsetup/main.go
T
sharangandClaude Opus 5.5 40a198c56f
ci / shared (push) Successful in 13s
ci / test (push) Successful in 23m50s
ci / image (push) Successful in 36s
feat(erpsetup): BreakPilot document layout and list prices (#51)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DmXxNULoSNPvjF7buKipsB
2026-09-30 10:44:03 +00:00

55 lines
1.9 KiB
Go

// erpsetup — applies the live-ERPNext configuration the tenant-registry needs
// (custom fields, the Usage Record doctype, the sales catalogue with SKU items,
// list prices and SEPA mandate fields, the document layout, the Frappe
// Webhooks). Idempotent;
// run with -dry-run first. It never submits, cancels or deletes ERP documents.
//
// ERP_BASE_URL=https://erp.breakpilot.com ERP_API_KEY=… ERP_API_SECRET=… \
// ERP_WEBHOOK_SECRET=… erpsetup -webhook-url https://registry.breakpilot.com/v1/internal/erp/webhook -dry-run
//
// The API user needs System Manager for this run (it creates a DocType,
// Webhooks, items and custom fields); the registry's day-to-day key can then have a narrower role.
package main
import (
"context"
"flag"
"fmt"
"os"
"os/signal"
"git.breakpilot.com/platform/tenant-registry/internal/erpsetup"
)
func main() {
dry := flag.Bool("dry-run", false, "report what would be created, change nothing")
hook := flag.String("webhook-url", "", "registry webhook receiver, e.g. https://registry.breakpilot.com/v1/internal/erp/webhook")
lead := flag.String("lead-doctype", envOr("ERP_LEAD_DOCTYPE", "Lead"), `"Lead" (ERPNext) or "CRM Lead" (Frappe CRM)`)
flag.Parse()
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt)
defer stop()
steps, err := erpsetup.Run(ctx, erpsetup.Config{
BaseURL: os.Getenv("ERP_BASE_URL"),
APIKey: os.Getenv("ERP_API_KEY"),
APISecret: os.Getenv("ERP_API_SECRET"),
WebhookURL: *hook,
WebhookSecret: os.Getenv("ERP_WEBHOOK_SECRET"),
LeadDoctype: *lead,
DryRun: *dry,
Log: func(f string, a ...any) { fmt.Printf(f+"\n", a...) },
})
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
fmt.Printf("%d steps, done%s\n", len(steps), map[bool]string{true: " (dry run, nothing changed)", false: ""}[*dry])
}
func envOr(k, d string) string {
if v := os.Getenv(k); v != "" {
return v
}
return d
}