From 01e0d481b6c272633355d3aea269b77370dfa75d Mon Sep 17 00:00:00 2001 From: Gabriel Augendre Date: Tue, 11 Feb 2020 23:58:08 +0100 Subject: [PATCH] Fix YNAB created transactions count --- ofx_processor/utils/ynab.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/ofx_processor/utils/ynab.py b/ofx_processor/utils/ynab.py index 8e7c970..bb15774 100644 --- a/ofx_processor/utils/ynab.py +++ b/ofx_processor/utils/ynab.py @@ -39,15 +39,23 @@ def push_transactions(transactions, account): url = f"{BASE_URL}/budgets/{budget_id}/transactions" for transaction in transactions: transaction["account_id"] = section["account"] + data = {"transactions": transactions} token = section["token"] headers = {"Authorization": f"Bearer {token}"} + res = requests.post(url, json=data, headers=headers) res.raise_for_status() data = res.json()["data"] - created = data["transactions"] - duplicates = data["duplicate_import_ids"] + + created = set() + for transaction in data["transactions"]: + matched_id = transaction["matched_transaction_id"] + if not matched_id or matched_id not in created: + created.add(transaction["id"]) click.secho(f"{len(created)} transactions created in YNAB.", fg="green", bold=True) + + duplicates = data["duplicate_import_ids"] if duplicates: click.secho( f"{len(duplicates)} transactions ignored (duplicates).", fg="yellow"