feat(dimensions): PR2 registry — CRUD API, register UI, settings toggle, SIE export on the new registry (#858)
* feat(dimensions): PR2 registry — CRUD API, register UI, settings toggle, SIE export on the new registry
Phase 2 of dev_docs/dimensions_implementation_plan.md. Companies with
dimensions_enabled=false (default) see zero change.
API:
- Dashboard CRUD: GET /api/dimensions (lazy-seeds system dims 1/6 via the
ensure_company_dimensions RPC), PATCH /api/dimensions/[id] (is_system
rename blocked), POST/PATCH/DELETE values (code immutable after creation;
strict Fortnox code format ^[A-Za-z0-9ÅÄÖåäö_+\-]{1,20}$ at the API layer;
retention-trigger deletes surface the Swedish "arkivera istället" message
as 409 DIMENSION_VALUE_REFERENCED).
- POST /api/dimensions/import-existing — scans journal_entry_lines.dimensions
for unregistered codes and mints inactive placeholder registry rows.
- v1 public API: GET dimensions + POST values (Idempotency-Key, dry-run),
registered in the OpenAPI spec (102→104 endpoints).
- dimensions_enabled boolean on company_settings (new migration,
UI-visibility only, never correctness-bearing) exposed through the
existing settings read/update path.
SIE export (lib/reports/sie-export.ts):
- Reads the new dimensions/dimension_values registry; legacy
cost_centers/projects tables now have zero readers (drop migration next).
- Fixes the latent Visma-rejection bug: #OBJEKT now declared for INACTIVE
values referenced by lines.
- Generic-N: #DIM/#UNDERDIM loop sorted by sie_dim_no; #TRANS object lists
serialize from the line JSONB map (sorted, '01'→'1' collapse); orphan
codes/dims synthesize declarations from the SIE reserved-number seed —
every referenced (dim, code) pair is guaranteed declared.
UI:
- /dimensions register (Register-recipe): tabs per dimension, search,
sortable table, value dialog (code immutable on edit, projekt dates on
dim 6), archive-not-delete affordances.
- DimensionCombobox shipped (mounts in the tagging PR).
- Settings toggle "Aktivera kostnadsställen & projekt" — toggle-on runs the
import-existing scan and links to the register.
- Nav row in redovisning, rendered only when dimensions_enabled (same
mechanism as pays_salaries).
- dimensions.* i18n namespace (51 keys, sv/en parity).
- Sandbox seed: demo dims + values, revenue line tagged {"1":"BUTIK","6":"P001"}.
Verified: 6328/6328 unit tests, guard + coverage gate green, tsc parity with
main (210=210), production build passes.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
* fix(dimensions): PR2 review round — atomic archived-create, UNDERDIM ordering, import robustness, date semantics
- POST values accepts is_active so "create as archived" is atomic; the UI's
fragile create-then-PATCH fallback is deleted (PR Agent finding 1).
- DimensionCombobox blur revert reads the committed value/values through refs
so a selection landing inside the 150ms window always wins (finding 2).
- import-existing sanitizes candidate codes like the PR1 backfill and upserts
with ignoreDuplicates — one bad/duplicate code can no longer abort the
batch; created counted from returned rows (finding 3).
- SIE export emits all root #DIM before any #UNDERDIM so a parent always
precedes a lower-numbered child (SIE4 declaration order — Swedish review);
synthesized placeholder declarations now log one structured warning
(BFNAR 2013:2 behandlingshistorik) + defence-in-depth comment.
- Value dates rejected (400 DIMENSION_VALUE_DATES_NOT_ALLOWED) when the
parent dimension is flow-period (resets_annually=true); explicit null
still clears (Swedish review).
- Sandbox seed logs seeded dimension codes; GET /api/dimensions documents
the deliberate absence of dimensions_enabled gating (UI-visibility flag,
not a security boundary — compliance-swarm V8.2.1 rejected by design).
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5
parent
8cc2efb083
commit
8bb49c07a2
@@ -81,6 +81,7 @@
|
||||
"transactions": "Transactions",
|
||||
"bookkeeping": "Bookkeeping",
|
||||
"chart_of_accounts": "Chart of accounts",
|
||||
"dimensions": "Cost centres & projects",
|
||||
"assets": "Fixed assets",
|
||||
"reports": "Reports",
|
||||
"budgets": "Budgets",
|
||||
@@ -3394,6 +3395,59 @@
|
||||
"toast_activated_title": "Account activated",
|
||||
"toast_activated_description": "Account {number} has been added to your chart of accounts"
|
||||
},
|
||||
"dimensions": {
|
||||
"new_value": "New value",
|
||||
"new_value_title": "New value – {dimension}",
|
||||
"edit_value_title": "Edit value",
|
||||
"search_placeholder": "Search by code or name…",
|
||||
"col_code": "Code",
|
||||
"col_name": "Name",
|
||||
"col_status": "Status",
|
||||
"col_start": "Start",
|
||||
"col_end": "End",
|
||||
"status_active": "Active",
|
||||
"status_archived": "Archived",
|
||||
"load_failed_title": "Could not load the register",
|
||||
"load_failed_description": "Try again in a moment.",
|
||||
"retry": "Try again",
|
||||
"empty_title": "No values yet",
|
||||
"empty_description": "Create values for {dimension} to tag journal lines and follow up results.",
|
||||
"no_search_results_title": "No matches",
|
||||
"no_search_results_description": "No value matches “{term}”.",
|
||||
"viewer_disabled_tooltip": "You have read-only access and cannot create values",
|
||||
"created_title": "Value created",
|
||||
"created_description": "{code} has been added to the register.",
|
||||
"updated_title": "Value updated",
|
||||
"deleted_title": "Value deleted",
|
||||
"save_failed_title": "Could not save",
|
||||
"delete_failed_title": "Could not delete",
|
||||
"form_code_label": "Code",
|
||||
"form_code_help": "1–20 characters: letters, digits and _ + -",
|
||||
"form_code_immutable_help": "The code cannot be changed after the value has been created.",
|
||||
"form_code_invalid": "Invalid code: 1–20 characters, only letters, digits and _ + -",
|
||||
"form_name_label": "Name",
|
||||
"form_name_invalid": "Enter a name (1–120 characters).",
|
||||
"form_active_label": "Active",
|
||||
"form_active_help": "Archived values are hidden in pickers but remain on posted vouchers.",
|
||||
"form_start_label": "Start date",
|
||||
"form_end_label": "End date",
|
||||
"form_date_order_invalid": "The end date cannot be before the start date.",
|
||||
"form_create": "Create",
|
||||
"form_save": "Save",
|
||||
"form_delete": "Delete",
|
||||
"delete_confirm_title": "Delete this value?",
|
||||
"delete_confirm_description": "“{code}” will be permanently deleted. Values used on posted vouchers cannot be deleted — archive them instead.",
|
||||
"delete_confirm_label": "Delete",
|
||||
"delete_cancel_label": "Cancel",
|
||||
"settings_heading": "Cost centres & projects",
|
||||
"settings_toggle_label": "Enable cost centres & projects",
|
||||
"settings_toggle_help": "Shows the register in the menu and lets you tag journal lines with cost centre and project.",
|
||||
"settings_imported_toast_title": "Existing codes imported",
|
||||
"settings_imported_toast": "{count, plural, one {1 existing code was imported} other {# existing codes were imported}}",
|
||||
"settings_import_failed_title": "Could not import existing codes",
|
||||
"settings_save_failed_title": "Could not save the setting",
|
||||
"settings_open_register": "Open cost centres & projects"
|
||||
},
|
||||
"tic_workspace": {
|
||||
"toast_settings_failed": "Could not fetch settings",
|
||||
"toast_profile_failed": "Could not fetch company profile",
|
||||
|
||||
@@ -81,6 +81,7 @@
|
||||
"transactions": "Transaktioner",
|
||||
"bookkeeping": "Bokföring",
|
||||
"chart_of_accounts": "Kontoplan",
|
||||
"dimensions": "Kostnadsställen & projekt",
|
||||
"assets": "Anläggningstillgångar",
|
||||
"reports": "Rapporter",
|
||||
"budgets": "Budgetar",
|
||||
@@ -3394,6 +3395,59 @@
|
||||
"toast_activated_title": "Konto aktiverat",
|
||||
"toast_activated_description": "Konto {number} har lagts till i din kontoplan"
|
||||
},
|
||||
"dimensions": {
|
||||
"new_value": "Nytt värde",
|
||||
"new_value_title": "Nytt värde – {dimension}",
|
||||
"edit_value_title": "Redigera värde",
|
||||
"search_placeholder": "Sök på kod eller namn…",
|
||||
"col_code": "Kod",
|
||||
"col_name": "Namn",
|
||||
"col_status": "Status",
|
||||
"col_start": "Start",
|
||||
"col_end": "Slut",
|
||||
"status_active": "Aktiv",
|
||||
"status_archived": "Arkiverad",
|
||||
"load_failed_title": "Kunde inte hämta registret",
|
||||
"load_failed_description": "Försök igen om en stund.",
|
||||
"retry": "Försök igen",
|
||||
"empty_title": "Inga värden ännu",
|
||||
"empty_description": "Skapa värden för {dimension} för att kunna tagga verifikatrader och följa upp resultatet.",
|
||||
"no_search_results_title": "Inga träffar",
|
||||
"no_search_results_description": "Inget värde matchar ”{term}”.",
|
||||
"viewer_disabled_tooltip": "Du har läsbehörighet och kan inte skapa värden",
|
||||
"created_title": "Värde skapat",
|
||||
"created_description": "{code} har lagts till i registret.",
|
||||
"updated_title": "Värde uppdaterat",
|
||||
"deleted_title": "Värde borttaget",
|
||||
"save_failed_title": "Kunde inte spara",
|
||||
"delete_failed_title": "Kunde inte ta bort",
|
||||
"form_code_label": "Kod",
|
||||
"form_code_help": "1–20 tecken: bokstäver, siffror samt _ + -",
|
||||
"form_code_immutable_help": "Koden kan inte ändras efter att värdet har skapats.",
|
||||
"form_code_invalid": "Ogiltig kod: 1–20 tecken, endast bokstäver, siffror samt _ + -",
|
||||
"form_name_label": "Namn",
|
||||
"form_name_invalid": "Ange ett namn (1–120 tecken).",
|
||||
"form_active_label": "Aktivt",
|
||||
"form_active_help": "Arkiverade värden döljs i väljare men finns kvar på bokförda verifikat.",
|
||||
"form_start_label": "Startdatum",
|
||||
"form_end_label": "Slutdatum",
|
||||
"form_date_order_invalid": "Slutdatum kan inte vara före startdatum.",
|
||||
"form_create": "Skapa",
|
||||
"form_save": "Spara",
|
||||
"form_delete": "Ta bort",
|
||||
"delete_confirm_title": "Ta bort värdet?",
|
||||
"delete_confirm_description": "”{code}” tas bort permanent. Värden som används på bokförda verifikat kan inte tas bort — arkivera dem istället.",
|
||||
"delete_confirm_label": "Ta bort",
|
||||
"delete_cancel_label": "Avbryt",
|
||||
"settings_heading": "Kostnadsställen & projekt",
|
||||
"settings_toggle_label": "Aktivera kostnadsställen & projekt",
|
||||
"settings_toggle_help": "Visar registret i menyn och gör det möjligt att tagga verifikatrader med kostnadsställe och projekt.",
|
||||
"settings_imported_toast_title": "Befintliga koder importerade",
|
||||
"settings_imported_toast": "{count, plural, one {1 befintlig kod importerades} other {# befintliga koder importerades}}",
|
||||
"settings_import_failed_title": "Kunde inte importera befintliga koder",
|
||||
"settings_save_failed_title": "Kunde inte spara inställningen",
|
||||
"settings_open_register": "Öppna kostnadsställen & projekt"
|
||||
},
|
||||
"tic_workspace": {
|
||||
"toast_settings_failed": "Kunde inte hämta inställningar",
|
||||
"toast_profile_failed": "Kunde inte hämta företagsprofil",
|
||||
|
||||
Reference in New Issue
Block a user