Kostenstelle umbenennen, in der Oberflaeche und im Import
rename_cost_center aendert nur die Bezeichnung; die Nummer bleibt, sie verbindet die Kostenstelle mit dem fuehrenden System und jeder Kontierung. Kein Stichtag, die bisherige Bezeichnung steht im Audit-Log. Positionen: Knopf "Kostenstelle umbenennen" mit Auswahl und neuer Bezeichnung. Blatt Kostenstellen: eine andere Bezeichnung bei vorhandener Nummer benennt um. Geprueft: Rauchtest Schritt 23 (Bezeichnung neu, Nummer und Kontierung bleiben, Protokoll) 35/35; Integrationstest Umbenennen per Import; alle Migrationen auf leerer Datenbank, zweiter Lauf leer; lint, tsc, types:check, 1014 Unit-Tests, Waechter.
This commit is contained in:
60
db/migrations/20261030100000_kostenstelle_umbenennen.sql
Normal file
60
db/migrations/20261030100000_kostenstelle_umbenennen.sql
Normal file
@@ -0,0 +1,60 @@
|
||||
-- Eine Kostenstelle umbenennen — nur die Bezeichnung.
|
||||
--
|
||||
-- Die Nummer bleibt: sie verbindet die Kostenstelle mit dem führenden System
|
||||
-- und mit jeder Kontierung. Eine Umbenennung hat keinen Stichtag, sie gilt
|
||||
-- auch rückwirkend für jede Anzeige. Die bisherige Bezeichnung steht im
|
||||
-- Protokoll.
|
||||
create or replace function public.rename_cost_center(payload jsonb)
|
||||
returns void
|
||||
language plpgsql
|
||||
set search_path = public, pg_temp
|
||||
as $$
|
||||
declare
|
||||
v_id uuid := (payload->>'cost_center_id')::uuid;
|
||||
v_name text := nullif(btrim(payload->>'name'), '');
|
||||
v_alt cost_centers%rowtype;
|
||||
begin
|
||||
perform require_hr_admin();
|
||||
|
||||
if v_name is null then
|
||||
raise exception 'Bitte eine Bezeichnung angeben.';
|
||||
end if;
|
||||
|
||||
select * into v_alt from cost_centers where id = v_id for update;
|
||||
if not found then
|
||||
raise exception 'Die Kostenstelle existiert nicht.';
|
||||
end if;
|
||||
if v_alt.name = v_name then
|
||||
raise exception 'Die Bezeichnung ist unverändert.';
|
||||
end if;
|
||||
|
||||
update cost_centers set name = v_name where id = v_id;
|
||||
|
||||
insert into audit_log (actor_user_id, actor_name, action, target_label, details)
|
||||
values (app_current_user_id(), current_actor_name(), 'Kostenstelle umbenannt',
|
||||
v_alt.code || ' · ' || v_name,
|
||||
'Bisherige Bezeichnung: ' || v_alt.name);
|
||||
end;
|
||||
$$;
|
||||
|
||||
grant execute on function public.rename_cost_center(jsonb) to alpenwerk_app;
|
||||
|
||||
do $pruefung$
|
||||
declare
|
||||
v_def text;
|
||||
begin
|
||||
select pg_get_functiondef(p.oid) into v_def
|
||||
from pg_proc p join pg_namespace n on n.oid = p.pronamespace
|
||||
where n.nspname = 'public' and p.prokind = 'f' and p.proname = 'rename_cost_center';
|
||||
if position(E'begin\n perform require_hr_admin();' in v_def) = 0
|
||||
or position('insert into audit_log' in v_def) = 0 then
|
||||
raise exception 'rename_cost_center prüft die Rechte nicht oder schreibt kein Protokoll.';
|
||||
end if;
|
||||
if position('set code' in v_def) > 0 then
|
||||
raise exception 'rename_cost_center darf die Nummer nicht ändern.';
|
||||
end if;
|
||||
if (select prosecdef from pg_proc where oid = 'public.rename_cost_center'::regproc) then
|
||||
raise exception 'rename_cost_center darf nicht SECURITY DEFINER sein.';
|
||||
end if;
|
||||
end
|
||||
$pruefung$;
|
||||
@@ -670,7 +670,15 @@ begin
|
||||
if v_ging or v_meldung not like '%gibt es bereits%' then
|
||||
raise exception 'Eine doppelte Kostenstellennummer wurde angenommen (%).', v_meldung;
|
||||
end if;
|
||||
raise notice '23/35 Kostenstelle angelegt und zugeordnet, doppelte Nummer abgewiesen';
|
||||
-- Umbenennen ändert nur die Bezeichnung; Nummer und Kontierung bleiben.
|
||||
perform rename_cost_center(jsonb_build_object('cost_center_id', v_stelle, 'name', 'Rauchtest Umbenannt'));
|
||||
if (select code <> 'RAUCHTEST-KST' or name <> 'Rauchtest Umbenannt' from cost_centers where id = v_stelle)
|
||||
or not exists (select 1 from position_cost_centers where position_id = v_p8 and cost_center_id = v_stelle)
|
||||
or not exists (select 1 from audit_log where action = 'Kostenstelle umbenannt'
|
||||
and details = 'Bisherige Bezeichnung: Rauchtest Kostenstelle') then
|
||||
raise exception 'Die Kostenstelle ist nicht umbenannt, hat ihre Nummer oder Kontierung verloren oder fehlt im Protokoll.';
|
||||
end if;
|
||||
raise notice '23/35 Kostenstelle angelegt, zugeordnet und umbenannt, doppelte Nummer abgewiesen';
|
||||
|
||||
-- ── Geplante Abwesenheit berichtigen (20261020120000) ───────────
|
||||
-- Über „Eintrag berichtigen": der Beginn wandert, die geplante Rückkehr
|
||||
|
||||
Reference in New Issue
Block a user