Skip to content

Commit

Permalink
fix(sync): Pending dates can be null.
Browse files Browse the repository at this point in the history
  • Loading branch information
elisiariocouto committed Mar 1, 2024
1 parent f3ad639 commit d8aa1ef
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions leggen/commands/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit d8aa1ef

Please sign in to comment.