Compare commits
2 Commits
148b1d00c4
...
699009d21a
| Author | SHA1 | Date | |
|---|---|---|---|
| 699009d21a | |||
| 440401049a |
@@ -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)
|
||||
|
||||
0
api/app/ledger/__init__.py
Normal file
0
api/app/ledger/__init__.py
Normal file
18
api/app/ledger/resource.py
Normal file
18
api/app/ledger/resource.py
Normal file
@@ -0,0 +1,18 @@
|
||||
from datetime import date
|
||||
|
||||
from sqlalchemy import and_, select
|
||||
from sqlalchemy.orm import aliased
|
||||
|
||||
from transaction.models import Split, Transaction
|
||||
|
||||
|
||||
class LedgerResource:
|
||||
@classmethod
|
||||
def get_ledger(cls, session, account_id):
|
||||
split_account = aliased(Split)
|
||||
|
||||
return session.exec(
|
||||
select(Transaction, split_account).join(split_account, and_(
|
||||
split_account.account_id == account_id,
|
||||
Transaction.id == split_account.transaction_id
|
||||
))).all()
|
||||
17
api/app/ledger/routes.py
Normal file
17
api/app/ledger/routes.py
Normal file
@@ -0,0 +1,17 @@
|
||||
from uuid import UUID
|
||||
|
||||
from fastapi import APIRouter, Depends
|
||||
|
||||
from db import SessionDep
|
||||
from ledger.schema import TransactionLedgerRead
|
||||
from transaction.resource import TransactionResource
|
||||
from user.manager import get_current_user
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
@router.get("/{account_id}")
|
||||
def read_ledger(account_id: UUID, session: SessionDep, current_user=Depends(get_current_user)) -> list[TransactionLedgerRead]:
|
||||
response = []
|
||||
for transaction, split in TransactionResource.get_ledger(session, account_id):
|
||||
response.append(TransactionLedgerRead(transaction=transaction, account_split=split))
|
||||
return response
|
||||
7
api/app/ledger/schema.py
Normal file
7
api/app/ledger/schema.py
Normal file
@@ -0,0 +1,7 @@
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
from transaction.models import TransactionRead, SplitRead
|
||||
|
||||
class TransactionLedgerRead(BaseModel):
|
||||
transaction: TransactionRead = Field()
|
||||
account_split: SplitRead = Field()
|
||||
@@ -5,15 +5,14 @@ from fastapi.security import OAuth2PasswordBearer
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from fastapi_pagination import add_pagination
|
||||
|
||||
|
||||
from db import create_db_and_tables
|
||||
from user import user_router, auth_router, create_admin_user
|
||||
from account.account_routes import router as account_router
|
||||
from account.category_routes import router as category_router
|
||||
from ledger.routes import router as ledger_router
|
||||
from payee.routes import router as payee_router
|
||||
from transaction.routes import router as transaction_router
|
||||
|
||||
|
||||
@asynccontextmanager
|
||||
async def lifespan(app: FastAPI):
|
||||
create_db_and_tables()
|
||||
@@ -41,6 +40,7 @@ app.include_router(auth_router, prefix="/auth", tags=["auth"], )
|
||||
app.include_router(user_router, prefix="/users", tags=["users"])
|
||||
app.include_router(account_router, prefix="/accounts", tags=["accounts"])
|
||||
app.include_router(category_router, prefix="/categories", tags=["categories"])
|
||||
app.include_router(ledger_router, prefix="/ledgers", tags=["ledgers"])
|
||||
app.include_router(payee_router, prefix="/payees", tags=["payees"])
|
||||
app.include_router(transaction_router, prefix="/transactions", tags=["transactions"])
|
||||
|
||||
|
||||
94
api/app/payee/fixtures.py
Normal file
94
api/app/payee/fixtures.py
Normal file
@@ -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"),
|
||||
},
|
||||
]
|
||||
Reference in New Issue
Block a user