The live ERPNext had none of the registry's SKUs (only the demo items), so a sales order could not unlock anything. erpsetup now also creates, where missing: - units Monat, Jahr, Prüfung and the item group BreakPilot Abonnements - 22 service items: the registry's 19 product SKUs plus the platform fee PLT-CORE-CLD-STD/BUS/ENT (billed, unlocks nothing), names and German descriptions from the SKU sheet; no prices (set in ERPNext) - Customer fields for the SEPA mandate (reference, date, CORE/B2B) - the payment method SEPA-Lastschrift A test keeps the item list in step with the registry's product SKUs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DmXxNULoSNPvjF7buKipsB
54 lines
1.9 KiB
Go
54 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
|
|
// and SEPA mandate fields, 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
|
|
}
|