arm-core/api/tests/test_domain_version_period.py
Andrey Epifancev 1ae6b8d2da feat(consolidation): временный режим «период ОСВ из версии консолидации» (#103)
Настройка CONSOLIDATION_PERIOD_FROM_VERSION (по умолчанию false; в контуре —
OPENBAO__APP__CONSOLIDATION_PERIOD_FROM_VERSION): ОСВ, загруженная в консолидацию
(stored_file.consolidation_id), считается нарастающей за год и квартал консолидации,
какой бы период ни стоял в шапке. Нужен для тестов на произвольных ОСВ: без него ОСВ
за 1 кв. 2025 в консолидации 2026 Q1 молча не привязывается и свод пуст.

- domain/version_period.py: представление документа с периодом версии (первичка не меняется)
- consolidation_documents.for_consolidation: единая точка подмены; её используют привязка
  (fits, ключ R-1, bind_confirmed, хуки подтверждения и маппинга), свод, чек-лист,
  колонка «ОСВ» периметра (osv_accounts)
- ББ/ОФР и файлы с рабочего стола режим не затрагивает; склейки кварталов в режиме нет
- тесты: unit на чистые функции, интеграционные — сценарий 2025 Q1 → 2026 Q1 с режимом
  и без, файл вне консолидации, чек-лист и карточка, подхват «один слот на счёт»

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-12 19:17:01 +04:00

84 lines
3.7 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""Временный режим «период ОСВ из версии консолидации» (arm-core#103): чистые функции `domain.version_period`."""
import datetime
import uuid
import pytest
from src.domain.version_period import takes_version_period, with_version_period
from src.models.consolidation import Consolidation, ConsolidationVersion
from src.models.enums import ConsolidationStatus, DocumentStatus, DocumentType, PeriodQuarter
from src.models.files import Document
from src.services.consolidation_documents import fits
CONSOLIDATION = uuid.uuid4()
OTHER = uuid.uuid4()
MEMBER = uuid.uuid4()
@pytest.mark.parametrize(
("enabled", "document_type", "file_consolidation_id", "expected"),
[
(True, DocumentType.OSV, CONSOLIDATION, True), # ОСВ загружена в эту консолидацию
(False, DocumentType.OSV, CONSOLIDATION, False), # режим выключен — период из шапки
(True, DocumentType.OSV, OTHER, False), # загружена в другую консолидацию
(True, DocumentType.OSV, None, False), # загружена с рабочего стола, без консолидации
(True, DocumentType.BALANCE, CONSOLIDATION, False), # ББ/ОФР — только период из шапки
(True, DocumentType.INCOME, CONSOLIDATION, False),
],
)
def test_takes_version_period(
enabled: bool, document_type: DocumentType, file_consolidation_id: uuid.UUID | None, expected: bool
) -> None:
assert (
takes_version_period(
enabled=enabled,
document_type=document_type,
file_consolidation_id=file_consolidation_id,
consolidation_id=CONSOLIDATION,
)
is expected
)
def _document(*, year: int | None = 2025, quarter: PeriodQuarter | None = PeriodQuarter.Q1) -> Document:
return Document(
id=uuid.uuid4(),
legal_entity_id=MEMBER,
document_type=DocumentType.OSV,
osv_account_code="60",
period_year=year,
period_quarter=quarter,
is_cumulative=False,
status=DocumentStatus.CONFIRMED,
confirmed_at=datetime.datetime(2026, 10, 12, tzinfo=datetime.UTC),
)
def test_with_version_period_takes_year_and_quarter_of_version_as_cumulative() -> None:
document = _document()
view = with_version_period(document, year=2026, quarter=PeriodQuarter.Q3)
assert (view.period_year, view.period_quarter, view.is_cumulative) == (2026, PeriodQuarter.Q3, True)
assert (view.id, view.legal_entity_id, view.document_type, view.osv_account_code) == (
document.id,
MEMBER,
DocumentType.OSV,
"60",
)
assert (view.status, view.confirmed_at) == (document.status, document.confirmed_at)
# первичка не мутируется: документ сохраняет период из шапки
assert (document.period_year, document.period_quarter, document.is_cumulative) == (2025, PeriodQuarter.Q1, False)
@pytest.mark.parametrize("quarter", [None, PeriodQuarter.Q4])
def test_version_period_fits_version_whatever_header_period(quarter: PeriodQuarter | None) -> None:
"""Документ без квартала или за другой год/квартал в представлении версии подходит ей (если ЮЛ — член)."""
consolidation = Consolidation(year=2026, quarter=PeriodQuarter.Q2)
version = ConsolidationVersion(status=ConsolidationStatus.INITIATED)
view = with_version_period(_document(year=2024, quarter=quarter), year=2026, quarter=PeriodQuarter.Q2)
assert fits(view, version, consolidation, {MEMBER}) is True
assert fits(view, version, consolidation, {uuid.uuid4()}) is False