feat(erpsetup): Reisekosten expense claim types with SKR04 accounts
ci / shared (pull_request) Successful in 12s
ci / test (pull_request) Successful in 25m44s
ci / image (pull_request) Skipped

Backlog #39 (a)+(b). The 22 Expense Claim Types the Reisekosten app names
(src/config/erpnext-mapping.json; same 22 names, checked), each with its
standard SKR04 account for the company, decided 2026-10-20 and changed
only if the tax advisor books differently: fares 6663, nights 6660, per
diem 6664, mileage 6668, incidentals and own meals 6650, Bewirtung 6640,
Messe/Konferenz 6600, telecom 6805, office supplies 6815, special items
6300. Directors of a GmbH are employees, so no Unternehmer accounts.

Expense Claim gets breakpilot_report_id (unique, read-only), the relay's
idempotency key (#40). A missing account is reported, not created.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Sharang ParnerkarandClaude Opus 5.5 committed 2026-10-20 12:31:25 +02:00
1 parent 174a2f1e01
commit f80a820462
4 files changed
+158 -4

No files matched your search

+4
View File
@@ -181,6 +181,10 @@ func Run(ctx context.Context, cfg Config) ([]Step, error) {
if err := r.einvoice(ctx); err != nil {
return r.steps, err
}
// Travel expenses: Expense Claim Types with SKR04 accounts (reisekosten.go).
if err := r.reisekosten(ctx); 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
+14 -4
View File
@@ -25,15 +25,25 @@ type fakeFrappe struct {
}
// newFake starts with what every ERPNext site has: the company (with its
// abbreviation), the SKR04 accounts erpsetup looks up (3900, 6300, 4700),
// abbreviation), the SKR04 accounts erpsetup looks up (3900, 6300, 4700 and
// the travel expense accounts),
// the company bank account, the tax templates and the e-invoice settings.
func newFake() *fakeFrappe {
return &fakeFrappe{docs: map[string]map[string]map[string]any{
"Company": {companyName: {"name": companyName, "company_name": companyName, "abbr": "BG"}},
"Account": {
"3900 - Passive Rechnungsabgrenzung - BG": {"name": "3900 - Passive Rechnungsabgrenzung - BG", "account_number": "3900", "company": companyName},
"6300 - Sonstige betriebliche Aufwendungen - BG": {"name": "6300 - Sonstige betriebliche Aufwendungen - BG", "account_number": "6300", "company": companyName},
"4700 - Erlösschmälerungen - BG": {"name": "4700 - Erlösschmälerungen - BG", "account_number": "4700", "company": companyName},
"3900 - Passive Rechnungsabgrenzung - BG": {"name": "3900 - Passive Rechnungsabgrenzung - BG", "account_number": "3900", "company": companyName},
"6300 - Sonstige betriebliche Aufwendungen - BG": {"name": "6300 - Sonstige betriebliche Aufwendungen - BG", "account_number": "6300", "company": companyName},
"4700 - Erlösschmälerungen - BG": {"name": "4700 - Erlösschmälerungen - BG", "account_number": "4700", "company": companyName},
"6663 - Reisekosten Arbeitnehmer Fahrtkosten - BG": {"name": "6663 - Reisekosten Arbeitnehmer Fahrtkosten - BG", "account_number": "6663", "company": companyName},
"6660 - Reisekosten Arbeitnehmer Übernachtungsaufwand - BG": {"name": "6660 - Reisekosten Arbeitnehmer Übernachtungsaufwand - BG", "account_number": "6660", "company": companyName},
"6650 - Reisekosten Arbeitnehmer - BG": {"name": "6650 - Reisekosten Arbeitnehmer - BG", "account_number": "6650", "company": companyName},
"6640 - Bewirtungskosten - BG": {"name": "6640 - Bewirtungskosten - BG", "account_number": "6640", "company": companyName},
"6600 - Werbekosten - BG": {"name": "6600 - Werbekosten - BG", "account_number": "6600", "company": companyName},
"6805 - Telefon - BG": {"name": "6805 - Telefon - BG", "account_number": "6805", "company": companyName},
"6815 - Bürobedarf - BG": {"name": "6815 - Bürobedarf - BG", "account_number": "6815", "company": companyName},
"6668 - Kilometergelderstattung Arbeitnehmer - BG": {"name": "6668 - Kilometergelderstattung Arbeitnehmer - BG", "account_number": "6668", "company": companyName},
"6664 - Reisekosten Arbeitnehmer Verpflegungsmehraufwand - BG": {"name": "6664 - Reisekosten Arbeitnehmer Verpflegungsmehraufwand - BG", "account_number": "6664", "company": companyName},
},
"Bank Account": {"Geschäftskonto - Sparkasse": {"name": "Geschäftskonto - Sparkasse", "company": companyName, "is_company_account": 1, "disabled": 0,
"account": "1800 - Bank - BG", "iban": "DE00TEST"}},
+87
View File
@@ -0,0 +1,87 @@
package erpsetup
// Travel expenses (backlog #39): the Reisekosten app hands an approved
// report to ERPNext as an Expense Claim (HRMS). Each line names an Expense
// Claim Type, exactly as in the app's src/config/erpnext-mapping.json, and
// the type carries the expense account per company. The accounts are our
// own choice of the standard SKR04 accounts (decided 2026-10-20), changed
// only if the tax advisor books differently. Managing directors of a GmbH
// are employees, hence the "Reisekosten Arbeitnehmer" accounts.
//
// The report id on the claim (breakpilot_report_id, unique) makes the relay
// idempotent (#40). The company's HR accounts (payable for expense claims,
// employee advances) wait for the tax advisor's expense account.
import (
"context"
"fmt"
)
type expenseType struct{ Name, Account string }
// expenseTypes: the 22 types of the app with their SKR04 account.
func expenseTypes() []expenseType {
return []expenseType{
{"Reisekosten Bahn", "6663"},
{"Reisekosten Flug", "6663"},
{"Reisekosten ÖPNV", "6663"},
{"Reisekosten Taxi", "6663"},
{"Reisekosten Mietwagen", "6663"},
{"Reisekosten Carsharing", "6663"},
{"Reisekosten Kraftstoff", "6663"}, // rental car or car sharing; a private car is covered by the Kilometerpauschale
{"Reisekosten Ladestrom", "6663"},
{"Reisekosten Fähre", "6663"},
{"Reisekosten Übernachtung", "6660"},
{"Reisekosten Verpflegung", "6650"}, // own meals on top of the per diem: wage-tax check (app flag "Sachbezug prüfen")
{"Reisenebenkosten Parken", "6650"},
{"Reisenebenkosten Maut", "6650"},
{"Reisenebenkosten Gebühren", "6650"},
{"Reisenebenkosten Sonstige", "6650"},
{"Bewirtung", "6640"}, // 30 % not deductible (6644), split by the tax advisor
{"Messe / Konferenz", "6600"}, // trade fairs; pure training would be 6821
{"Telekommunikation", "6805"},
{"Bürobedarf", "6815"},
{"Sonderausgabe (Prüfung)", "6300"}, // always checked by hand
{"Kilometerpauschale", "6668"},
{"Verpflegungsmehraufwand (steuerfrei)", "6664"},
}
}
func reportIDField() map[string]any {
f := customField("Expense Claim", "breakpilot_report_id", "Reisekostenabrechnung", "Data", "employee_name", true)
f["read_only"] = 1
f["description"] = "Von der Reisekosten-App gesetzt: die Abrechnung, aus der diese Spesenabrechnung stammt. Nicht ändern."
return f
}
func (r *runner) reisekosten(ctx context.Context) error {
f := reportIDField()
if err := r.ensure(ctx, "Custom Field", f["name"].(string), fmt.Sprintf("custom field %s.%s", f["dt"], f["fieldname"]), f); err != nil {
return err
}
accounts := map[string]string{} // SKR04 number → account name, "" when missing
for _, t := range expenseTypes() {
if err := r.ensure(ctx, "Expense Claim Type", t.Name, "expense claim type "+t.Name,
map[string]any{"doctype": "Expense Claim Type", "name": t.Name, "expense_type": t.Name}); err != nil {
return err
}
account, seen := accounts[t.Account]
if !seen {
a, err := r.findAccount(ctx, t.Account)
if err != nil {
return err
}
account, accounts[t.Account] = a, a
}
what := "expense claim type " + t.Name + " account " + t.Account
if account == "" {
r.record(what, "missing (not created)")
continue
}
if err := r.ensureChildRow(ctx, "Expense Claim Type", t.Name, "accounts", what,
map[string]any{"company": companyName}, map[string]any{"default_account": account}); err != nil {
return err
}
}
return nil
}
+53
View File
@@ -0,0 +1,53 @@
package erpsetup
import (
"context"
"fmt"
"net/http/httptest"
"strings"
"testing"
)
func TestReisekostenExpenseTypes(t *testing.T) {
f := newFake()
srv := httptest.NewServer(f)
defer srv.Close()
if _, err := Run(context.Background(), cfg(srv.URL)); err != nil {
t.Fatal(err)
}
if n := len(f.docs["Expense Claim Type"]); n != 22 {
t.Fatalf("%d expense claim types, want 22", n)
}
for _, et := range expenseTypes() {
d := f.docs["Expense Claim Type"][et.Name]
rows, _ := d["accounts"].([]any)
if len(rows) != 1 {
t.Errorf("%s: account rows %v", et.Name, rows)
continue
}
row := rows[0].(map[string]any)
if row["company"] != companyName || !strings.HasPrefix(fmt.Sprint(row["default_account"]), et.Account+" - ") {
t.Errorf("%s: %v, want %s", et.Name, row, et.Account)
}
}
cf := f.docs["Custom Field"]["Expense Claim-breakpilot_report_id"]
if cf == nil || cf["unique"] != float64(1) || cf["read_only"] != float64(1) {
t.Errorf("report id field %v", cf)
}
}
// The names are the app's Expense Claim Types (src/config/erpnext-mapping.json
// in the Reisekosten app): no duplicates, and the GmbH's directors book on
// the employee travel accounts, never the owner (Unternehmer) ones.
func TestExpenseTypesAreUniqueAndUseEmployeeAccounts(t *testing.T) {
seen := map[string]bool{}
for _, et := range expenseTypes() {
if seen[et.Name] {
t.Errorf("duplicate %s", et.Name)
}
seen[et.Name] = true
if et.Account >= "6670" && et.Account <= "6680" {
t.Errorf("%s on an Unternehmer account %s", et.Name, et.Account)
}
}
}