fix(bookkeeping): a following year's own IB no longer blocks nollställ, and a re-dated räkenskapsår gets the right name (#2286)
Customer report (Aisen & Adison AB, 2026-09-03): Fortnox years 2024-2026
imported first, then the first year 2022/2023 backfilled. Two bugs surfaced.
1. The backfilled year was saved as "Räkenskapsår 2027": CreatePeriodDialog
seeds the next forward year and kept that name when the user re-dated the
form. The name now follows the typed dates until the user edits the name
(fiscalYearName exported from suggest-fiscal-period).
2. Nollställ of the backfilled year was refused with next_year_dependency
because 2024 carried an opening-balance verifikat. Any IB in the next year
counted as reliance, so a backfilled year could never be reset, while a
next year WITHOUT an IB (whose balansrapport really rolls from this year)
was allowed. Migration 20260904163000 redefines fiscal_year_reset_snapshot:
the block fires only when the next year is locked, closed or has its own
closing entry; a bokslut-generated IB is still refused via this year's
closing_entry_id (year_end_state). The snapshot returns next_period
{id, name, has_opening_balances} and the dialog states that the following
year's IB stays as it is.
pg-real: reset-fiscal-year.pg.test.ts pins the narrowed guard (closed next
year, next year with closing entry, next year with its own IB survives the
reset untouched).
Co-authored-by: Jakob Wennberg <311770904+jakobwennberg-oss@users.noreply.github.com>
Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Jakob Wennberg
Claude Fable 5.1
parent
db289e3bdc
commit
9618bab273
@@ -16,7 +16,7 @@ import { Label } from '@/components/ui/label'
|
||||
import { AttnLine } from '@/components/ui/attn-line'
|
||||
import { useToast } from '@/components/ui/use-toast'
|
||||
import { Loader2 } from 'lucide-react'
|
||||
import { computeSuggestedPeriod } from '@/lib/bookkeeping/suggest-fiscal-period'
|
||||
import { computeSuggestedPeriod, fiscalYearName } from '@/lib/bookkeeping/suggest-fiscal-period'
|
||||
import { fiscalPeriodAdvisoryText } from '@/lib/bookkeeping/fiscal-period-warnings'
|
||||
import type { FiscalPeriod } from '@/types'
|
||||
import { invalidateReferenceData } from '@/lib/reference-data/invalidate'
|
||||
@@ -61,6 +61,11 @@ export default function CreatePeriodDialog({ open, onOpenChange, entryDate, peri
|
||||
const suggested = useMemo(() => computeSuggestedPeriod(entryDate, periods), [entryDate, periods])
|
||||
|
||||
const [name, setName] = useState(suggested.name)
|
||||
// The name follows the dates until the user types a name of their own.
|
||||
// Without this the seed suggestion (the next forward year, e.g.
|
||||
// "Räkenskapsår 2027") survived the user re-dating the form to a backfilled
|
||||
// first year and was saved verbatim.
|
||||
const [nameEdited, setNameEdited] = useState(false)
|
||||
const [periodStart, setPeriodStart] = useState(suggested.period_start)
|
||||
const [periodEnd, setPeriodEnd] = useState(suggested.period_end)
|
||||
const [isSubmitting, setIsSubmitting] = useState(false)
|
||||
@@ -72,12 +77,21 @@ export default function CreatePeriodDialog({ open, onOpenChange, entryDate, peri
|
||||
const [lastSuggested, setLastSuggested] = useState(suggested)
|
||||
if (suggested.name !== lastSuggested.name || suggested.period_start !== lastSuggested.period_start) {
|
||||
setName(suggested.name)
|
||||
setNameEdited(false)
|
||||
setPeriodStart(suggested.period_start)
|
||||
setPeriodEnd(suggested.period_end)
|
||||
setLastSuggested(suggested)
|
||||
setCreated(null)
|
||||
}
|
||||
|
||||
// A date input yields '' while incomplete and a full YYYY-MM-DD otherwise:
|
||||
// only derive a name once both ends are known.
|
||||
const updateDates = (start: string, end: string) => {
|
||||
setPeriodStart(start)
|
||||
setPeriodEnd(end)
|
||||
if (!nameEdited && start && end) setName(fiscalYearName(start, end))
|
||||
}
|
||||
|
||||
// Close, and refetch in the parent if this session created a period. The
|
||||
// refetch is deferred to here on the advisory path on purpose: it swaps the
|
||||
// `periods` prop, which resets the form above, and that would pull the
|
||||
@@ -175,16 +189,23 @@ export default function CreatePeriodDialog({ open, onOpenChange, entryDate, peri
|
||||
<div className="space-y-3">
|
||||
<div>
|
||||
<Label>Namn</Label>
|
||||
<Input value={name} onChange={(e) => setName(e.target.value)} className="mt-1" />
|
||||
<Input
|
||||
value={name}
|
||||
onChange={(e) => {
|
||||
setName(e.target.value)
|
||||
setNameEdited(true)
|
||||
}}
|
||||
className="mt-1"
|
||||
/>
|
||||
</div>
|
||||
<div className="grid grid-cols-2 gap-3">
|
||||
<div>
|
||||
<Label>Startdatum</Label>
|
||||
<Input type="date" value={periodStart} onChange={(e) => setPeriodStart(e.target.value)} className="mt-1" />
|
||||
<Input type="date" value={periodStart} onChange={(e) => updateDates(e.target.value, periodEnd)} className="mt-1" />
|
||||
</div>
|
||||
<div>
|
||||
<Label>Slutdatum</Label>
|
||||
<Input type="date" value={periodEnd} onChange={(e) => setPeriodEnd(e.target.value)} className="mt-1" />
|
||||
<Input type="date" value={periodEnd} onChange={(e) => updateDates(periodStart, e.target.value)} className="mt-1" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -242,6 +242,11 @@ export function FiscalYearResetDialog({
|
||||
<p className="mt-2 text-xs text-muted-foreground">
|
||||
{t('fy_reset_documents_note')}
|
||||
</p>
|
||||
{eligibility.next_period?.has_opening_balances ? (
|
||||
<p className="mt-2 text-xs text-muted-foreground">
|
||||
{t('fy_reset_next_year_ib_note', { name: eligibility.next_period.name })}
|
||||
</p>
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
{eligibility.eligible ? (
|
||||
|
||||
Reference in New Issue
Block a user