From e41cf50afe34b2d9942198c2ae6025e7e730eac2 Mon Sep 17 00:00:00 2001 From: Mattsson <111893710+mattssonn@users.noreply.github.com> Date: Thu, 27 Aug 2026 17:45:52 +0200 Subject: [PATCH] fix(bookkeeping): verifikat views show company account names for off-catalog accounts (#1997) * fix(bookkeeping): verifikat views show company account names for off-catalog accounts Verifikat views (entry detail, JournalEntryList, StrikeLinesDialog, CorrectionPreview) rendered AccountNumber without a name source, so accounts outside the BAS 2026 catalog (typically SIE-imported, e.g. a legacy 1580) showed a blank Benamning even though the company's kontoplan has the name. AccountNumber now falls back to a session-cached map of the company's own chart-of-accounts names (one fetch per page load, inactive accounts included for historical verifikat). Precedence: explicit name prop, then the company map, then the BAS reference name, keeping the PR #1968 rule that user-editable chart rows win over hardcoded copy. Co-Authored-By: Claude Fable 5 Claude-Session: https://claude.ai/code/session_01N1rcRYRM8DyVp48mp5NNVc * refactor(bookkeeping): read company account names via the shared reference-data cache The check:guards raw-reference-fetch ratchet rightly rejected the hand-rolled session cache: lib/reference-data/hooks.ts already provides useAccounts with a per-company SWR cache seeded by the dashboard layout. AccountNumber now derives the company name from useAccounts(false) instead, and the bespoke hook and its tests are removed. Co-Authored-By: Claude Fable 5 Claude-Session: https://claude.ai/code/session_01N1rcRYRM8DyVp48mp5NNVc --------- Co-authored-by: Claude Fable 5 --- components/ui/account-number.tsx | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/components/ui/account-number.tsx b/components/ui/account-number.tsx index de899096..d143bf05 100644 --- a/components/ui/account-number.tsx +++ b/components/ui/account-number.tsx @@ -1,7 +1,9 @@ 'use client' +import { useMemo } from 'react' import { getAccountDescription, type AccountType } from '@/lib/bookkeeping/account-descriptions' import { useBasReference } from '@/lib/bookkeeping/use-bas-reference' +import { useAccounts } from '@/lib/reference-data/hooks' import { Tooltip, TooltipTrigger, @@ -45,11 +47,21 @@ export function AccountNumber({ // Loads the BAS chart chunk after mount and re-renders once names and // descriptions for non-hardcoded accounts are available. useBasReference() + // Inactive accounts included: historical verifikat keep referencing them + // long after they leave the active chart. + const { accounts } = useAccounts(false) + const companyName = useMemo( + () => accounts.find((a) => a.account_number === number)?.account_name, + [accounts, number], + ) const desc = getAccountDescription(number) // The company's own account name wins over the BAS reference name: a chart // row is user-editable data and must never be visually overridden by our - // hardcoded copy. The tooltip still shows the BAS name as reference. - const displayName = name || desc?.name + // hardcoded copy. Call sites that already know the row pass `name`; the + // rest (verifikat views) fall back to the shared reference-data cache, so + // off-catalog accounts (e.g. SIE-imported 1580) still get their names. + // The tooltip still shows the BAS name as reference. + const displayName = name || companyName || desc?.name const numberElement = (