old data ISSUE
Browse files- plaid_client.py +33 -1
plaid_client.py
CHANGED
|
@@ -62,11 +62,43 @@ def _load_raw_balances():
|
|
| 62 |
raise FileNotFoundError(f"Fixture not found: {path}")
|
| 63 |
return json.loads(path.read_text())
|
| 64 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
def _load_raw_transactions():
|
| 66 |
path = FIXTURES_DIR / "raw_transactions.json"
|
| 67 |
if not path.exists():
|
| 68 |
raise FileNotFoundError(f"Fixture not found: {path}")
|
| 69 |
-
|
|
|
|
|
|
|
| 70 |
|
| 71 |
|
| 72 |
# ---------- REAL: Balances ----------
|
|
|
|
| 62 |
raise FileNotFoundError(f"Fixture not found: {path}")
|
| 63 |
return json.loads(path.read_text())
|
| 64 |
|
| 65 |
+
|
| 66 |
+
def _shift_fixture_to_today(fixture):
|
| 67 |
+
"""
|
| 68 |
+
Slide all transaction dates forward so the newest transaction
|
| 69 |
+
lands on today. Preserves relative gaps between transactions
|
| 70 |
+
so recurring detection still works correctly.
|
| 71 |
+
"""
|
| 72 |
+
txns = fixture.get('transactions', [])
|
| 73 |
+
if not txns:
|
| 74 |
+
return fixture
|
| 75 |
+
|
| 76 |
+
# Find the latest date in the fixture
|
| 77 |
+
def parse_date(d):
|
| 78 |
+
return date.fromisoformat(d) if isinstance(d, str) else d
|
| 79 |
+
|
| 80 |
+
latest = max(parse_date(t['date']) for t in txns)
|
| 81 |
+
today = date.today()
|
| 82 |
+
shift_days = (today - latest).days
|
| 83 |
+
|
| 84 |
+
if shift_days <= 0:
|
| 85 |
+
return fixture # already current or in the future
|
| 86 |
+
|
| 87 |
+
# Shift every transaction date forward by shift_days
|
| 88 |
+
for t in txns:
|
| 89 |
+
original = parse_date(t['date'])
|
| 90 |
+
t['date'] = str(original + timedelta(days=shift_days))
|
| 91 |
+
|
| 92 |
+
return fixture
|
| 93 |
+
|
| 94 |
+
|
| 95 |
def _load_raw_transactions():
|
| 96 |
path = FIXTURES_DIR / "raw_transactions.json"
|
| 97 |
if not path.exists():
|
| 98 |
raise FileNotFoundError(f"Fixture not found: {path}")
|
| 99 |
+
fixture = json.loads(path.read_text())
|
| 100 |
+
return _shift_fixture_to_today(fixture)
|
| 101 |
+
|
| 102 |
|
| 103 |
|
| 104 |
# ---------- REAL: Balances ----------
|