add date range validation for transaction creation

This commit is contained in:
2026-10-17 12:23:03 -04:00
parent 0a1c5b2838
commit 5d5c40b995
+23 -1
View File
@@ -7,6 +7,7 @@ from pathlib import Path
from typing import Any from typing import Any
import ynab import ynab
from dateutil.relativedelta import relativedelta
from category_suggester import CategoryHistory from category_suggester import CategoryHistory
from wf_credit_extractor import WellsFargoPayloadExtractor as CreditExtractor from wf_credit_extractor import WellsFargoPayloadExtractor as CreditExtractor
@@ -601,6 +602,27 @@ def _execute_import(
# --- Create new + duplicates --- # --- Create new + duplicates ---
to_create = classification.new + classification.duplicates to_create = classification.new + classification.duplicates
if to_create: if to_create:
today = date.today()
earliest_ynab_date = today - relativedelta(years=5)
eligible_to_create = []
skipped_for_date = []
for transaction in to_create:
transaction_date = date.fromisoformat(transaction["date"])
if earliest_ynab_date <= transaction_date <= today:
eligible_to_create.append(transaction)
else:
skipped_for_date.append(transaction)
if skipped_for_date:
print(
f" [ynab] Skipped {len(skipped_for_date)} transaction(s) outside "
f"the supported date range ({earliest_ynab_date} through {today}):"
)
for transaction in skipped_for_date:
payee = transaction.get("payee_name") or "(no payee)"
print(f" {transaction['date']} | {payee}")
if eligible_to_create:
new_txns = [ new_txns = [
ynab.NewTransaction( ynab.NewTransaction(
account_id=t["account_id"], account_id=t["account_id"],
@@ -613,7 +635,7 @@ def _execute_import(
import_id=t["import_id"], import_id=t["import_id"],
approved=t.get("approved", False), approved=t.get("approved", False),
) )
for t in to_create for t in eligible_to_create
] ]
resp = ynab_client.create_transactions(new_txns) resp = ynab_client.create_transactions(new_txns)
created_ids = resp.transaction_ids or [] created_ids = resp.transaction_ids or []