From 8192807d5571170bca0b74da172a00e6d8728d4c Mon Sep 17 00:00:00 2001 From: longieirl Date: Wed, 25 Mar 2026 15:26:42 +0000 Subject: [PATCH] refactor(#45): delete TransactionProcessingOrchestrator - Remove transaction_processing_orchestrator.py and its test file - Remove unused import and instantiation from processor.py - Clean up stale docstring references in service_registry.py group_by_iban is now accessed via ServiceRegistry directly. --- .../src/bankstatements_core/processor.py | 8 --- .../services/service_registry.py | 8 +-- .../transaction_processing_orchestrator.py | 64 ------------------- ...est_transaction_processing_orchestrator.py | 60 ----------------- 4 files changed, 2 insertions(+), 138 deletions(-) delete mode 100644 packages/parser-core/src/bankstatements_core/services/transaction_processing_orchestrator.py delete mode 100644 packages/parser-core/tests/services/test_transaction_processing_orchestrator.py diff --git a/packages/parser-core/src/bankstatements_core/processor.py b/packages/parser-core/src/bankstatements_core/processor.py index 4f524f6..8b4f20f 100644 --- a/packages/parser-core/src/bankstatements_core/processor.py +++ b/packages/parser-core/src/bankstatements_core/processor.py @@ -29,9 +29,6 @@ TransactionSortingService, ) from bankstatements_core.services.transaction_filter import TransactionFilterService -from bankstatements_core.services.transaction_processing_orchestrator import ( - TransactionProcessingOrchestrator, -) from bankstatements_core.utils import is_date_column, to_float # noqa: F401 logger = logging.getLogger(__name__) @@ -247,11 +244,6 @@ def __init__( entitlements=self.entitlements, ) - self._transaction_orchestrator = TransactionProcessingOrchestrator( - duplicate_detector=self._duplicate_service, - sorting_service=self._sorting_service, - ) - # ServiceRegistry: single wiring point for transaction processing if registry is not None: self._registry = registry diff --git a/packages/parser-core/src/bankstatements_core/services/service_registry.py b/packages/parser-core/src/bankstatements_core/services/service_registry.py index 52acfaa..10c304c 100644 --- a/packages/parser-core/src/bankstatements_core/services/service_registry.py +++ b/packages/parser-core/src/bankstatements_core/services/service_registry.py @@ -1,8 +1,7 @@ """ServiceRegistry — single wiring point for transaction processing services. Centralises construction of duplicate detection, sorting, IBAN grouping, and -the enrichment/classification pipeline that was previously spread across -TransactionProcessingOrchestrator and BankStatementProcessor. +the enrichment/classification pipeline. Usage (primary path):: @@ -149,9 +148,6 @@ def process_transaction_group( ) -> tuple[list[dict], list[dict]]: """Enrich → classify → deduplicate → sort a group of transactions. - This replaces the explicit five-call chain that was previously spread - across BankStatementProcessor and TransactionProcessingOrchestrator. - Args: transactions: List of transaction dicts for a single IBAN group. template: Optional bank template used for transaction type keywords. @@ -205,7 +201,7 @@ def get_grouping_service(self) -> "IIBANGrouping": return self._grouping_service # ------------------------------------------------------------------ - # Internal enrichment helpers (inlined from TransactionProcessingOrchestrator) + # Internal enrichment helpers # ------------------------------------------------------------------ @staticmethod diff --git a/packages/parser-core/src/bankstatements_core/services/transaction_processing_orchestrator.py b/packages/parser-core/src/bankstatements_core/services/transaction_processing_orchestrator.py deleted file mode 100644 index 077bb25..0000000 --- a/packages/parser-core/src/bankstatements_core/services/transaction_processing_orchestrator.py +++ /dev/null @@ -1,64 +0,0 @@ -"""Transaction Processing Orchestrator for bank statements. - -This module orchestrates IBAN grouping. Enrichment, classification, duplicate -detection and sorting have moved to ServiceRegistry. - -Note: This class is retained for backward compatibility. A follow-up issue will -track its complete removal once all callers migrate to ServiceRegistry. -""" - -from __future__ import annotations - -import logging -from typing import TYPE_CHECKING - -if TYPE_CHECKING: - from bankstatements_core.domain.protocols.services import ( - IDuplicateDetector, - IIBANGrouping, - ITransactionSorting, - ) - -logger = logging.getLogger(__name__) - - -class TransactionProcessingOrchestrator: - """Orchestrates IBAN grouping for transaction processing. - - Note: enrichment and classification logic has moved to ServiceRegistry. - This class is retained for backward compatibility and will be removed in a - follow-up. - """ - - def __init__( - self, - duplicate_detector: "IDuplicateDetector", - sorting_service: "ITransactionSorting", - grouping_service: "IIBANGrouping | None" = None, - ): - """Initialize transaction processing orchestrator. - - Args: - duplicate_detector: Service for detecting duplicates - sorting_service: Service for sorting transactions - grouping_service: Service for grouping by IBAN (optional, creates default if None) - """ - from bankstatements_core.services.iban_grouping import IBANGroupingService - - self.duplicate_detector = duplicate_detector - self.sorting_service = sorting_service - self.grouping_service = grouping_service or IBANGroupingService() - - def group_by_iban( - self, transactions: list[dict], pdf_ibans: dict[str, str] - ) -> dict[str, list[dict]]: - """Group transactions by their source IBAN. - - Args: - transactions: List of transaction dictionaries - pdf_ibans: Dictionary mapping PDF filenames to IBANs - - Returns: - Dictionary mapping IBANs to their transactions - """ - return self.grouping_service.group_by_iban(transactions, pdf_ibans) diff --git a/packages/parser-core/tests/services/test_transaction_processing_orchestrator.py b/packages/parser-core/tests/services/test_transaction_processing_orchestrator.py deleted file mode 100644 index 30f8f6a..0000000 --- a/packages/parser-core/tests/services/test_transaction_processing_orchestrator.py +++ /dev/null @@ -1,60 +0,0 @@ -"""Tests for TransactionProcessingOrchestrator. - -The orchestrator now only handles IBAN grouping. Enrichment, classification, -duplicate detection and sorting are tested via test_service_registry.py. -""" - -from __future__ import annotations - -from unittest.mock import Mock - -import pytest - -from bankstatements_core.services.transaction_processing_orchestrator import ( - TransactionProcessingOrchestrator, -) - - -@pytest.fixture -def mock_duplicate_detector(): - detector = Mock() - detector.detect_and_separate.return_value = ([], []) - return detector - - -@pytest.fixture -def mock_sorting_service(): - sorter = Mock() - sorter.sort.side_effect = lambda x: x - return sorter - - -@pytest.fixture -def orchestrator(mock_duplicate_detector, mock_sorting_service): - return TransactionProcessingOrchestrator( - duplicate_detector=mock_duplicate_detector, - sorting_service=mock_sorting_service, - ) - - -class TestGroupByIBAN: - def test_delegates_to_grouping_service(self, orchestrator): - transactions = [ - {"Date": "01/12/2023", "Details": "Test", "Filename": "test1.pdf"}, - {"Date": "02/12/2023", "Details": "Test2", "Filename": "test2.pdf"}, - ] - pdf_ibans = {"test1.pdf": "IE12345", "test2.pdf": "IE67890"} - - orchestrator.grouping_service = Mock() - orchestrator.grouping_service.group_by_iban.return_value = { - "IE12345": [transactions[0]], - "IE67890": [transactions[1]], - } - - result = orchestrator.group_by_iban(transactions, pdf_ibans) - - orchestrator.grouping_service.group_by_iban.assert_called_once_with( - transactions, pdf_ibans - ) - assert "IE12345" in result - assert "IE67890" in result