fix(skattekonto): look-alike beslut rows, the list-to-voucher round trip, makulerad rendering, huvudbok discoverability (#1297)

Four fixes from the exit mail Anders Orback (Center Node AB) sent hours
after churning. His five points were mostly one job: reconciling
skattekontot against banken before årsredovisningen.

Skattekonto look-alike rows. Skatteverket splits a retroactive
omprövningsbeslut across every month it re-charges and sends one
transaction per month, sharing date, text and amount; only
ranteberakningsdatum separates them, and we stored it but rendered it
nowhere. A real company posted 15 such vouchers (67 785 kr across Feb
2025-Apr 2026) unable to tell them from duplicates of the automatic
hämtning. Surface the field when it carries information: its month
differs from the Datum column, or another row in the same band is
otherwise indistinguishable.

The list-to-voucher round trip. The verifikat list collapsed to a
skeleton on every refetch and sprang back, moving rows under the
pointer; only the first load shows a skeleton now. Filter state is
React-only, so leaving the list loses it: add a hover-revealed
open-in-new-tab affordance on the voucher list and the skattekonto page,
where the link had been behind a hand-rolled opacity-0 that coarse
pointers never trigger.

Makulerad rendering. A stornoed verifikat now reads as struck out, per
data cell rather than on the row, because text-decoration propagates and
a child cannot opt out.

Vouchers-per-account discoverability. /reports/huvudbok?account=1930
already existed; the palette matcher requires every token and the entry
never contained the word "verifikat". Add ReportDescriptor.searchTerms
plus a report-library search box.

Also fixes a false "Saknar underlag" compliance chip that flashed before
attachment counts resolved, and a keyboard-access regression where
HOVER_REVEAL_CLASS carried focus-visible only, hiding controls inside a
non-focusable wrapper from keyboard users.

No migration. No write paths, storno paths or posted entries touched.

Follow-ups filed: #1300 #1301 #1302 #1303 #1304 #1305 #1306 #1307 #1308.
Open decision: #1305 (Omförd vs Makulerad).

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Jakob Wennberg
2026-07-30 18:27:29 +02:00
committed by GitHub
co-authored by Claude Opus 5
parent 144cc51458
commit fa394e3759
14 changed files with 584 additions and 58 deletions
+1 -1
View File
@@ -48,7 +48,7 @@ export const AGENT_GROUND_RULES: string[] = [
' • Är verifikationen den SENASTE i sin serie kan den även raderas helt ("Radera verifikat"): då återanvänds löpnumret och ingen lucka uppstår.',
' • Konton som finns i BAS-kontoplanen men saknas i företagets kontoplan läggs till AUTOMATISKT vid bokföring och rättelse. Be aldrig användaren registrera standardkonton manuellt innan de bokför: bara okända kontonummer eller avaktiverade konton stoppar.',
' • När en bokning makuleras (storno utan rättelse) släpps den kopplade banktransaktionen och blir bokföringsbar igen i transaktionsvyn: användaren kan alltid klicka på transaktionen och bokföra om. Vid en rättelse följer transaktionen och underlaget med till rättelseverifikationen.',
' • En storno på 0 kr med status "Makulerad" i kedjan är resterna av ett avbrutet rättelseförsök: den påverkar inga saldon. Oförklarade luckor i löpnummerserien dokumenteras via verifikationsluckor (gnubok_list_voucher_gaps / gnubok_explain_voucher_gap).',
' • En storno på 0 kr med status "Avbruten" i kedjan är resterna av ett avbrutet rättelseförsök: den påverkar inga saldon. Oförklarade luckor i löpnummerserien dokumenteras via verifikationsluckor (gnubok_list_voucher_gaps / gnubok_explain_voucher_gap).',
'',
// -- Representation: headcount + per-person VAT cap --
'- REPRESENTATION (måltid/restaurang): innan du bokför, fånga ANTAL deltagare, vilka de var (namn + företag), och syftet. Antalet är inte valfritt: momsavdraget beräknas per person. Fråga "Hur många var ni, och vilka?" om det inte redan framgår.',
@@ -0,0 +1,61 @@
import { describe, it, expect } from 'vitest'
import { REPORT_CATALOG, reportMatchesQuery, getReport } from '@/lib/reports/catalog'
describe('reportMatchesQuery', () => {
it('returns everything for an empty query', () => {
expect(reportMatchesQuery('Huvudbok', '')).toBe(true)
expect(reportMatchesQuery('Huvudbok', ' ')).toBe(true)
})
it('requires every token, so extra words narrow', () => {
expect(reportMatchesQuery('Huvudbok verifikat per konto', 'verifikat konto')).toBe(true)
expect(reportMatchesQuery('Huvudbok verifikat per konto', 'verifikat faktura')).toBe(false)
})
it('ignores case and diacritics in both directions', () => {
expect(reportMatchesQuery('Stäm av bank', 'stam av')).toBe(true)
expect(reportMatchesQuery('Stam av bank', 'stäm')).toBe(true)
expect(reportMatchesQuery('Balansrapport', 'BALANS')).toBe(true)
})
it('matches on a substring so partial words still find the report', () => {
expect(reportMatchesQuery('Momsdeklaration', 'moms')).toBe(true)
})
})
describe('huvudbok is reachable by the words a bookkeeper uses', () => {
const huvudbok = getReport('huvudbok')!
const haystack = `Huvudbok ${huvudbok.searchTerms ?? ''}`
// The phrase from the churn report that returned zero hits before.
it.each([
'verifikat per konto',
'verifikationer',
'kontoanalys',
'kontokort',
'stäm av konto',
'account statement',
])('finds huvudbok for %j', (query) => {
expect(reportMatchesQuery(haystack, query)).toBe(true)
})
})
describe('catalog search terms', () => {
it('never lets searchTerms shadow another report by slug', () => {
// A report's synonyms must not be so broad that they swallow a query
// aimed squarely at a different report's own name.
const huvudbok = getReport('huvudbok')!
const terms = huvudbok.searchTerms ?? ''
for (const slug of ['balansrapport', 'resultatrapport', 'vat-declaration']) {
expect(reportMatchesQuery(terms, slug)).toBe(false)
}
})
it('keeps searchTerms lowercase-comparable and free of punctuation noise', () => {
for (const report of REPORT_CATALOG) {
if (!report.searchTerms) continue
expect(report.searchTerms).toBe(report.searchTerms.trim())
expect(report.searchTerms).not.toMatch(/[,;]/)
}
})
})
+33
View File
@@ -67,6 +67,13 @@ export interface ReportDescriptor {
* lib/reports/__tests__/dimension-statutory-guard.test.ts.
*/
dimensions?: boolean
/**
* Extra words the library search should match, beyond the translated name
* and description. For the vocabulary a user brings from another product or
* from the task they are doing ("verifikat per konto", "kontoanalys"), which
* is often not the word we chose for the report.
*/
searchTerms?: string
/** Only shown when company_settings.dimensions_enabled is true. */
needsDimensions?: boolean
/**
@@ -249,6 +256,11 @@ export const REPORT_CATALOG: ReportDescriptor[] = [
params: 'fiscal-range',
exports: ['xlsx'],
dimensions: true,
// This is the "show me the verifikat behind account 1930" report, which
// is what people search for when reconciling before årsredovisningen.
// Fortnox calls it Kontoanalys, Björn Lundén Kontokontroll.
searchTerms:
'verifikat verifikationer per konto kontoanalys kontokort kontohistorik stäm av stämma avstämning ledger account statement vouchers',
},
{
slug: 'grundbok',
@@ -364,3 +376,24 @@ export function getLibrarySections(
),
})).filter((s) => s.items.length > 0)
}
/**
* Token-AND match used by the report library's search box.
*
* Every whitespace-separated token in the query must appear somewhere in the
* haystack, so narrowing words keep narrowing. Case- and diacritic-insensitive
* so "stam av" finds "stäm av" and a Swedish keyboard is not required.
*/
export function reportMatchesQuery(haystack: string, query: string): boolean {
const tokens = fold(query).split(/\s+/).filter(Boolean)
if (tokens.length === 0) return true
const hay = fold(haystack)
return tokens.every((token) => hay.includes(token))
}
function fold(value: string): string {
return value
.toLowerCase()
.normalize('NFD')
.replace(/[̀-ͯ]/g, '')
}
@@ -0,0 +1,94 @@
import { describe, it, expect } from 'vitest'
import {
rowsNeedingInterestDate,
type InterestPeriodRow,
} from '@/lib/skatteverket/interest-period'
function row(overrides: Partial<InterestPeriodRow> & { id: string }): InterestPeriodRow {
return {
displayDate: '2026-05-07',
transaktionstext: 'Debiterad preliminärskatt',
belopp: -4519,
ranteberakningsdatum: '2026-05-12',
...overrides,
}
}
describe('rowsNeedingInterestDate', () => {
it('marks every row of a retroactive omprövningsbeslut', () => {
// The real Center Node AB case: one beslut dated 2026-05-07 re-charging
// preliminary tax across 15 months. Same date, text and amount on all of
// them; only ränteberäkningsdatum differs.
const rows = [
'2025-02-13',
'2025-03-13',
'2025-04-15',
'2026-03-13',
'2026-04-14',
].map((d, i) =>
row({
id: `r${i}`,
transaktionstext: 'Beslut 260506 debiterad preliminärskatt',
ranteberakningsdatum: d,
}),
)
const marked = rowsNeedingInterestDate(rows)
expect(marked.size).toBe(5)
for (const r of rows) expect(marked.has(r.id)).toBe(true)
})
it('leaves an ordinary row alone when the interest date is in the shown month', () => {
const marked = rowsNeedingInterestDate([
row({ id: 'a', displayDate: '2026-05-07', ranteberakningsdatum: '2026-05-12' }),
])
expect(marked.size).toBe(0)
})
it('marks a row whose interest date falls in another month', () => {
const marked = rowsNeedingInterestDate([
row({ id: 'a', displayDate: '2026-05-07', ranteberakningsdatum: '2025-11-13' }),
])
expect([...marked]).toEqual(['a'])
})
it('marks same-month twins that would otherwise render identically', () => {
// Guards the case the month rule alone would miss: a decision split
// inside one month still produces two indistinguishable rows.
const marked = rowsNeedingInterestDate([
row({ id: 'a', ranteberakningsdatum: '2026-05-12' }),
row({ id: 'b', ranteberakningsdatum: '2026-05-20' }),
])
expect(marked.has('a')).toBe(true)
expect(marked.has('b')).toBe(true)
})
it('does not mark rows that differ in amount or text', () => {
const marked = rowsNeedingInterestDate([
row({ id: 'a', belopp: -4519 }),
row({ id: 'b', belopp: -1570 }),
row({ id: 'c', transaktionstext: 'Intäktsränta' }),
])
expect(marked.size).toBe(0)
})
it('skips rows with no interest date rather than rendering an empty marker', () => {
const marked = rowsNeedingInterestDate([
row({ id: 'a', ranteberakningsdatum: null }),
row({ id: 'b', ranteberakningsdatum: null }),
])
expect(marked.size).toBe(0)
})
it('tolerates malformed dates without throwing', () => {
const marked = rowsNeedingInterestDate([
row({ id: 'a', displayDate: '', ranteberakningsdatum: '2026-05-12' }),
])
expect(marked.has('a')).toBe(true)
})
it('handles an empty band', () => {
expect(rowsNeedingInterestDate([]).size).toBe(0)
})
})
+77
View File
@@ -0,0 +1,77 @@
/**
* Disambiguation of look-alike skattekonto rows.
*
* When Skatteverket issues a retroactive omprövningsbeslut it does not send one
* transaction: it splits the decision across every month it re-charges and
* sends one transaction per month. Those rows share transaktionsdatum,
* transaktionstext and belopp, and carry their own transaktionsidentitet. The
* only human-readable field that separates them is `ranteberakningsdatum`.
*
* The skattekonto table shows Datum / Händelse / Belopp, so such a decision
* renders as N pixel-identical rows. That reads as duplicates from the
* automatic Skatteverket fetch, which is a well-known failure mode in this
* market and has cost us at least one customer who booked all of them and then
* could not tell whether he had to reverse fourteen of them.
*
* We surface `ranteberakningsdatum` only on rows where it actually carries
* information, so it stays an exception marker (design convention 5) rather
* than noise repeated on every row. A row qualifies when either:
* 1. its interest date falls in a different month than the date shown in the
* Datum column (the retroactive-decision signature), or
* 2. another row in the same band is otherwise indistinguishable from it.
*
* Rule 2 catches the look-alikes the month rule alone would miss, such as a
* decision split inside a single month. It cannot separate rows that share a
* ränteberäkningsdatum, or that both lack one, since that is the only field
* left to distinguish them; in practice Skatteverket gives each month of a
* decision its own date, which is exactly the case this exists for.
*/
export interface InterestPeriodRow {
id: string
/** The date actually rendered in the Datum column for this row. */
displayDate: string
transaktionstext: string
belopp: number
ranteberakningsdatum: string | null | undefined
}
/** `yyyy-MM` from an ISO date or timestamp; '' when the input is unusable. */
function monthOf(value: string): string {
if (typeof value !== 'string' || value.length < 7) return ''
return value.slice(0, 7)
}
/**
* Identity as the table renders it. Two rows with the same key are
* indistinguishable to the reader.
*/
function renderedIdentity(row: InterestPeriodRow): string {
return `${row.displayDate}|${row.transaktionstext}|${row.belopp}`
}
/**
* Ids of the rows that should display their ränteberäkningsdatum.
*
* Pass one band (upcoming / overdue / booked) at a time: rows are only
* confusable with the rows they are rendered next to.
*/
export function rowsNeedingInterestDate(rows: InterestPeriodRow[]): Set<string> {
const seen = new Map<string, number>()
for (const row of rows) {
const key = renderedIdentity(row)
seen.set(key, (seen.get(key) ?? 0) + 1)
}
const result = new Set<string>()
for (const row of rows) {
if (!row.ranteberakningsdatum) continue
const spansAnotherMonth =
monthOf(row.ranteberakningsdatum) !== monthOf(row.displayDate)
const hasTwin = (seen.get(renderedIdentity(row)) ?? 0) > 1
if (spansAnotherMonth || hasTwin) result.add(row.id)
}
return result
}