feat(onboarding): minimal input: orgnr + moms period is the whole ask (#1952)
* feat(onboarding): minimal input: orgnr + moms period is the whole ask
Two fixes from the third E2E attempt (2026-08-26):
1. accounting_method is now optional in CompanySetupSchema and defaults by
form in planCompanySetup: aktiebolag = accrual (the norm), enskild
firma = cash (the common small-EF choice; legal under 3 MSEK, BFL 4
kap 4 paragraf). The plan flags the default (resolved.accountingMethodDefaulted)
and gnubok_create_company's preview carries accounting_method_defaulted
so the readback names it and the user overrides in the same 'ja'.
Never silent: the preview is the checkpoint. Applies to the MCP tool
and POST /api/v1/companies (additive; response shows the resolved
value). The lookup tool's still_to_ask no longer lists it.
2. The agent refused a real orgnr because the user said 'nytt bolag' and
the registry showed an established company ('Stopp. Numret matchar
inte ett nytt bolag'): lookup instructions now state that an
established company with F-skatt/VAT is the NORMAL case (new = new to
Accounted) and the orgnr is never second-guessed for looking
established.
Skill + plugin (v1.2.1) updated; API skill regenerated; DECISIONS.md entry.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
* fix(onboarding): surface the kontantmetod 3-MSEK condition on the defaulted cash method
Compliance-review finding on #1952: the EF cash default carries a legal
eligibility condition (turnover normally under 3 MSEK, BFL 4 kap 4 §)
that a client not reading the onboarding skill would never see. The
create preview now carries accounting_method_note with the condition
whenever cash was defaulted, and the v1 pitfall states it for API
integrators. The registry cannot verify turnover, so the confirm-time
human check is the gate; the default itself stays (a brand-new EF has
zero turnover by definition).
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
---------
Co-authored-by: Jakob Wennberg <311770904+jakobwennberg-oss@users.noreply.github.com>
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5
Jakob Wennberg
parent
4ac7b45c8a
commit
4af7469523
@@ -34,6 +34,41 @@ describe('CompanySetupSchema', () => {
|
||||
expect(result.success).toBe(true)
|
||||
})
|
||||
|
||||
it('defaults an omitted accounting_method by form and flags it in the plan', () => {
|
||||
// Minimal-input decision 2026-08-26: orgnr + moms period is the whole ask.
|
||||
const ab = CompanySetupSchema.safeParse({ ...base, accounting_method: undefined })
|
||||
expect(ab.success).toBe(true)
|
||||
if (ab.success) {
|
||||
const plan = planCompanySetup(ab.data)
|
||||
expect(plan.ok).toBe(true)
|
||||
if (plan.ok) {
|
||||
expect(plan.resolved).toEqual({ accountingMethod: 'accrual', accountingMethodDefaulted: true })
|
||||
expect(plan.input.settings.accounting_method).toBe('accrual')
|
||||
}
|
||||
}
|
||||
|
||||
const ef = CompanySetupSchema.safeParse({
|
||||
...base,
|
||||
entity_type: 'enskild_firma',
|
||||
accounting_method: undefined,
|
||||
})
|
||||
expect(ef.success).toBe(true)
|
||||
if (ef.success) {
|
||||
const plan = planCompanySetup(ef.data)
|
||||
expect(plan.ok && plan.resolved.accountingMethod).toBe('cash')
|
||||
}
|
||||
})
|
||||
|
||||
it('an explicit accounting_method always wins over the form default', () => {
|
||||
const parsed = CompanySetupSchema.safeParse({ ...base, accounting_method: 'cash' })
|
||||
expect(parsed.success).toBe(true)
|
||||
if (parsed.success) {
|
||||
const plan = planCompanySetup(parsed.data)
|
||||
expect(plan.ok && plan.resolved.accountingMethod).toBe('cash')
|
||||
expect(plan.ok && plan.resolved.accountingMethodDefaulted).toBe(false)
|
||||
}
|
||||
})
|
||||
|
||||
it('refuses a VAT-registered company without an org number (invoice momsregistreringsnummer)', () => {
|
||||
const result = CompanySetupSchema.safeParse({ ...base, org_number: undefined })
|
||||
expect(result.success).toBe(false)
|
||||
|
||||
@@ -29,7 +29,15 @@ export const CompanySetupSchema = z
|
||||
org_number: z.string().trim().min(1).max(20).optional(),
|
||||
vat_registered: z.boolean(),
|
||||
moms_period: z.enum(['monthly', 'quarterly', 'yearly']).nullable().optional(),
|
||||
accounting_method: z.enum(['accrual', 'cash']),
|
||||
/**
|
||||
* Optional since 2026-08-26 (founder call: minimal onboarding input is
|
||||
* orgnr + moms period). When omitted it defaults by form in
|
||||
* planCompanySetup: aktiebolag → 'accrual' (the norm; kontantmetoden is
|
||||
* rare for AB), enskild firma → 'cash' (the common small-EF choice;
|
||||
* legal below 3 MSEK turnover, BFL 4 kap 4 §). The default is flagged in
|
||||
* the plan so previews present it for confirmation, never silently.
|
||||
*/
|
||||
accounting_method: z.enum(['accrual', 'cash']).optional(),
|
||||
/** Godkänd för F-skatt. Explicit on purpose: never assumed (SE-R-005 risk). */
|
||||
f_skatt: z.boolean(),
|
||||
/** 1-12. Ignored for enskild firma (always calendar year). */
|
||||
@@ -103,6 +111,8 @@ export type CompanySetupPlan =
|
||||
input: Omit<CreateCompanyInput, 'ticLookup'>
|
||||
/** What the fiscal period resolved to, for previews. */
|
||||
fiscalPeriod: { startDate: string; endDate: string; name: string }
|
||||
/** Values planCompanySetup filled in, so previews can flag them. */
|
||||
resolved: { accountingMethod: 'accrual' | 'cash'; accountingMethodDefaulted: boolean }
|
||||
}
|
||||
| { ok: false; error: string }
|
||||
|
||||
@@ -114,6 +124,7 @@ export function planCompanySetup(setup: CompanySetup): CompanySetupPlan {
|
||||
const isEf = setup.entity_type === 'enskild_firma'
|
||||
const firstYear = setup.first_fiscal_year
|
||||
const startMonth = isEf ? 1 : (setup.fiscal_year_start_month ?? 1)
|
||||
const accountingMethod = setup.accounting_method ?? (isEf ? 'cash' : 'accrual')
|
||||
|
||||
const settings: Record<string, unknown> = {
|
||||
entity_type: setup.entity_type,
|
||||
@@ -122,7 +133,7 @@ export function planCompanySetup(setup: CompanySetup): CompanySetupPlan {
|
||||
vat_registered: setup.vat_registered,
|
||||
vat_number: setup.vat_registered ? deriveSwedishVatNumber(setup.org_number ?? null) : null,
|
||||
moms_period: setup.vat_registered ? setup.moms_period ?? null : null,
|
||||
accounting_method: setup.accounting_method,
|
||||
accounting_method: accountingMethod,
|
||||
f_skatt: setup.f_skatt,
|
||||
// Enskild firma is calendar-year by law, with or without a first year.
|
||||
fiscal_year_start_month: isEf ? 1 : firstYear ? nextMonthAfter(firstYear.end) : startMonth,
|
||||
@@ -151,6 +162,10 @@ export function planCompanySetup(setup: CompanySetup): CompanySetupPlan {
|
||||
fiscalPeriod: { startDate: period.startStr, endDate: period.endStr, name: period.periodName },
|
||||
},
|
||||
fiscalPeriod: { startDate: period.startStr, endDate: period.endStr, name: period.periodName },
|
||||
resolved: {
|
||||
accountingMethod,
|
||||
accountingMethodDefaulted: setup.accounting_method === undefined,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user