Skip to content

Commit

Permalink
Split internal reference when there are multiple
Browse files Browse the repository at this point in the history
  • Loading branch information
dbtdsilva committed Mar 13, 2024
1 parent 671bd63 commit 2ea9580
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
7 changes: 5 additions & 2 deletions src/services/transaction_import_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 8 additions & 1 deletion src/services/transaction_link_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions src/utils/file_watcher_handler.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import logging
import os
import shutil
import traceback
from watchdog.events import FileSystemEventHandler

from ..firefly_sync_cli import FireflySyncCli
Expand All @@ -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):
Expand Down

0 comments on commit 2ea9580

Please sign in to comment.