feat(erpsetup): AB and invoice after the legal review (#59)
ci / shared (push) Successful in 12s
ci / test (push) Successful in 24m9s
ci / image (push) Successful in 34s

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DmXxNULoSNPvjF7buKipsB
This commit was merged in pull request #59.
This commit is contained in:
sharangandClaude Opus 5.5 committed 2026-09-30 16:26:47 +00:00
1 parent 60f20e6419
commit 6141e45811
4 files changed
+118 -11

No files matched your search

+19 -4
View File
@@ -177,6 +177,11 @@ var documentHTML = brand.Replace(`{%- set is_inv = doc.doctype == "Sales Invoice
{%- set mandate = frappe.db.get_value("Customer", cust, ["sepa_mandate_reference", "sepa_mandate_type"], as_dict=1) if doc.doctype != "Quotation" or doc.quotation_to == "Customer" else None -%}
{%- set sepa = doc.payment_schedule and doc.payment_schedule[0].mode_of_payment == "SEPA-Lastschrift" -%}
{%- set tpl = doc.taxes_and_charges or "" -%}
{%- set order_no = (doc.items[0].get("sales_order") if is_inv and doc.items else None) -%}
{%- set service_start = doc.get("from_date") or doc.get("delivery_date") -%}
{%- set units = doc.items | map(attribute="uom") | list if doc.items else [] -%}
{%- set interval = "monatlich" if units and units | select("equalto", "Monat") | list | length == units | length else ("jährlich" if units and units | select("equalto", "Jahr") | list | length == units | length else "") -%}
{%- set has_mandate = mandate and mandate.sepa_mandate_reference -%}
{%- set period_from = doc.get("from_date") or (doc.items[0].get("service_start_date") if doc.items else None) -%}
{%- set period_to = doc.get("to_date") or (doc.items[0].get("service_end_date") if doc.items else None) -%}
{%- if letter_head and not no_letterhead %}<div class="letter-head">{{ letter_head }}</div>{% endif %}
@@ -199,6 +204,8 @@ var documentHTML = brand.Replace(`{%- set is_inv = doc.doctype == "Sales Invoice
.bp .totals td { padding: 2px 0 2px 16px; }
.bp .totals tr.grand td { border-top: 1px solid $INK; font-weight: bold; font-size: 10.5pt; padding-top: 5px; }
.bp .note { margin-top: 18px; font-size: 8.5pt; }
.bp .sepa-head { margin: 10px 0 2px 0; }
.bp .note p.sepa-head + p { margin-top: 0; }
.bp .muted { color: $MUTED; }
</style>
<div class="bp">
@@ -218,7 +225,11 @@ var documentHTML = brand.Replace(`{%- set is_inv = doc.doctype == "Sales Invoice
<table class="meta" style="margin-left:auto;">
<tr><td class="k">Nummer</td><td class="nw"><b>{{ doc.name }}</b></td></tr>
<tr><td class="k">Datum</td><td>{{ frappe.utils.formatdate(doc_date) }}</td></tr>
<tr><td class="k">Kundennummer</td><td>{{ cust }}</td></tr>
{%- if cust and cust != doc.customer_name %}<tr><td class="k">Kundennummer</td><td>{{ cust }}</td></tr>{% endif %}
{%- if is_inv and order_no %}<tr><td class="k">Auftragsnummer</td><td class="nw">{{ order_no }}</td></tr>{% endif %}
{%- if doc.get("vertragsgrundlage") %}<tr><td class="k">Vertragsgrundlage</td><td>{{ doc.vertragsgrundlage }}</td></tr>{% endif %}
{%- if is_so and service_start %}<tr><td class="k">Leistungsbeginn</td><td>{{ frappe.utils.formatdate(service_start) }}</td></tr>{% endif %}
{%- if is_so and interval %}<tr><td class="k">Abrechnungsintervall</td><td>{{ interval }}</td></tr>{% endif %}
{%- if doc.get("tax_id") %}<tr><td class="k">Ihre USt-IdNr.</td><td>{{ doc.tax_id }}</td></tr>{% endif %}
{%- if is_inv and not doc.is_return %}<tr><td class="k">Fällig am</td><td>{{ frappe.utils.formatdate(doc.due_date) }}</td></tr>{% endif %}
{%- if doc.doctype == "Quotation" and doc.valid_till %}<tr><td class="k">Gültig bis</td><td>{{ frappe.utils.formatdate(doc.valid_till) }}</td></tr>{% endif %}
@@ -266,14 +277,18 @@ var documentHTML = brand.Replace(`{%- set is_inv = doc.doctype == "Sales Invoice
<p>Nicht im Inland steuerbare Leistung.</p>
{%- endif %}
{%- if is_inv and not doc.is_return %}
{%- if sepa %}
{%- if sepa and has_mandate %}
{%- set creditor = frappe.db.get_value("Company", doc.company, "sepa_creditor_id") %}
<p>Wir ziehen den Rechnungsbetrag von&nbsp;<b>{{ doc.get_formatted("rounded_total" if doc.rounded_total else "grand_total") }}</b> am <b>{{ frappe.utils.formatdate(doc.due_date) }}</b> per SEPA-{{ "Firmenlastschrift" if mandate and mandate.sepa_mandate_type and "B2B" in mandate.sepa_mandate_type else "Lastschrift" }} von Ihrem Konto ein{% if creditor or (mandate and mandate.sepa_mandate_reference) %} (Gläubiger-ID {{ creditor or "–" }}, Mandatsreferenz {{ (mandate and mandate.sepa_mandate_reference) or "–" }}){% endif %}. Bitte sorgen Sie für ausreichende Deckung.</p>
<p class="sepa-head"><b>SEPA-Lastschrift</b></p>
<p>Den Rechnungsbetrag von <b>{{ doc.get_formatted("rounded_total" if doc.rounded_total else "grand_total") }}</b> ziehen wir am <b>{{ frappe.utils.formatdate(doc.due_date) }}</b> auf Grundlage des erteilten SEPA-Lastschriftmandats ein.<br>
{%- if creditor %}Gläubiger-Identifikationsnummer: {{ creditor }}<br>{% endif %}
Mandatsreferenz: {{ mandate.sepa_mandate_reference }}<br>
Bitte sorgen Sie für ausreichende Kontodeckung.</p>
{%- else %}
<p>Bitte überweisen Sie den Rechnungsbetrag bis zum <b>{{ frappe.utils.formatdate(doc.due_date) }}</b> unter Angabe der Rechnungsnummer <b>{{ doc.name }}</b>.</p>
{%- endif %}
{%- elif not is_inv and sepa %}
<p>Zahlung per SEPA-Lastschrift nach Rechnungsstellung.</p>
<p>Zahlungsart: SEPA-Lastschrift {{ "gemäß erteiltem SEPA-Lastschriftmandat" if has_mandate else "nach Erteilung eines gültigen SEPA-Lastschriftmandats" }}.</p>
{%- endif %}
{%- if doc.get("terms") %}<div class="muted">{{ doc.terms }}</div>{% endif %}
<p class="muted">Vielen Dank für Ihr Vertrauen.</p>
+57 -1
View File
@@ -24,7 +24,7 @@ func skus() []sku {
{"PLT-CORE-CLD-STD", "BreakPilot Plattform – Starter", "Monat", "Arbeitsbereich mit Anmeldung, Team und Rechnungen: bis 25 Nutzer, bis 3 Produkte, Standard-Support.", 290},
{"PLT-CORE-CLD-BUS", "BreakPilot Plattform – Growth", "Monat", "Arbeitsbereich für bis 100 Nutzer, beliebig viele Produkte, monatlicher Nutzungsbericht, vorrangiger Support.", 790},
{"PLT-CORE-CLD-ENT", "BreakPilot Plattform – Enterprise", "Monat", "Arbeitsbereich ohne Nutzergrenze, persönliche Betreuung, individuelle Verträge (AVV), Wahl der EU-Region.", 1990},
{"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.", 1490},
{"CRA-CSA-CLD-STD", "Prüfwerk Cloud – Standard", "Monat", "Automatisierte Cybersecurity-Analyse von Quellcode, Firmware und SPS-Programmen für CRA-bezogene Compliance-Prozesse: 5 Prüfobjekte, 50 Prüfungen im Monat, monatliches Nachweispaket.", 1490},
{"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.", 3990},
{"CRA-CSA-CLD-ENT", "Prüfwerk Cloud – Enterprise", "Monat", "Prüfwerk ohne Obergrenzen, eigener Kontrollkatalog, Nachweisexport für abgeschottete Umgebungen.", 9900},
{"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.", 12},
@@ -109,3 +109,59 @@ func itemPriceDoc(s sku) map[string]any {
"price_list_rate": s.Price, "currency": "EUR", "selling": 1,
}
}
// Customers created from now on are numbered K-00001, K-00002, … (the
// number is what documents show as "Kundennummer"); existing customers keep
// their name. The registry stores whatever name ERPNext assigns.
const customerSeries = "K-.#####"
func customerNumbering() (settings map[string]any, setters []map[string]any) {
settings = map[string]any{"doctype": "Selling Settings", "name": "Selling Settings", "cust_master_name": "Naming Series"}
setter := func(prop string) map[string]any {
return map[string]any{
"doctype": "Property Setter", "name": "Customer-naming_series-" + prop,
"doctype_or_field": "DocField", "doc_type": "Customer", "field_name": "naming_series",
"property": prop, "property_type": "Text", "value": customerSeries,
}
}
return settings, []map[string]any{setter("options"), setter("default")}
}
// paymentTerms21 is the default for new customers: SEPA direct debit 21 days
// after the invoice date, so the invoice (the SEPA pre-notification) reaches
// the customer at least 14 days before the debit.
const paymentTerms21 = "SEPA-Lastschrift 21 Tage"
func paymentTermDoc() map[string]any {
return map[string]any{
"doctype": "Payment Term", "name": paymentTerms21, "payment_term_name": paymentTerms21,
"invoice_portion": 100, "mode_of_payment": "SEPA-Lastschrift",
"due_date_based_on": "Day(s) after invoice date", "credit_days": 21,
"description": "Der Rechnungsbetrag wird per SEPA-Lastschrift von Ihrem Konto eingezogen.",
}
}
func paymentTemplateDoc() map[string]any {
return map[string]any{
"doctype": "Payment Terms Template", "name": paymentTerms21, "template_name": paymentTerms21,
"terms": []map[string]any{{
"payment_term": paymentTerms21, "invoice_portion": 100, "mode_of_payment": "SEPA-Lastschrift",
"due_date_based_on": "Day(s) after invoice date", "credit_days": 21,
"description": "Der Rechnungsbetrag wird per SEPA-Lastschrift von Ihrem Konto eingezogen.",
}},
}
}
// contractBasisFields: "Vertragsgrundlage" on order and invoice, filled by
// hand for now (e.g. "SaaS-Vertrag vom 30.09.2026"); printed only when set.
func contractBasisFields() []map[string]any {
out := []map[string]any{}
for _, dt := range []string{"Sales Order", "Sales Invoice"} {
f := customField(dt, "vertragsgrundlage", "Vertragsgrundlage", "Data", "po_no", false)
f["description"] = "Z. B. \"SaaS-Vertrag vom 30.09.2026\". Erscheint auf Auftragsbestätigung und Rechnung."
f["allow_on_submit"] = 0
delete(f, "no_copy") // carried from the order to the invoice
out = append(out, f)
}
return out
}
+28 -1
View File
@@ -85,7 +85,9 @@ func Run(ctx context.Context, cfg Config) ([]Step, error) {
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 {
// The description is the product wording on every document (Angebot,
// Auftragsbestätigung, Rechnung) and follows the catalogue here.
if err := r.ensureFields(ctx, "Item", s.Code, "item "+s.Code+" ("+s.Name+")", itemDoc(s), "description"); err != nil {
return r.steps, err
}
}
@@ -108,6 +110,31 @@ func Run(ctx context.Context, cfg Config) ([]Step, error) {
return r.steps, err
}
}
// Customer numbers, payment terms and the contract basis (portal#66/#67).
settings, custSetters := customerNumbering()
if err := r.ensureFields(ctx, "Selling Settings", "Selling Settings", "customer naming by series "+customerSeries, settings, "cust_master_name"); err != nil {
return r.steps, err
}
for _, ps := range custSetters {
if err := r.ensureValue(ctx, "Property Setter", ps["name"].(string), "customer number range ("+ps["property"].(string)+") "+customerSeries, ps); err != nil {
return r.steps, err
}
}
if err := r.ensure(ctx, "Payment Term", paymentTerms21, "payment term "+paymentTerms21, paymentTermDoc()); err != nil {
return r.steps, err
}
if err := r.ensure(ctx, "Payment Terms Template", paymentTerms21, "payment terms template "+paymentTerms21, paymentTemplateDoc()); err != nil {
return r.steps, err
}
if err := r.ensureFields(ctx, "Company", companyName, "company default payment terms "+paymentTerms21,
map[string]any{"doctype": "Company", "name": companyName, "payment_terms": paymentTerms21}, "payment_terms"); err != nil {
return r.steps, err
}
for _, f := range contractBasisFields() {
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
}
}
// Documents in the BreakPilot look: creditor id field, company address,
// letter head, print formats, invoice e-mail and the defaults.
for _, f := range brandingFields() {
+14 -5
View File
@@ -136,8 +136,8 @@ func TestRunCreatesThenIsIdempotent(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if len(steps) != 76 || f.posts != 76 {
t.Fatalf("first run: %d steps, %d creates; want 76/76: %+v", len(steps), f.posts, steps)
if len(steps) != 84 || f.posts != 84 {
t.Fatalf("first run: %d steps, %d creates; want 84/84: %+v", len(steps), f.posts, steps)
}
for _, s := range steps {
if s.Result != "created" {
@@ -153,8 +153,8 @@ func TestRunCreatesThenIsIdempotent(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if f.posts != 76 {
t.Fatalf("second run created %d more docs", f.posts-76)
if f.posts != 84 {
t.Fatalf("second run created %d more docs", f.posts-84)
}
for _, s := range steps {
if !strings.HasPrefix(s.Result, "exists") {
@@ -450,7 +450,7 @@ func TestEverySKUHasAListPrice(t *testing.T) {
// § 14 Abs. 4 UStG and § 35a GmbHG: what the documents must show.
func TestDocumentsCarryTheLegalDetails(t *testing.T) {
for _, want := range []string{"Leistungszeitraum", "Leistungsdatum entspricht dem Rechnungsdatum", "USt-IdNr.", "doc.taxes", "net_total", "grand_total", "Reverse Charge", "Mandatsreferenz", "Gläubiger-ID", "doc.customer_address", `ca.country != "Germany"`, "{{ letter_head }}", `id="footer-html"`} {
for _, want := range []string{"Leistungszeitraum", "Leistungsdatum entspricht dem Rechnungsdatum", "USt-IdNr.", "doc.taxes", "net_total", "grand_total", "Reverse Charge", "Mandatsreferenz", "Gläubiger-Identifikationsnummer", "Leistungsbeginn", "Abrechnungsintervall", "Vertragsgrundlage", "Auftragsnummer", "nach Erteilung eines gültigen SEPA-Lastschriftmandats", "gemäß erteiltem SEPA-Lastschriftmandat", "cust != doc.customer_name", "doc.customer_address", `ca.country != "Germany"`, "{{ letter_head }}", `id="footer-html"`} {
if !strings.Contains(documentHTML, want) {
t.Errorf("document template lacks %q", want)
}
@@ -466,3 +466,12 @@ func TestDocumentsCarryTheLegalDetails(t *testing.T) {
}
}
}
// portal#66/#67: no product is described as a legal CRA check (RDG boundary).
func TestProductWordingIsNoLegalCheck(t *testing.T) {
for _, s := range skus() {
if strings.Contains(s.Description, "CRA-Prüfung") || strings.Contains(s.Name, "CRA-Prüfung") {
t.Errorf("%s: %q", s.Code, s.Description)
}
}
}