diff --git a/src/services/transaction_import_service.py b/src/services/transaction_import_service.py index 1b6a7f2..f6f59c2 100644 --- a/src/services/transaction_import_service.py +++ b/src/services/transaction_import_service.py @@ -47,8 +47,11 @@ def import_file(self, file: str) -> bool: stored_transactions = self.api.accounts.get_account_transactions( account_id=account.id, start_date=start_date, end_date=end_date) - stored_transactions_by_reference = {t.internal_reference: t for t in stored_transactions - if t.internal_reference is not None} + stored_transactions_by_reference = { + hash_part.strip(): t + for t in stored_transactions + for hash_part in (t.internal_reference.split(',') if t.internal_reference is not None else []) + if hash_part} tag = self.__create_tag_for_import(file, account, start_date, end_date) if not self.dry_run else None diff --git a/src/services/transaction_link_service.py b/src/services/transaction_link_service.py index ff17eba..9fce4bc 100644 --- a/src/services/transaction_link_service.py +++ b/src/services/transaction_link_service.py @@ -10,6 +10,10 @@ from ..firefly_api.api import FireflyApi +DEFAULT_AMOUNT_DIFF_PERCENTAGE = 2.0 +DEFAULT_DATE_DIFF_DAYS = 3 + + class TransactionLinkService(BaseService): def __init__(self, api: FireflyApi, dry_run: bool) -> None: @@ -61,7 +65,10 @@ def link_identical_transactions( def __get_identical_transactions_by_source( self, start_date: datetime = None, end_date: datetime = None, - amount_diff_percentage: float = 2.0, date_diff_days: int = 3) -> Dict[Transaction, List[Transaction]]: + amount_diff_percentage: float = DEFAULT_AMOUNT_DIFF_PERCENTAGE, + date_diff_days: int = DEFAULT_DATE_DIFF_DAYS) -> Dict[Transaction, List[Transaction]]: + amount_diff_percentage = DEFAULT_AMOUNT_DIFF_PERCENTAGE if amount_diff_percentage is None else amount_diff_percentage + date_diff_days = DEFAULT_DATE_DIFF_DAYS if date_diff_days is None else date_diff_days transactions = self.api.transactions.get_transactions(transaction_type=TransactionType.ALL, start_date=start_date, end_date=end_date) diff --git a/src/utils/file_watcher_handler.py b/src/utils/file_watcher_handler.py index 96086b5..a497ef4 100644 --- a/src/utils/file_watcher_handler.py +++ b/src/utils/file_watcher_handler.py @@ -1,7 +1,6 @@ import logging import os import shutil -import traceback from watchdog.events import FileSystemEventHandler from ..firefly_sync_cli import FireflySyncCli @@ -23,7 +22,7 @@ def safe_import_and_move_file(self, file_path): try: self.import_and_move_file(file_path=file_path) except Exception as e: # noqa: F841 - logging.error(traceback.format_exc()) + logging.error(e) def import_and_move_file(self, file_path): if not os.path.exists(file_path):