From d8aa1ef90d263771b080194adc9e983b1b3d56fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elisi=C3=A1rio=20Couto?= Date: Fri, 1 Mar 2024 14:40:16 +0000 Subject: [PATCH] fix(sync): Pending dates can be null. --- leggen/commands/sync.py | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/leggen/commands/sync.py b/leggen/commands/sync.py index 68281e5..4415b06 100644 --- a/leggen/commands/sync.py +++ b/leggen/commands/sync.py @@ -21,13 +21,16 @@ def save_transactions(ctx: click.Context, account: str): ) for transaction in account_transactions.get("booked", []): - booked_date = datetime.fromisoformat( - transaction.get("bookingDateTime", transaction.get("bookingDate")) + booked_date = transaction.get("bookingDateTime") or transaction.get( + "bookingDate" ) - value_date = datetime.fromisoformat( - transaction.get("valueDateTime", transaction.get("valueDate")) - ) - min_date = min(booked_date, value_date) + value_date = transaction.get("valueDateTime") or transaction.get("valueDate") + if booked_date and value_date: + min_date = min( + datetime.fromisoformat(booked_date), datetime.fromisoformat(value_date) + ) + else: + min_date = datetime.fromisoformat(booked_date or value_date) transactionValue = float( transaction.get("transactionAmount", {}).get("amount", 0) @@ -54,13 +57,16 @@ def save_transactions(ctx: click.Context, account: str): transactions.append(t) for transaction in account_transactions.get("pending", []): - booked_date = datetime.fromisoformat( - transaction.get("bookingDateTime", transaction.get("bookingDate")) - ) - value_date = datetime.fromisoformat( - transaction.get("valueDateTime", transaction.get("valueDate")) + booked_date = transaction.get("bookingDateTime") or transaction.get( + "bookingDate" ) - min_date = min(booked_date, value_date) + value_date = transaction.get("valueDateTime") or transaction.get("valueDate") + if booked_date and value_date: + min_date = min( + datetime.fromisoformat(booked_date), datetime.fromisoformat(value_date) + ) + else: + min_date = datetime.fromisoformat(booked_date or value_date) transactionValue = float( transaction.get("transactionAmount", {}).get("amount", 0)