Квартальные ОСВ, загруженные в консолидацию своего периода и уже привязанные, в режиме становились «нарастающими за квартал версии»: select_sources возвращал все такие документы, и свод брал их строки как есть — консолидация РБ 2024 Q3 на стенде задвоилась бы. Теперь подмена — только если период шапки версии не подходит (fits_by_header); регрессионный тест test_mode_keeps_header_period_when_it_fits_version. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
90 lines
4.0 KiB
Python
90 lines
4.0 KiB
Python
"""Временный режим «период ОСВ из версии консолидации» (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", "fits_by_header", "expected"),
|
||
[
|
||
(True, DocumentType.OSV, CONSOLIDATION, False, True), # ОСВ «не того» периода загружена в эту консолидацию
|
||
(True, DocumentType.OSV, CONSOLIDATION, True, False), # период шапки и так подходит — склейка кварталов цела
|
||
(False, DocumentType.OSV, CONSOLIDATION, False, False), # режим выключен — период из шапки
|
||
(True, DocumentType.OSV, OTHER, False, False), # загружена в другую консолидацию
|
||
(True, DocumentType.OSV, None, False, False), # загружена с рабочего стола, без консолидации
|
||
(True, DocumentType.BALANCE, CONSOLIDATION, False, False), # ББ/ОФР — только период из шапки
|
||
(True, DocumentType.INCOME, CONSOLIDATION, False, False),
|
||
],
|
||
)
|
||
def test_takes_version_period(
|
||
enabled: bool,
|
||
document_type: DocumentType,
|
||
file_consolidation_id: uuid.UUID | None,
|
||
fits_by_header: bool,
|
||
expected: bool,
|
||
) -> None:
|
||
assert (
|
||
takes_version_period(
|
||
enabled=enabled,
|
||
document_type=document_type,
|
||
file_consolidation_id=file_consolidation_id,
|
||
consolidation_id=CONSOLIDATION,
|
||
fits_by_header=fits_by_header,
|
||
)
|
||
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
|