Skip to content

Commit 74084c9

Browse files
authored
Merge pull request #15 from erwindouna/fix-bugs
Fix bug on duplicate name and scheduler init
2 parents f09beee + 742d759 commit 74084c9

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

importer2firefly.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ async def start_import(self) -> AsyncGenerator[Any, Any]:
103103
total_transactions = len(txns)
104104
for i, txn in enumerate(txns, start=1):
105105
cp_iban = txn.get("meta", {}).get("counter_party_iban")
106+
cp_name = txn.get("meta", {}).get("counter_party_preferred_name")
106107
transaction_type = (
107108
"debit" if txn["transaction_type"].lower() == "debit" else "credit"
108109
)
@@ -121,14 +122,29 @@ async def start_import(self) -> AsyncGenerator[Any, Any]:
121122
):
122123
continue
123124

125+
# Check if the IBAN matches
124126
if cp_iban == firefly_account["attributes"].get("iban"):
125127
yield f"Matching account found via IBAN: {txn['description']} - {cp_iban}"
126128
linked_account = firefly_account
127129
matching += 1
128130
break
129131

132+
# Check if the name matches, as a final fallback
133+
# This is not prefered, but can be used if the IBAN is not available or when the account uses multiple IBANs
134+
# Firefly doesn't allow to create multiple accounts with the same name, so this should be safe
135+
if cp_name is not None and cp_name == firefly_account[
136+
"attributes"
137+
].get("name"):
138+
yield f"Matching account found via name: {txn['description']} - {cp_name}"
139+
linked_account = firefly_account
140+
matching += 1
141+
break
142+
130143
if linked_account is None:
131-
yield f"No match, still a valid IBAN. Creating a new account: {txn} - {cp_iban}"
144+
account_type = (
145+
"revenue" if transaction_type == "credit" else "Expense"
146+
)
147+
yield f"No match, still a valid IBAN. Creating a new account: {txn} - {cp_iban} - {account_type}"
132148
response = await self._firefly_client.create_account(
133149
{
134150
"name": txn.get("meta", {}).get(
@@ -151,7 +167,6 @@ async def start_import(self) -> AsyncGenerator[Any, Any]:
151167
newly_created += 1
152168
else:
153169
unmatching += 1
154-
# TODO: find the unknown destination account
155170
yield f"Transaction has no IBAN: {txn['description']}"
156171

157172
# Ensure the amount is always positive

scheduler.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ def __init__(self, schedule: str | None = None) -> None:
2525
"""Initialize the Scheduler class."""
2626
self._config: Config = Config()
2727
self._scheduler: AsyncIOScheduler = AsyncIOScheduler()
28-
self._import_job = None
28+
self._import_job: AsyncIOScheduler = None
2929
self._schedule: str | None = schedule or self._config.get("import_schedule")
3030

3131
def start(self) -> None:
3232
"""Start the scheduler."""
3333
_LOGGER.info("Starting the scheduler, with schedule: %s", self._schedule)
34-
if self._schedule is None:
34+
if self._schedule is None or self._schedule == "":
3535
_LOGGER.warning("No schedule set, not starting the scheduler")
3636
return
3737

0 commit comments

Comments
 (0)