Changing Account/category structure and Adding transactions and splits
This commit is contained in:
@@ -1,11 +1,7 @@
|
||||
from uuid import UUID, uuid4
|
||||
from enum import Enum
|
||||
|
||||
from sqlmodel import Field, SQLModel, select, Relationship
|
||||
from pydantic import Field as PydField
|
||||
|
||||
from category.models import CategoryRead, Category
|
||||
|
||||
from sqlmodel import Field, SQLModel, select
|
||||
|
||||
class AccountType(Enum):
|
||||
Asset = "Asset" # < Denotes a generic asset account.
|
||||
@@ -21,24 +17,21 @@ class AccountType(Enum):
|
||||
MoneyMarket = "MoneyMarket" # < Money Market Account
|
||||
|
||||
Currency = "Currency" # < Denotes a currency trading account.
|
||||
Income = "Income" # < Denotes an income account
|
||||
Expense = "Expense" # < Denotes an expense account
|
||||
AssetLoan = "AssetLoan" # < Denotes a loan (asset of the owner of this object)
|
||||
Stock = "Stock" # < Denotes an security account as sub-account for an investment
|
||||
Equity = "Equity" # < Denotes an equity account e.g. opening/closing balance
|
||||
|
||||
Payee = "Payee"
|
||||
Income = "Income" # < Denotes an income account
|
||||
Expense = "Expense" # < Denotes an expense account
|
||||
|
||||
class AccountBase(SQLModel):
|
||||
name: str = Field(index=True)
|
||||
type: AccountType = Field(index=True)
|
||||
default_category_id: UUID | None = Field(default=None, foreign_key="category.id")
|
||||
|
||||
class AccountBaseId(AccountBase):
|
||||
id: UUID | None = Field(default_factory=uuid4, primary_key=True)
|
||||
|
||||
class Account(AccountBaseId, table=True):
|
||||
default_category: Category | None = Relationship()
|
||||
|
||||
@classmethod
|
||||
def create(cls, account, session):
|
||||
@@ -51,7 +44,7 @@ class Account(AccountBaseId, table=True):
|
||||
|
||||
@classmethod
|
||||
def list(cls):
|
||||
return select(Account).join(Category)
|
||||
return select(Account)
|
||||
|
||||
@classmethod
|
||||
def get(cls, session, account_id):
|
||||
@@ -71,18 +64,10 @@ class Account(AccountBaseId, table=True):
|
||||
session.commit()
|
||||
|
||||
class AccountRead(AccountBaseId):
|
||||
default_category: CategoryRead
|
||||
pass
|
||||
|
||||
class AccountWrite(AccountBase):
|
||||
default_category_id: UUID = PydField(default=None, json_schema_extra={
|
||||
"foreign_key": {
|
||||
"reference": {
|
||||
"resource": "categories",
|
||||
"schema": "CategoryRead",
|
||||
"label": "name"
|
||||
}
|
||||
}
|
||||
})
|
||||
pass
|
||||
|
||||
class AccountCreate(AccountWrite):
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user