"""Сборка агрегатов из уже готовых назначений ОСВ.""" import uuid from decimal import Decimal from types import SimpleNamespace from src.services.correction_source import ( VgoAssignmentCorrectionSource, _AggregateGroup, _company_no, _EntryGroup, _RuleSpec, ) SECOND_COMPANY = 2 def _rule(**changes): values = dict( id=uuid.uuid4(), rule_no=6, article_1_line="1230", article_2_line="1520", side_1="D", measure="closing", elimination_mode="min", ) values.update(changes) return SimpleNamespace(**values) def test_assigned_entries_form_oriented_company_aggregate() -> None: first = SimpleNamespace(id=uuid.uuid4(), name="Компания А") second = SimpleNamespace(id=uuid.uuid4(), name="Компания Б") rule = _rule() group = _AggregateGroup(rule, first, second) group.entries[1][(first.id, second.id, "62.01", "D")] = _EntryGroup( [uuid.UUID(int=2), uuid.UUID(int=1)], Decimal("100.00") ) group.entries[2][(second.id, first.id, "60.01", "K")] = _EntryGroup([uuid.UUID(int=3)], Decimal("95.00")) aggregate = VgoAssignmentCorrectionSource._aggregate(group) assert (aggregate.company_1.id, aggregate.company_2.id) == (first.id, second.id) assert aggregate.side_1.amount == Decimal("100.00") assert aggregate.side_2.amount == Decimal("95.00") assert aggregate.deviation_percent == Decimal("5") / Decimal("95") * 100 assert aggregate.exceeds_threshold assert aggregate.side_1.entries[0].entry_ids == [uuid.UUID(int=1), uuid.UUID(int=2)] def test_overlapping_rule_accounts_use_nonzero_rule_direction() -> None: account_id = uuid.uuid4() rule = _rule() spec = _RuleSpec(rule) spec.included[1].add(account_id) spec.included[2].add(account_id) debit_entry = SimpleNamespace( account_id=account_id, closing_debit=Decimal("10"), closing_credit=Decimal("0"), turnover_debit=Decimal("0"), turnover_credit=Decimal("0"), ) credit_entry = SimpleNamespace( account_id=account_id, closing_debit=Decimal("0"), closing_credit=Decimal("10"), turnover_debit=Decimal("0"), turnover_credit=Decimal("0"), ) assert _company_no(spec, debit_entry) == 1 assert _company_no(spec, credit_entry) == SECOND_COMPANY