From d542a228e0c3ddd9ec0f35dc1342f9dfd465da49 Mon Sep 17 00:00:00 2001 From: Andrey Epifancev Date: Mon, 2 Nov 2026 20:17:48 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B5=D0=B2=D1=8C=D1=8E=20#208=20(I-7):?= =?UTF-8?q?=20=D0=BE=D1=81=D0=B8=D1=80=D0=BE=D1=82=D0=B5=D0=B2=D1=88=D0=B0?= =?UTF-8?q?=D1=8F=20APPLIED-=D0=BA=D0=BE=D1=80=D1=80=D0=B5=D0=BA=D1=82?= =?UTF-8?q?=D0=B8=D1=80=D0=BE=D0=B2=D0=BA=D0=B0=20=D1=82=D1=80=D0=B5=D0=B1?= =?UTF-8?q?=D1=83=D0=B5=D1=82=20=D0=BF=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D0=BA?= =?UTF-8?q?=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit attach_corrections молча пропускала (continue) корректировку, чей агрегат (rule_id, пара ЮЛ) больше не существует после пересчёта разнесения ВГО — вместо этого, как и в остальных ветках функции, поднимаем ConflictError("CORRECTION_REVIEW_REQUIRED"). --- api/src/services/corrections_view.py | 2 +- api/tests/test_corrections_view.py | 56 ++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 api/tests/test_corrections_view.py diff --git a/api/src/services/corrections_view.py b/api/src/services/corrections_view.py index d3eb719..c301d26 100644 --- a/api/src/services/corrections_view.py +++ b/api/src/services/corrections_view.py @@ -31,7 +31,7 @@ def attach_corrections( for key, corrections in grouped.items(): aggregate = by_key.get(key) if aggregate is None: - continue + raise ConflictError("CORRECTION_REVIEW_REQUIRED", "Корректировка ссылается на агрегат, которого больше нет") ordered = sorted(corrections, key=lambda c: (c.parent_correction_id is not None, c.id)) roots = [c for c in ordered if c.parent_correction_id is None] root_ids = {c.id for c in roots} diff --git a/api/tests/test_corrections_view.py b/api/tests/test_corrections_view.py new file mode 100644 index 0000000..5e30fc9 --- /dev/null +++ b/api/tests/test_corrections_view.py @@ -0,0 +1,56 @@ +import uuid +from decimal import Decimal + +import pytest + +from src.common.exceptions import ConflictError +from src.models.kfo import Correction +from src.schemas.consolidations import RefOut +from src.schemas.corrections import AggregateSideOut, CorrectionAggregateOut +from src.services.corrections_view import attach_corrections + +ZERO = Decimal("0") + + +def _side() -> AggregateSideOut: + return AggregateSideOut(article_line="1230", accounts=[], amount=ZERO, entries=[]) + + +def _aggregate(rule_id: uuid.UUID, company_1: uuid.UUID, company_2: uuid.UUID) -> CorrectionAggregateOut: + return CorrectionAggregateOut( + rule_id=rule_id, + rule_no=1, + company_1=RefOut(id=company_1, name="А"), + company_2=RefOut(id=company_2, name="Б"), + side_1=_side(), + side_2=_side(), + deviation_amount=ZERO, + deviation_percent=None, + exceeds_threshold=False, + status="AUTO", + eliminated_amount=ZERO, + correction=None, + ) + + +def _correction(rule_id: uuid.UUID, legal_entity_id: uuid.UUID, counterparty_id: uuid.UUID) -> Correction: + return Correction( + id=uuid.uuid4(), + rule_id=rule_id, + legal_entity_id=legal_entity_id, + counterparty_id=counterparty_id, + parent_correction_id=None, + comment="комментарий", + version_no=1, + ) + + +async def test_attach_corrections_rejects_correction_for_aggregate_that_no_longer_exists() -> None: + rule_id, company_1, company_2 = uuid.uuid4(), uuid.uuid4(), uuid.uuid4() + aggregates = [_aggregate(uuid.uuid4(), company_1, company_2)] + corrections = [_correction(rule_id, company_1, company_2)] + + with pytest.raises(ConflictError) as excinfo: + attach_corrections(aggregates, corrections, {}) + + assert excinfo.value.code == "CORRECTION_REVIEW_REQUIRED"