feat(arsredovisning): manual override for medelantal anställda (Not 2) (#2420)
* feat(arsredovisning): manual override for medelantal anstallda (Not 2) Why the problem occurred: the ÅRL 5:20 § note was derived only from the employees table, and most aktiebolag that book salary never create a Löner employee record (hand-booked salary, SIE import, migrated history). In prod 148 of 195 aktiebolag with posted 70xx-73xx lines have no employees rows, so their note reads "inga anställda". The reporting company had one row created the same day with a start date halfway through a July-June year: 181/365 = 0.5 FTE rounds to 0. What was removed or simplified: nothing removed. One resolver (resolveMedelantalAnstallda: override, else FTE average) now feeds the K2 note, the K3 note and the iXBRL fact, so no reader can pick a different number. The override sits on arsredovisning_narratives next to the other ÅRL 5 kap. disclosures and rides the existing narrative GET/POST route, service and page save. Why this and not the proposed one: the request asked support to "enable override of Not 2" as free text. A whole number keeps the statutory sentence intact and the iXBRL MedelantaletAnstallda fact taggable; free text would allow a non-compliant note. Rounding 0.5 up globally was rejected (changes every company's note silently, does nothing for companies with no employees rows), as was backdating the hire date (fixes one company, misstates the fact). The iXBRL input also reads the previous period's override so the jämförelseår column shows what last year's document showed. Migration 20260908130127 is additive (nullable INTEGER with a CHECK) and is applied and tracked on staging. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GxiKQke7sY6mrAK9KX4hbD * fix(arsredovisning): size-threshold metrics use the medelantal override too Skeptic refutation on 442fa1bc5: reportMetrics in model.ts still read the FTE average from the employees table, so the ÅRL 1:3 § större- företag test and the K2 relief thresholds could disagree with the figure Not 2 and the iXBRL fact disclose. A SIE-migrated aktiebolag with no employees rows and an override of 60 both years, balansomslutning over 40 MSEK, would have validated as K2-eligible while its own document said 60 employees. Fix: the metrics resolve the employee figure the same way the note does (current period override from report.disclosures, previous period via getMedelantalOverride on that period's narrative row). previous_period on ArsredovisningData now carries the period id so the lookup needs no extra fiscal_periods read. The iXBRL employees-error fallback keeps the previous period's override instead of blanking the jämförelseår. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GxiKQke7sY6mrAK9KX4hbD --------- Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5.1
parent
59d5b7b366
commit
e85eac317c
+28
@@ -140,6 +140,34 @@ describe('POST /api/bookkeeping/fiscal-periods/[id]/arsredovisning/narrative', (
|
||||
expect(body.data.parent_company_org_number).toBe('CHE-123.456.789')
|
||||
})
|
||||
|
||||
it('returns 400 for a fractional or negative medelantal anställda override', async () => {
|
||||
setupSupabase()
|
||||
expect((await POST(postReq({ medelantal_anstallda_override: 1.5 }), idParams)).status).toBe(400)
|
||||
setupSupabase()
|
||||
expect((await POST(postReq({ medelantal_anstallda_override: -1 }), idParams)).status).toBe(400)
|
||||
})
|
||||
|
||||
it('saves a whole-number medelantal anställda override and lets null clear it', async () => {
|
||||
const { enqueue } = setupSupabase()
|
||||
enqueue({ data: { id: 'period-1' } }) // fiscal_periods ownership check
|
||||
enqueue({ data: null }) // no registrerad submission
|
||||
enqueue({ data: { ...narrativeRow, medelantal_anstallda_override: 1 } }) // upsert
|
||||
enqueue({ data: null }) // clear narrative confirmation
|
||||
const { status, body } = await parseJsonResponse<{
|
||||
data: typeof narrativeRow & { medelantal_anstallda_override: number | null }
|
||||
}>(await POST(postReq({ medelantal_anstallda_override: 1 }), idParams))
|
||||
expect(status).toBe(200)
|
||||
expect(body.data.medelantal_anstallda_override).toBe(1)
|
||||
|
||||
const cleared = setupSupabase()
|
||||
cleared.enqueue({ data: { id: 'period-1' } })
|
||||
cleared.enqueue({ data: null })
|
||||
cleared.enqueue({ data: { ...narrativeRow, medelantal_anstallda_override: null } })
|
||||
cleared.enqueue({ data: null })
|
||||
const res = await POST(postReq({ medelantal_anstallda_override: null }), idParams)
|
||||
expect(res.status).toBe(200)
|
||||
})
|
||||
|
||||
it('returns 400 when the payload contains an unknown field', async () => {
|
||||
setupSupabase()
|
||||
const res = await POST(
|
||||
|
||||
@@ -87,6 +87,11 @@ const PostSchema = z.object({
|
||||
.nullable()
|
||||
.optional(),
|
||||
parent_company_city: sanitizedText(100).nullable().optional(),
|
||||
// ÅRL 5:20 §: manual medelantal anställda. Null clears the override and
|
||||
// the note falls back to the FTE average over the employees table. Whole
|
||||
// employees only (the K2 note and the iXBRL fact are integers); the cap
|
||||
// matches the DB CHECK.
|
||||
medelantal_anstallda_override: z.number().int().min(0).max(100_000).nullable().optional(),
|
||||
long_term_debt_over_five_years_confirmed: z.boolean().optional(),
|
||||
securities_pledged_confirmed: z.boolean().optional(),
|
||||
contingent_liabilities_confirmed: z.boolean().optional(),
|
||||
|
||||
Reference in New Issue
Block a user