feat(erpsetup): sales catalogue — SKU items, units, SEPA mandate fields
ci / shared (pull_request) Successful in 14s
ci / test (pull_request) Successful in 23m45s
ci / image (pull_request) Skipped

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
This commit is contained in:
Sharang ParnerkarandClaude Opus 5.5 committed 2026-09-29 17:57:35 +02:00
1 parent f96525dd4d
commit 5af7061708
4 files changed
+181 -9

No files matched your search

+4 -3
View File
@@ -1,12 +1,13 @@
// erpsetup — applies the live-ERPNext configuration the tenant-registry needs
// (custom fields, the Usage Record doctype, the Frappe Webhooks). Idempotent;
// (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 and
// Webhooks); the registry's day-to-day key can then have a narrower role.
// 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 (
+81
View File
@@ -0,0 +1,81 @@
package erpsetup
// The sales catalogue in ERPNext: the SKU items (codes as in the registry's
// products table and the "Breakpilot SKU + SLA" sheet), their units and item
// group, the SEPA direct-debit mandate on the Customer and the payment method.
// Prices are not set here: they live in ERPNext (price list or quotation).
const itemGroup = "BreakPilot Abonnements"
type sku struct {
Code, Name, UOM, Description string
}
// skus lists every item a sales order may carry. The registry unlocks a
// product for the product SKUs; the platform fee (PLT-CORE-*) is billed but
// unlocks nothing on its own.
func skus() []sku {
return []sku{
{"PLT-CORE-CLD-STD", "BreakPilot Plattform – Starter", "Monat", "Arbeitsbereich mit Anmeldung, Team und Rechnungen: bis 25 Nutzer, bis 3 Produkte, Standard-Support."},
{"PLT-CORE-CLD-BUS", "BreakPilot Plattform – Growth", "Monat", "Arbeitsbereich für bis 100 Nutzer, beliebig viele Produkte, monatlicher Nutzungsbericht, vorrangiger Support."},
{"PLT-CORE-CLD-ENT", "BreakPilot Plattform – Enterprise", "Monat", "Arbeitsbereich ohne Nutzergrenze, persönliche Betreuung, individuelle Verträge (AVV), Wahl der EU-Region."},
{"CRA-CSA-CLD-STD", "Prüfwerk Cloud – Standard", "Monat", "Automatische CRA-Prüfung von Quellcode, Firmware und SPS-Programmen: 5 Prüfobjekte, 50 Prüfungen im Monat, monatliches Nachweispaket."},
{"CRA-CSA-CLD-BUS", "Prüfwerk Cloud – Business", "Monat", "Prüfwerk für 25 Prüfobjekte und 500 Prüfungen im Monat, mit Schnittstelle (MCP) für eigene Werkzeuge."},
{"CRA-CSA-CLD-ENT", "Prüfwerk Cloud – Enterprise", "Monat", "Prüfwerk ohne Obergrenzen, eigener Kontrollkatalog, Nachweisexport für abgeschottete Umgebungen."},
{"CRA-CSA-CLD-SCAN", "Prüfwerk – Zusätzliche Prüfung", "Prüfung", "Einzelne Prüfung über das Monatskontingent hinaus; nur zu einem aktiven Prüfwerk-Abonnement."},
{"CRA-WBK-CLD-STD", "Werkbank Runner Cloud – Standard", "Monat", "Prüfmaschine für aktive Tests externer Systeme (1 vCPU / 2 GB); Zusatz zu Prüfwerk."},
{"CRA-WBK-CLD-BUS", "Werkbank Runner Cloud – Business", "Monat", "Prüfmaschine mit parallelen Prüfungen (2 vCPU / 4 GB); Zusatz zu Prüfwerk."},
{"CRA-WBK-CLD-ENT", "Werkbank Runner Cloud – Enterprise", "Monat", "Prüfmaschine mit eigenen Prüfmodulen (4 vCPU / 8 GB); Zusatz zu Prüfwerk."},
{"DEV-WP-CLD-STD", "Werkpilot Cloud – Standard", "Monat", "KI-Assistent für Code und SPS-Programme, gemeinsame KI-Kapazität in der EU; je Nutzer und Monat."},
{"DEV-WP-CLD-BUS", "Werkpilot Cloud – Business", "Monat", "Werkpilot mit reservierter KI-Kapazität und Single Sign-on; je Nutzer und Monat."},
{"DEV-WP-CLD-ENT", "Werkpilot Cloud – Enterprise", "Monat", "Werkpilot auf eigener KI-Instanz, optional auf Ihren Code abgestimmt; je Nutzer und Monat."},
{"DEV-WP-OPR-STD", "Werkpilot On-Prem – Standard", "Jahr", "Werkpilot im eigenen Netz, ohne dass Quellcode das Haus verlässt; Jahreslizenz."},
{"DEV-WP-OPR-BUS", "Werkpilot On-Prem – Business", "Jahr", "Werkpilot im eigenen Netz für mittlere Teams; Jahreslizenz."},
{"DEV-WP-OPR-ENT", "Werkpilot On-Prem – Enterprise", "Jahr", "Werkpilot im eigenen Netz für große Entwicklungsorganisationen; Jahreslizenz."},
{"DEV-FWK-CLD-STD", "Firmwerk Cloud – Standard", "Monat", "Reproduzierbare Firmware-Builds mit Stückliste und Nachweis, 10 Umgebungen je Nutzer; je Nutzer und Monat."},
{"DEV-FWK-CLD-BUS", "Firmwerk Cloud – Business", "Monat", "Firmwerk mit beliebig vielen Umgebungen und Team-Freigabe; je Nutzer und Monat."},
{"DEV-FWK-CLD-ENT", "Firmwerk Cloud – Enterprise", "Monat", "Firmwerk mit eigenen Toolchains und LTS-Stand; je Nutzer und Monat."},
{"DEV-FWK-OPR-STD", "Firmwerk On-Prem – Standard", "Jahr", "Firmwerk im eigenen Netz; Jahreslizenz."},
{"DEV-FWK-OPR-BUS", "Firmwerk On-Prem – Business", "Jahr", "Firmwerk im eigenen Netz für größere Teams; Jahreslizenz."},
{"DEV-FWK-OPR-ENT", "Firmwerk On-Prem – Enterprise", "Jahr", "Firmwerk im eigenen Netz für große Organisationen; Jahreslizenz."},
}
}
func uoms() []map[string]any {
out := []map[string]any{}
for _, u := range []string{"Monat", "Jahr", "Prüfung"} {
out = append(out, map[string]any{"doctype": "UOM", "name": u, "uom_name": u, "must_be_whole_number": 1})
}
return out
}
func itemGroupDoc() map[string]any {
return map[string]any{"doctype": "Item Group", "name": itemGroup, "item_group_name": itemGroup, "parent_item_group": "All Item Groups", "is_group": 0}
}
func itemDoc(s sku) map[string]any {
return map[string]any{
"doctype": "Item", "name": s.Code, "item_code": s.Code, "item_name": s.Name,
"item_group": itemGroup, "stock_uom": s.UOM, "description": s.Description,
"is_stock_item": 0, "is_sales_item": 1, "is_purchase_item": 0, "include_item_in_manufacturing": 0,
}
}
// sepaFields put the direct-debit mandate on the Customer: reference, date of
// signature and type (Basislastschrift/CORE or Firmenlastschrift/B2B).
func sepaFields() []map[string]any {
section := customField("Customer", "sepa_section", "SEPA-Lastschriftmandat", "Section Break", "tenant_slug", false)
ref := customField("Customer", "sepa_mandate_reference", "Mandatsreferenz", "Data", "sepa_section", false)
date := customField("Customer", "sepa_mandate_date", "Mandat unterschrieben am", "Date", "sepa_mandate_reference", false)
kind := customField("Customer", "sepa_mandate_type", "Mandatsart", "Select", "sepa_mandate_date", false)
kind["options"] = "\nBasislastschrift (CORE)\nFirmenlastschrift (B2B)"
for _, f := range []map[string]any{section, ref, date, kind} {
f["description"] = "SEPA-Lastschriftmandat des Kunden; von Hand gepflegt."
}
section["collapsible"] = 1
return []map[string]any{section, ref, date, kind}
}
func modeOfPaymentDoc() map[string]any {
return map[string]any{"doctype": "Mode of Payment", "name": "SEPA-Lastschrift", "mode_of_payment": "SEPA-Lastschrift", "type": "Bank", "enabled": 1}
}
+26 -2
View File
@@ -1,7 +1,8 @@
// Package erpsetup applies the live-ERPNext configuration the registry relies
// on (ERP/03 "live configuration"): custom fields that carry the tenant id, the
// Usage Record doctype the outbox writes, and the Frappe Webhooks that drive
// the tenant ladder. Every step checks first and creates only what is missing,
// Usage Record doctype the outbox writes, the sales catalogue (SKU items, units,
// SEPA mandate fields, payment method) and the Frappe Webhooks that drive the
// tenant ladder. Every step checks first and creates only what is missing,
// so it can run again at any time; with DryRun it only reports.
//
// It never submits, cancels or deletes an ERP document.
@@ -72,6 +73,29 @@ func Run(ctx context.Context, cfg Config) ([]Step, error) {
if err := r.ensure(ctx, "DocType", "Usage Record", "doctype Usage Record", usageRecordDoctype()); err != nil {
return r.steps, err
}
// Sales catalogue: units, item group, the SKU items, SEPA mandate fields
// on the Customer and the payment method.
for _, u := range uoms() {
if err := r.ensure(ctx, "UOM", u["name"].(string), "unit "+u["name"].(string), u); err != nil {
return r.steps, err
}
}
if err := r.ensure(ctx, "Item Group", itemGroup, "item group "+itemGroup, itemGroupDoc()); err != nil {
return r.steps, err
}
for _, s := range skus() {
if err := r.ensure(ctx, "Item", s.Code, "item "+s.Code+" ("+s.Name+")", itemDoc(s)); err != nil {
return r.steps, err
}
}
for _, f := range sepaFields() {
if err := r.ensure(ctx, "Custom Field", f["name"].(string), fmt.Sprintf("custom field %s.%s", f["dt"], f["fieldname"]), f); err != nil {
return r.steps, err
}
}
if err := r.ensure(ctx, "Mode of Payment", "SEPA-Lastschrift", "mode of payment SEPA-Lastschrift", modeOfPaymentDoc()); err != nil {
return r.steps, err
}
for _, w := range webhooks(cfg.WebhookURL, cfg.WebhookSecret) {
if err := r.ensureWebhook(ctx, w); err != nil {
return r.steps, err
+70 -4
View File
@@ -10,6 +10,8 @@ import (
"strings"
"sync"
"testing"
"git.breakpilot.com/platform/tenant-registry/internal/store"
)
// fakeFrappe keeps named docs per doctype and a list of webhooks.
@@ -82,8 +84,8 @@ func TestRunCreatesThenIsIdempotent(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if len(steps) != 9 || f.posts != 9 {
t.Fatalf("first run: %d steps, %d creates; want 9/9: %+v", len(steps), f.posts, steps)
if len(steps) != 40 || f.posts != 40 {
t.Fatalf("first run: %d steps, %d creates; want 40/40: %+v", len(steps), f.posts, steps)
}
for _, s := range steps {
if s.Result != "created" {
@@ -99,8 +101,8 @@ func TestRunCreatesThenIsIdempotent(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if f.posts != 9 {
t.Fatalf("second run created %d more docs", f.posts-9)
if f.posts != 40 {
t.Fatalf("second run created %d more docs", f.posts-40)
}
for _, s := range steps {
if !strings.HasPrefix(s.Result, "exists") {
@@ -193,3 +195,67 @@ func TestWebhookDocIsNamed(t *testing.T) {
seen[name] = true
}
}
// Every SKU the registry's catalogue sells exists as an item, with a unit that
// exists too, and the platform fee is there for invoicing.
func TestCatalogueCoversTheRegistrySKUs(t *testing.T) {
want := []string{
"CRA-CSA-CLD-STD", "CRA-CSA-CLD-BUS", "CRA-CSA-CLD-ENT", "CRA-CSA-CLD-SCAN",
"CRA-WBK-CLD-STD", "CRA-WBK-CLD-BUS", "CRA-WBK-CLD-ENT",
"DEV-WP-CLD-STD", "DEV-WP-CLD-BUS", "DEV-WP-CLD-ENT", "DEV-WP-OPR-STD", "DEV-WP-OPR-BUS", "DEV-WP-OPR-ENT",
"DEV-FWK-CLD-STD", "DEV-FWK-CLD-BUS", "DEV-FWK-CLD-ENT", "DEV-FWK-OPR-STD", "DEV-FWK-OPR-BUS", "DEV-FWK-OPR-ENT",
"PLT-CORE-CLD-STD", "PLT-CORE-CLD-BUS", "PLT-CORE-CLD-ENT",
}
units := map[string]bool{}
for _, u := range uoms() {
units[u["name"].(string)] = true
}
have := map[string]sku{}
for _, s := range skus() {
if _, dup := have[s.Code]; dup {
t.Errorf("duplicate %s", s.Code)
}
have[s.Code] = s
if !units[s.UOM] || s.Name == "" || s.Description == "" {
t.Errorf("incomplete item %+v", s)
}
d := itemDoc(s)
if d["is_stock_item"] != 0 || d["is_sales_item"] != 1 || d["item_group"] != itemGroup {
t.Errorf("item doc %v", d)
}
}
for _, code := range want {
if _, ok := have[code]; !ok {
t.Errorf("missing %s", code)
}
}
if len(have) != len(want) {
t.Errorf("%d items, want %d", len(have), len(want))
}
if f := sepaFields(); len(f) != 4 || f[3]["options"] != "\nBasislastschrift (CORE)\nFirmenlastschrift (B2B)" {
t.Errorf("sepa fields %v", f)
}
}
// A SKU added to the registry's catalogue must be added here too, or a sales
// order for it would find no item in ERPNext.
func TestCatalogueMatchesStoreDefaults(t *testing.T) {
have := map[string]bool{}
for _, s := range skus() {
have[s.Code] = true
}
for _, p := range store.DefaultProducts() {
for _, code := range p.SKUs {
if !have[code] {
t.Errorf("%s: SKU %s has no ERPNext item", p.Key, code)
}
}
for _, a := range p.Addons {
for _, code := range a.SKUs {
if !have[code] {
t.Errorf("%s/%s: SKU %s has no ERPNext item", p.Key, a.ID, code)
}
}
}
}
}