From 7430c3a4bb1422fb9efb510e03156111e806b879 Mon Sep 17 00:00:00 2001 From: Sharang Parnerkar <30073382+mighty840@users.noreply.github.com> Date: Mon, 9 Nov 2026 13:32:17 +0100 Subject: [PATCH] fix(contracts): legal form in ag_name, no LBs from preview grants ag_name is the company name with the form's label of its legal form ("Muster GmbH"), not appended when the name already ends with it (case-insensitive; "UG" counts for the UG), nor for Einzelunternehmen, Sonstige or no form. The e.V. is written without "(Verein)". A staff preview grant no longer brings in a product's Leistungsbeschreibung: only enabled, unexpired bookings and trials count. Co-Authored-By: Claude Opus 5.5 --- internal/server/contract_documents.go | 39 +++++++++++++++++++--- internal/server/contract_documents_test.go | 37 ++++++++++++++++++-- 2 files changed, 68 insertions(+), 8 deletions(-) diff --git a/internal/server/contract_documents.go b/internal/server/contract_documents.go index 5a5a982..cfcbaaa 100644 --- a/internal/server/contract_documents.go +++ b/internal/server/contract_documents.go @@ -62,13 +62,14 @@ func (s *Server) contractCatalogue() *contractdocs.Catalogue { } // contractHoldings is what decides a tenant's Leistungsbeschreibungen: the -// products it may use now (booked, on trial, or an unexpired preview grant) -// and the managed services it has (in any status: the contract stands while -// the service is provisioned, restricted or halted). +// products it has booked or on trial now (enabled, not expired; a staff +// preview grant is no booking and brings in no Leistungsbeschreibung) and the +// managed services it has (in any status: the contract stands while the +// service is provisioned, restricted or halted). func contractHoldings(tps []store.TenantProduct, services []store.ManagedService, now time.Time) contractdocs.Holdings { h := contractdocs.Holdings{Products: map[string]bool{}, ManagedServices: map[string]bool{}} for _, tp := range tps { - if !tp.Enabled || (tp.ExpiresAt != nil && !tp.ExpiresAt.After(now)) || (tp.Preview && !tp.PreviewActive(now)) { + if tp.Preview || !tp.Enabled || (tp.ExpiresAt != nil && !tp.ExpiresAt.After(now)) { continue } h.Products[tp.Product] = true @@ -224,7 +225,7 @@ func (s *Server) adminAVVValues(w http.ResponseWriter, r *http.Request) { writeError(w, http.StatusInternalServerError, "internal", "the company profile could not be read") return } - v.Name = profile["companyName"] + v.Name = companyWithLegalForm(profile["companyName"], profile["legalForm"]) v.Anschrift = joinNonEmpty(", ", profile["headquartersStreet"], joinNonEmpty(" ", profile["headquartersZip"], profile["headquartersCity"]), @@ -286,6 +287,34 @@ func (s *Server) companyProfileAnswers(ctx context.Context, tenantID string) (ma return out, nil } +// legalFormNames are the company profile's legal forms (portal schema +// companyProfile.ts, LEGAL_FORM) as written after the company name; the +// first is the form's label, the others are spellings that count as already +// written. "Einzelunternehmen" and "Sonstige" are not appended; the e.V. is +// written without the form's "(Verein)". +var legalFormNames = map[string][]string{ + "gbr": {"GbR"}, "ohg": {"OHG"}, "kg": {"KG"}, "gmbh": {"GmbH"}, + "ug": {"UG (haftungsbeschränkt)", "UG"}, "ag": {"AG"}, "gmbh_co_kg": {"GmbH & Co. KG"}, + "ev": {"e.V."}, "stiftung": {"Stiftung"}, +} + +// companyWithLegalForm is the company name with its legal form ("Muster +// GmbH"), unless the name already ends with it (case-insensitive), the form +// is not appended, or there is no name. +func companyWithLegalForm(name, form string) string { + names := legalFormNames[form] + if name == "" || len(names) == 0 { + return name + } + lower := strings.ToLower(name) + for _, n := range names { + if strings.HasSuffix(lower, strings.ToLower(n)) { + return name + } + } + return name + " " + names[0] +} + // profileCountry is the country as written in the address: none for // Germany, the name for a listed code, the free text for "other". func profileCountry(code, other string) string { diff --git a/internal/server/contract_documents_test.go b/internal/server/contract_documents_test.go index f848898..209b52e 100644 --- a/internal/server/contract_documents_test.go +++ b/internal/server/contract_documents_test.go @@ -66,7 +66,7 @@ func catalogueWithAVV() (*contractdocs.Catalogue, []byte) { avv := []byte("%PDF-1.7 synthetic AVV master") lb := []byte("%PDF-1.7 synthetic platform LB") return contractdocs.NewCatalogue( - contractdocs.Doc{ID: "lb-plattform", Kind: contractdocs.KindLB, Title: "Leistungsbeschreibung Breakpilot", Version: "1.0.0", Date: "06.11.2026", PDF: lb, SHA256: contractdocs.Sum(lb), File: "LB.pdf"}, + contractdocs.Doc{ID: "lb-plattform", Kind: contractdocs.KindLB, Title: "Leistungsbeschreibung Breakpilot Plattform", Version: "1.0.0", Date: "06.11.2026", PDF: lb, SHA256: contractdocs.Sum(lb), File: "LB.pdf"}, contractdocs.Doc{ID: "avv", Kind: contractdocs.KindAVV, Title: "Auftragsverarbeitungsvertrag", Version: "1.0.0", Date: "01.12.2026", PDF: avv, SHA256: contractdocs.Sum(avv), File: "AVV.pdf"}, ), avv } @@ -93,7 +93,7 @@ func TestContractHoldings(t *testing.T) { } services := []store.ManagedService{{Kind: store.ManagedServiceKindGit, Status: store.ManagedServiceHalted}} h := contractHoldings(tps, services, now) - for p, want := range map[string]bool{"pruefwerk": true, "werkpilot": true, "firmwerk": false, "werkmeister": true, "compliance": false, "other": false, "edge": false} { + for p, want := range map[string]bool{"pruefwerk": true, "werkpilot": true, "firmwerk": false, "werkmeister": false, "compliance": false, "other": false, "edge": false} { if h.Products[p] != want { t.Errorf("%s: %v", p, h.Products[p]) } @@ -453,7 +453,7 @@ func TestAdminAVVValues(t *testing.T) { t.Fatalf("empty: %d %s", code, raw) } - saveProfile(t, f, `{"companyName":"Muster Maschinenbau GmbH","legalForm":"gmbh","headquartersStreet":"Musterstraße 1", + saveProfile(t, f, `{"companyName":"Muster Maschinenbau","legalForm":"gmbh","headquartersStreet":"Musterstraße 1", "headquartersZip":"12345","headquartersCity":" Musterstadt ","headquartersCountry":"DE","legalContactEmail":"recht@muster.test","employees":12}`) f.kc.Members["acme"] = append(f.kc.Members["acme"], keycloak.OrgMember{UserID: "u-ceo", Email: "ceo@muster.test", FirstName: "Erika", LastName: "Mustermann", Enabled: true}, @@ -560,6 +560,37 @@ func (failingProfileStore) GetCompanyProfile(context.Context, string) (*store.Co return nil, errContractStore } +// The legal form follows the name as the form labels it, once. +func TestCompanyWithLegalForm(t *testing.T) { + for _, c := range []struct{ name, form, want string }{ + {"Muster Maschinenbau", "gmbh", "Muster Maschinenbau GmbH"}, + {"Muster Maschinenbau GmbH", "gmbh", "Muster Maschinenbau GmbH"}, + {"Muster Maschinenbau gmbh", "gmbh", "Muster Maschinenbau gmbh"}, + {"Muster", "ug", "Muster UG (haftungsbeschränkt)"}, + {"Muster UG (haftungsbeschränkt)", "ug", "Muster UG (haftungsbeschränkt)"}, + {"Muster UG", "ug", "Muster UG"}, + {"Muster", "ag", "Muster AG"}, + {"Muster", "gmbh_co_kg", "Muster GmbH & Co. KG"}, + {"Muster GmbH & Co. KG", "gmbh_co_kg", "Muster GmbH & Co. KG"}, + {"Muster", "ohg", "Muster OHG"}, + {"Muster", "kg", "Muster KG"}, + {"Muster", "gbr", "Muster GbR"}, + {"Musterverein", "ev", "Musterverein e.V."}, + {"Musterverein e.V.", "ev", "Musterverein e.V."}, + {"Muster", "stiftung", "Muster Stiftung"}, + {"Muster-Stiftung", "stiftung", "Muster-Stiftung"}, + {"Erika Mustermann", "einzelunternehmen", "Erika Mustermann"}, + {"Muster", "other", "Muster"}, + {"Muster", "", "Muster"}, + {"Muster", "unknown", "Muster"}, + {"", "gmbh", ""}, + } { + if got := companyWithLegalForm(c.name, c.form); got != c.want { + t.Errorf("%q + %q: %q, want %q", c.name, c.form, got, c.want) + } + } +} + func TestGermanList(t *testing.T) { for want, in := range map[string][]string{"": nil, "A": {"A"}, "A und B": {"A", "B"}, "A, B und C": {"A", "B", "C"}} { if got := germanList(in); got != want {