From 2f08ce4155a45306e09f3ef7ced409d657c9d5bc Mon Sep 17 00:00:00 2001 From: PotapovaA Date: Wed, 21 Oct 2026 19:02:41 +0300 Subject: [PATCH] =?UTF-8?q?test(matrix):=20=D0=BF=D1=80=D0=BE=D0=B2=D0=B5?= =?UTF-8?q?=D1=80=D0=B8=D1=82=D1=8C=20=D0=BF=D1=80=D0=B5=D1=81=D0=B5=D1=82?= =?UTF-8?q?=20=D1=81=20=D0=BA=D1=80=D0=B5=D0=B4=D0=B8=D1=82=D0=BE=D0=B2?= =?UTF-8?q?=D0=BE=D0=B9=20=D0=BF=D0=B5=D1=80=D0=B2=D0=BE=D0=B9=20=D1=81?= =?UTF-8?q?=D1=82=D0=BE=D1=80=D0=BE=D0=BD=D0=BE=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/tests/test_intercompany_matrix.py | 34 +++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/api/tests/test_intercompany_matrix.py b/api/tests/test_intercompany_matrix.py index aaef320..d417d72 100644 --- a/api/tests/test_intercompany_matrix.py +++ b/api/tests/test_intercompany_matrix.py @@ -174,6 +174,40 @@ async def test_preset_applies_exclusions_to_its_own_side_and_rule_measure(monkey assert info.article_2_line == rule.article_2_line +async def test_preset_credit_first_uses_second_side_for_debit(monkeypatch: pytest.MonkeyPatch) -> None: + credit_parent = _account(AccountKind.P) + credit_child = _account(AccountKind.P, credit_parent.id) + debit_parent = _account(AccountKind.A) + debit_child = _account(AccountKind.A, debit_parent.id) + accounts = [credit_parent, credit_child, debit_parent, debit_child] + by_id, children = matrix._make_account_tree(accounts) + rule = SimpleNamespace( + version_no=1, + valid_to=None, + statement_type=StatementType.balance, + side_1="K", + measure="turnover", + ) + rule_accounts = [ + SimpleNamespace(company_no=1, account_id=credit_parent.id, is_excluded=False), + SimpleNamespace(company_no=1, account_id=credit_child.id, is_excluded=True), + SimpleNamespace(company_no=2, account_id=debit_parent.id, is_excluded=False), + ] + monkeypatch.setattr( + matrix.elimination_rules_repo, "rule_with_account", AsyncMock(return_value=(rule, rule_accounts)) + ) + service = matrix.IntercompanyMatrixService(object(), None, object()) + + selection, selected_rule = await service._resolve_preset_selection( + uuid.uuid4(), SimpleNamespace(elimination_rules_version=1), by_id, children + ) + + assert selected_rule is rule + assert selection.company_1_account_ids == {debit_parent.id, debit_child.id} + assert selection.company_2_account_ids == {credit_parent.id} + assert selection.measure == "turnover" + + async def test_preset_rejects_income_rule_before_selecting_accounts(monkeypatch: pytest.MonkeyPatch) -> None: rule = SimpleNamespace( statement_type=StatementType.income,