From 440401049a72ef6a2af3791c7c05424373ea873f Mon Sep 17 00:00:00 2001 From: ewandor Date: Sun, 16 Feb 2025 16:54:52 +0100 Subject: [PATCH] Adding fixtures for payees --- api/app/initialize_db.py | 2 + api/app/payee/fixtures.py | 94 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 96 insertions(+) create mode 100644 api/app/payee/fixtures.py diff --git a/api/app/initialize_db.py b/api/app/initialize_db.py index 949bd1a..7368e8e 100644 --- a/api/app/initialize_db.py +++ b/api/app/initialize_db.py @@ -2,6 +2,7 @@ import main from account.resource import AccountResource from account.fixtures import inject_fixtures as account_inject_fixtures +from payee.fixtures import inject_fixtures as payee_inject_fixtures from db import create_db_and_tables, get_session, drop_tables from user import create_admin_user @@ -12,3 +13,4 @@ session = get_session().__next__() create_admin_user(session) AccountResource.create_equity_account(session) account_inject_fixtures(session) +payee_inject_fixtures(session) diff --git a/api/app/payee/fixtures.py b/api/app/payee/fixtures.py new file mode 100644 index 0000000..c247c9b --- /dev/null +++ b/api/app/payee/fixtures.py @@ -0,0 +1,94 @@ +from datetime import date +from decimal import Decimal + +from account.resource import AccountResource +from account.schemas import AccountCreate, CategoryCreate +from payee.models import PayeeCreate, Payee + + +def inject_fixtures(session): + for f in fixtures_payee: + # f = prepare_dict(session, f) + schema = PayeeCreate(**f) + Payee.create(schema, session) + +def prepare_dict(session, entry): + if entry['parent_path']: + parent = AccountResource.get_by_path(session, entry['parent_path']) + entry['parent_account_id'] = parent.id + else: + entry['parent_account_id'] = None + del entry['parent_path'] + return entry + +fixtures_payee = [ + { + "name": "PayeeEmployer", + }, + { + "name": "PayeeSocialSecurity", + }, + { + "name": "PayeeAssurance1", + }, + { + "name": "PayeeAssurance2", + }, + { + "name": "PayeeSupermarket1", + }, + { + "name": "PayeeSupermarket2", + }, + { + "name": "PayeeTaxes", + }, + { + "name": "PayeeRent", + }, +] + +fixtures_account = [ + { + "name": "Current Assets", + "parent_path": None, + "type": "Asset", + "opening_date": date(1970, 1, 2), + "opening_balance": Decimal("0.00"), + }, + { + "name": "Cash in Wallet", + "parent_path": "/Accounts/Asset/Current Assets/", + "type": "Asset", + "opening_date": date(1970, 1, 3), + "opening_balance": Decimal("0.00"), + }, + { + "name": "Checking Account", + "parent_path": "/Accounts/Asset/Current Assets/", + "type": "Asset", + "opening_date": date(1970, 1, 4), + "opening_balance": Decimal("0.00"), + }, + { + "name": "Savings Account", + "parent_path": "/Accounts/Asset/Current Assets/", + "type": "Asset", + "opening_date": date(1970, 1, 5), + "opening_balance": Decimal("0.00"), + }, + { + "name": "Debt Accounts", + "parent_path": None, + "type": "Liability", + "opening_date": date(1970, 1, 6), + "opening_balance": Decimal("0.00"), + }, + { + "name": "Credit Card", + "parent_path": "/Accounts/Liability/Debt Accounts/", + "type": "Liability", + "opening_date": date(1970, 1, 7), + "opening_balance": Decimal("0.00"), + }, +]