diff --git a/sqlite_export_for_ynab/ddl/create-relations.sql b/sqlite_export_for_ynab/ddl/create-relations.sql index eb67809..3fa7d9d 100644 --- a/sqlite_export_for_ynab/ddl/create-relations.sql +++ b/sqlite_export_for_ynab/ddl/create-relations.sql @@ -189,8 +189,7 @@ LEFT JOIN subtransactions AS st ) WHERE TRUE - AND NOT t.deleted - AND NOT st.deleted + AND NOT COALESCE(st.deleted, t.deleted) ; CREATE TABLE IF NOT EXISTS scheduled_transactions ( @@ -277,6 +276,5 @@ LEFT JOIN scheduled_subtransactions AS st ) WHERE TRUE - AND NOT t.deleted - AND NOT st.deleted + AND NOT COALESCE(st.deleted, t.deleted) ; diff --git a/testing/fixtures.py b/testing/fixtures.py index 11e64b4..c808f66 100644 --- a/testing/fixtures.py +++ b/testing/fixtures.py @@ -123,6 +123,7 @@ TRANSACTION_ID_1 = str(uuid4()) TRANSACTION_ID_2 = str(uuid4()) +TRANSACTION_ID_3 = str(uuid4()) SUBTRANSACTION_ID_1 = str(uuid4()) SUBTRANSACTION_ID_2 = str(uuid4()) @@ -155,10 +156,18 @@ "deleted": True, "subtransactions": [], }, + { + "id": TRANSACTION_ID_3, + "date": "2024-03-01", + "amount": -19000, + "deleted": False, + "subtransactions": [], + }, ] SCHEDULED_TRANSACTION_ID_1 = str(uuid4()) SCHEDULED_TRANSACTION_ID_2 = str(uuid4()) +SCHEDULED_TRANSACTION_ID_3 = str(uuid4()) SCHEDULED_SUBTRANSACTION_ID_1 = str(uuid4()) SCHEDULED_SUBTRANSACTION_ID_2 = str(uuid4()) @@ -189,6 +198,12 @@ "deleted": True, "subtransactions": [], }, + { + "id": SCHEDULED_TRANSACTION_ID_3, + "amount": -9000, + "deleted": False, + "subtransactions": [], + }, ] diff --git a/tests/_main_test.py b/tests/_main_test.py index 783843f..6322547 100644 --- a/tests/_main_test.py +++ b/tests/_main_test.py @@ -61,6 +61,7 @@ from testing.fixtures import SCHEDULED_SUBTRANSACTION_ID_2 from testing.fixtures import SCHEDULED_TRANSACTION_ID_1 from testing.fixtures import SCHEDULED_TRANSACTION_ID_2 +from testing.fixtures import SCHEDULED_TRANSACTION_ID_3 from testing.fixtures import SCHEDULED_TRANSACTIONS from testing.fixtures import SCHEDULED_TRANSACTIONS_ENDPOINT_RE from testing.fixtures import SERVER_KNOWLEDGE_1 @@ -70,6 +71,7 @@ from testing.fixtures import TOKEN from testing.fixtures import TRANSACTION_ID_1 from testing.fixtures import TRANSACTION_ID_2 +from testing.fixtures import TRANSACTION_ID_3 from testing.fixtures import TRANSACTIONS from testing.fixtures import TRANSACTIONS_ENDPOINT_RE @@ -251,6 +253,13 @@ def test_insert_transactions(cur): "amount": -15000, "deleted": True, }, + { + "id": TRANSACTION_ID_3, + "budget_id": BUDGET_ID_1, + "date": "2024-03-01", + "amount": -19000, + "deleted": False, + }, ] cur.execute("SELECT * FROM subtransactions ORDER BY amount") @@ -273,6 +282,14 @@ def test_insert_transactions(cur): cur.execute("SELECT * FROM flat_transactions ORDER BY amount") assert [strip_nones(d) for d in cur.fetchall()] == [ + { + "transaction_id": TRANSACTION_ID_3, + "budget_id": BUDGET_ID_1, + "date": "2024-03-01", + "id": TRANSACTION_ID_3, + "amount": -19000, + "amount_major": pytest.approx(19), + }, { "transaction_id": TRANSACTION_ID_1, "subtransaction_id": SUBTRANSACTION_ID_1, @@ -315,6 +332,12 @@ def test_insert_scheduled_transactions(cur): "amount": -11000, "deleted": True, }, + { + "id": SCHEDULED_TRANSACTION_ID_3, + "budget_id": BUDGET_ID_1, + "amount": -9000, + "deleted": False, + }, ] cur.execute("SELECT * FROM scheduled_subtransactions ORDER BY amount") @@ -337,6 +360,13 @@ def test_insert_scheduled_transactions(cur): cur.execute("SELECT * FROM scheduled_flat_transactions ORDER BY amount") assert [strip_nones(d) for d in cur.fetchall()] == [ + { + "transaction_id": SCHEDULED_TRANSACTION_ID_3, + "budget_id": BUDGET_ID_1, + "id": SCHEDULED_TRANSACTION_ID_3, + "amount": -9000, + "amount_major": pytest.approx(9), + }, { "transaction_id": SCHEDULED_TRANSACTION_ID_1, "subtransaction_id": SCHEDULED_SUBTRANSACTION_ID_1,