Let an absence be taken back, in the right order

A long-term absence recorded by mistake could only be undone by booking
a second event on top of it — leaving two entries in the file, the first
of which never happened. Karenz and Rückkehr can now be deleted and
corrected like the other entries.

For that to restore anything, the two operations first had to start
recording what they overwrote. start_karenz and record_karenz_return now
keep before/after the way change_employee_data does: status, kind of
absence, start, planned return — and for a return also employment type,
hours and the part-time variant. Without that there is nothing to revert
to, only a sentence.

The ordering rule HR asked for is enforced in the database, not just in
the UI: an absence cannot be deleted while a later return exists. A
return standing on its own would be a return from nothing, and the
person's status would derive from an entry whose starting point had been
deleted. Delete the return first and the absence frees up.

Rehearsed end to end on real data: absence recorded, return recorded on
reduced hours; deleting the absence refused; deleting the return put the
person back on Karenz with the original hours and the part-time variant
cleared; deleting the absence then put them back to Aktiv with no trace.

Rows written before today carry no before/after and stay untouchable,
with the reason they already gave. Planned absences are refused too —
they have their own operation, and their fields have no place in a
pending payload, which is why app_feld_karte carries a null group for
them rather than a plausible-looking wrong one.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
2026-08-14 13:13:01 +02:00
parent f5ace8af2e
commit 384bdb4fb3
4 changed files with 688 additions and 4 deletions

View File

@@ -30,7 +30,7 @@ describe("darfKorrigiertWerden", () => {
expect(u.erlaubt === false && u.grund).toMatch(/Anfang der Zeitleiste/);
});
it.each<HistoryEventType>(["Versetzung", "Beförderung", "Karenz", "Rückkehr", "Austritt", "Wiedereintritt", "Reorganisation"])(
it.each<HistoryEventType>(["Versetzung", "Beförderung", "Austritt", "Wiedereintritt", "Reorganisation"])(
"verweist bei %s auf den fachlichen Vorgang",
(typ) => {
const u = darfKorrigiertWerden(eintrag({ event_type: typ }), HEUTE);
@@ -39,6 +39,14 @@ describe("darfKorrigiertWerden", () => {
}
);
it("lässt Abwesenheit und Rückkehr zu", () => {
// Eine versehentlich erfasste Abwesenheit war sonst nur durch eine zweite
// Buchung loszuwerden — und dann stünden zwei Einträge in der Akte, von
// denen der erste nie stattgefunden hat.
expect(darfKorrigiertWerden(eintrag({ event_type: "Karenz" }), HEUTE).erlaubt).toBe(true);
expect(darfKorrigiertWerden(eintrag({ event_type: "Rückkehr" }), HEUTE).erlaubt).toBe(true);
});
it("lässt Zukünftiges zu, sobald der geplante Vorgang bekannt ist", () => {
// Das ist der Sinn von pending_id: ohne Bezug liesse sich die geplante
// Änderung nur über Person und Datum finden, und das ist nicht eindeutig.
@@ -113,3 +121,38 @@ describe("loeschVorschau", () => {
expect(v).toMatchObject({ feld: "Adresse", von: "Endstrasse 9", auf: "Zwischenweg 1" });
});
});
// Die Reihenfolge zählt: eine Rückkehr setzt eine Abwesenheit voraus. Bliebe
// sie stehen, während die Abwesenheit verschwindet, stünde in der Akte eine
// Rückkehr aus dem Nichts — und der Status ergäbe sich aus einem Eintrag,
// dessen Ausgangslage gelöscht ist.
describe("Reihenfolge von Abwesenheit und Rückkehr", () => {
const karenz = eintrag({ id: "k", event_type: "Karenz", event_date: "2026-07-15", created_at: "2026-07-15T09:00:00.000Z" });
const rueckkehr = eintrag({ id: "r", event_type: "Rückkehr", event_date: "2026-08-10", created_at: "2026-08-10T09:00:00.000Z" });
it("verweigert die Abwesenheit, solange die Rückkehr steht", () => {
const u = darfKorrigiertWerden(karenz, HEUTE, [karenz, rueckkehr]);
expect(u.erlaubt).toBe(false);
expect(u.erlaubt === false && u.grund).toMatch(/Rückkehr.*zuerst gelöscht/);
});
it("lässt die Rückkehr jederzeit zurücknehmen — sie ist das obere Ende", () => {
expect(darfKorrigiertWerden(rueckkehr, HEUTE, [karenz, rueckkehr]).erlaubt).toBe(true);
});
it("gibt die Abwesenheit frei, sobald die Rückkehr weg ist", () => {
expect(darfKorrigiertWerden(karenz, HEUTE, [karenz]).erlaubt).toBe(true);
});
it("stört sich nicht an einer früheren Rückkehr aus einer anderen Abwesenheit", () => {
const frueher = eintrag({ id: "r0", event_type: "Rückkehr", event_date: "2026-01-05", created_at: "2026-01-05T09:00:00.000Z" });
expect(darfKorrigiertWerden(karenz, HEUTE, [frueher, karenz]).erlaubt).toBe(true);
});
it("lässt eine noch nicht wirksame Abwesenheit in Ruhe", () => {
const geplant = eintrag({ event_type: "Karenz", event_date: "2099-01-01", pending_id: "p1" });
const u = darfKorrigiertWerden(geplant, HEUTE, [geplant]);
expect(u.erlaubt).toBe(false);
expect(u.erlaubt === false && u.grund).toMatch(/noch nicht wirksam/);
});
});