6bd85f94b6
The correction header was always built server-side as "Rattelse: <original description>". When the original entry was labelled after the wrong account, the correction kept echoing that stale label even after the user switched to the correct account (follow-up to the line-description fix in #1029). - CorrectJournalEntrySchema gains an optional trimmed description - correctEntry() accepts options.description; blank or absent falls back to the canonical "Rattelse: <original>" auto text - both correct routes (dashboard + v1, which share the schema) thread the description through - CorrectionEntryDialog surfaces an editable verifikationstext field, pre-filled with the auto text; an untouched or cleared prefill is NOT sent, so the server-side fallback stays the source of truth (same only-overwrite-auto-filled principle as #1029) Forward-only: already-posted corrections are immutable per BFL. Fixes #1031 Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
35 lines
1.5 KiB
TypeScript
35 lines
1.5 KiB
TypeScript
/**
|
|
* Entry-level verifikationstext handling for the correction dialog.
|
|
*
|
|
* The correction header defaults server-side to "Rättelse: <original>"
|
|
* (lib/core/bookkeeping/storno-service.ts). If the original entry was
|
|
* labelled after the wrong account (e.g. "Lån från närstående personer,
|
|
* långfristig del"), that header keeps echoing the wrong label even after
|
|
* the account itself is corrected (issue #1031). The dialog therefore
|
|
* pre-fills an editable field with the same auto text and only sends a
|
|
* description when the user actually changed it: an untouched auto prefill
|
|
* is omitted from the request so the server-side fallback stays the single
|
|
* source of truth for the default format. Same only-overwrite-auto-filled
|
|
* principle as the line-description guard from #1029.
|
|
*/
|
|
|
|
/** The auto text the server would generate for the correction header. */
|
|
export function autoCorrectionDescription(originalDescription: string): string {
|
|
return `Rättelse: ${originalDescription}`
|
|
}
|
|
|
|
/**
|
|
* Decide what to send as the correction's description.
|
|
* Returns undefined when the field is blank or still equals the auto prefill:
|
|
* in both cases the server-side fallback should apply.
|
|
*/
|
|
export function correctionDescriptionForSubmit(
|
|
currentDescription: string,
|
|
originalDescription: string,
|
|
): string | undefined {
|
|
const trimmed = currentDescription.trim()
|
|
if (!trimmed) return undefined
|
|
if (trimmed === autoCorrectionDescription(originalDescription).trim()) return undefined
|
|
return trimmed
|
|
}
|