60 lines
2.2 KiB
Python
60 lines
2.2 KiB
Python
"""Выбор дерева счетов и отчётной колонки без догадок по is_current."""
|
||
|
||
import datetime as dt
|
||
from decimal import Decimal
|
||
from types import SimpleNamespace as N
|
||
from uuid import UUID
|
||
|
||
import pytest
|
||
from sqlalchemy import select
|
||
|
||
from src.models.accounting import ChartOfAccount
|
||
from src.models.enums import StatementLineStatus
|
||
from src.repositories.goodwill import accounts
|
||
from src.services.goodwill_source import capital_amounts
|
||
|
||
|
||
@pytest.mark.integration
|
||
async def test_accounts_query_loads_only_investment_subtree(seeded) -> None:
|
||
root = (await seeded.scalars(select(ChartOfAccount).where(ChartOfAccount.code == "58.01"))).one()
|
||
child = ChartOfAccount(
|
||
code="GOODWILL_CHILD",
|
||
name="Потомок 58.01",
|
||
parent_id=root.id,
|
||
kind=root.kind,
|
||
row_type=root.row_type,
|
||
)
|
||
sibling = ChartOfAccount(
|
||
code="58.0199",
|
||
name="Похожий код вне ветки",
|
||
parent_id=root.parent_id,
|
||
kind=root.kind,
|
||
row_type=root.row_type,
|
||
)
|
||
seeded.add_all([child, sibling])
|
||
await seeded.flush()
|
||
selected = await accounts(seeded)
|
||
ids = {account.id for account in selected}
|
||
assert {root.id, child.id} <= ids
|
||
assert sibling.id not in ids
|
||
assert all(account.id == root.id or account.parent_id in ids for account in selected)
|
||
|
||
|
||
def test_capital_aggregates_duplicates_at_period_end() -> None:
|
||
mid, col = UUID(int=1), UUID(int=2)
|
||
columns = [
|
||
N(id=col, meta_id=mid, period_date=dt.date(2025, 9, 30), is_current=False),
|
||
N(id=UUID(int=3), meta_id=mid, period_date=dt.date(2024, 12, 31), is_current=True),
|
||
]
|
||
values = [
|
||
(
|
||
N(id=UUID(int=i), meta_id=mid, line_code="1310", row_index=i, line_status=StatementLineStatus.ok),
|
||
col,
|
||
Decimal(amount),
|
||
)
|
||
for i, amount in [(4, "100"), (5, "20")]
|
||
]
|
||
assert capital_amounts(mid, "тыс. руб.", columns, values, dt.date(2025, 9, 30)) == (Decimal("120000"), None)
|
||
assert capital_amounts(mid, "тыс. руб.", columns, values, dt.date(2025, 6, 30)) == (None, None)
|
||
assert capital_amounts(mid, None, columns, values, dt.date(2025, 9, 30)) == (None, None)
|