From 20d0520b7d56fd4f969ee6605102d6b04632b76e Mon Sep 17 00:00:00 2001 From: Raykov-MS Date: Tue, 30 Jun 2026 10:54:09 +0300 Subject: [PATCH 1/3] =?UTF-8?q?=D0=9F=D0=BE=D0=BF=D1=80=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BA=D0=B8=20=D0=B2=20=D1=82?= =?UTF-8?q?=D0=B5=D1=81=D1=82=D0=B0=D1=85=20=D0=B8=20=D1=84=D1=83=D0=BD?= =?UTF-8?q?=D0=BA=D1=86=D0=B8=D1=8E=20=D0=B2=20=D0=B1=D0=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/alembic/versions/sql/0002_functions.sql | 20 +++++++++++++++---- .../integration/test_projects_api_smoke.py | 2 ++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/api/alembic/versions/sql/0002_functions.sql b/api/alembic/versions/sql/0002_functions.sql index cdf70dc..c19ea53 100644 --- a/api/alembic/versions/sql/0002_functions.sql +++ b/api/alembic/versions/sql/0002_functions.sql @@ -1571,7 +1571,7 @@ AS $function$ DECLARE v_report_id INT; v_eid INT; - v_org_id INT; + v_form_id INT; v_ei_path INT[]; BEGIN -- Извлекаем report_id + ei ДО DELETE (нужен для path) @@ -1585,21 +1585,33 @@ BEGIN v_ei_path := v3._expense_item_path_set(ARRAY[v_eid]); + SELECT bf.id + INTO v_form_id + FROM v3.rf_project_report r + JOIN v3.project p + ON p.id = r.project_id + LEFT JOIN v3.budget_form bf + ON bf.form_type_code = 'FORM_3' + AND bf.year = r.year + AND bf.org_unit_id = p.org_unit_id + WHERE r.id = v_report_id + LIMIT 1; + -- Каскад (FK без ON DELETE CASCADE) DELETE FROM v3.rf_project_report_quarter WHERE rf_project_report_line_id = p_line_id; DELETE FROM v3.rf_project_report_line WHERE id = p_line_id; - SELECT org_unit_id INTO v_org_id FROM v3.project WHERE id = v_report_id; -- Аудит: ROW_DELETE PERFORM v3.log_event( 'ROW_DELETE', 'ROW', jsonb_build_object( 'sheet', 'FORM_3', 'line_id', p_line_id, - 'entity_id', p_line_id, + 'form_id', v_form_id, 'report_id', v_report_id, 'expense_item_id', v_eid - ), null, null, v_org_id + ), + v_form_id ); -- Возврат: только иерархия по пути удалённой (INPUT уже нет) diff --git a/api/tests/integration/test_projects_api_smoke.py b/api/tests/integration/test_projects_api_smoke.py index dc21b78..a4bd92b 100644 --- a/api/tests/integration/test_projects_api_smoke.py +++ b/api/tests/integration/test_projects_api_smoke.py @@ -86,6 +86,8 @@ def test_projects_write_smoke(client, admin_tokens, auth_headers): f"/api/v1/projects/{project_id}/report/2026/LIMIT/line/{line_id}", headers=auth_headers(admin_tokens), ) + + print(del_line_response.status_code, del_line_response.json()) assert del_line_response.status_code == 200 From 48c7ab3eb1237fcaf1f20d565bf62ae1f3813133 Mon Sep 17 00:00:00 2001 From: Raykov-MS Date: Tue, 30 Jun 2026 10:54:56 +0300 Subject: [PATCH 2/3] del print --- api/tests/integration/test_projects_api_smoke.py | 1 - 1 file changed, 1 deletion(-) diff --git a/api/tests/integration/test_projects_api_smoke.py b/api/tests/integration/test_projects_api_smoke.py index a4bd92b..eaac624 100644 --- a/api/tests/integration/test_projects_api_smoke.py +++ b/api/tests/integration/test_projects_api_smoke.py @@ -87,7 +87,6 @@ def test_projects_write_smoke(client, admin_tokens, auth_headers): headers=auth_headers(admin_tokens), ) - print(del_line_response.status_code, del_line_response.json()) assert del_line_response.status_code == 200 From 0c10be7eb10ff8c8d1117540fdcd00774d748136 Mon Sep 17 00:00:00 2001 From: Raykov-MS Date: Tue, 30 Jun 2026 10:56:23 +0300 Subject: [PATCH 3/3] del space --- api/tests/integration/test_projects_api_smoke.py | 1 - 1 file changed, 1 deletion(-) diff --git a/api/tests/integration/test_projects_api_smoke.py b/api/tests/integration/test_projects_api_smoke.py index eaac624..dc21b78 100644 --- a/api/tests/integration/test_projects_api_smoke.py +++ b/api/tests/integration/test_projects_api_smoke.py @@ -86,7 +86,6 @@ def test_projects_write_smoke(client, admin_tokens, auth_headers): f"/api/v1/projects/{project_id}/report/2026/LIMIT/line/{line_id}", headers=auth_headers(admin_tokens), ) - assert del_line_response.status_code == 200