61 lines
1.6 KiB
Python
61 lines
1.6 KiB
Python
from datetime import date
|
|
from decimal import Decimal
|
|
from typing import Optional
|
|
from uuid import UUID, uuid4
|
|
|
|
from pydantic.json_schema import SkipJsonSchema
|
|
from sqlmodel import Field, SQLModel
|
|
from pydantic import Field as PydField
|
|
|
|
from account.enums import Asset, Liability, CategoryFamily
|
|
|
|
class AccountBase(SQLModel):
|
|
name: str = Field(index=True)
|
|
parent_account_id: Optional[UUID] = Field(default=None, foreign_key="account.id")
|
|
|
|
class AccountBaseId(AccountBase):
|
|
id: UUID | None = Field(default_factory=uuid4, primary_key=True)
|
|
family: str = Field(index=True)
|
|
type: str = Field(index=True)
|
|
path: str = Field(index=True)
|
|
|
|
class AccountRead(AccountBaseId):
|
|
opening_date: date = Field()
|
|
opening_balance: Decimal = Field(decimal_places=2, default=0)
|
|
|
|
class BaseAccountWrite(AccountBase):
|
|
path: SkipJsonSchema[str] = Field(default="")
|
|
family: SkipJsonSchema[str] = Field(default="")
|
|
opening_date: date = Field()
|
|
opening_balance: Decimal = Field(decimal_places=2, default=0)
|
|
|
|
class AccountWrite(BaseAccountWrite):
|
|
type: Asset | Liability = Field()
|
|
parent_account_id: UUID | None = PydField(default=None, json_schema_extra={
|
|
"foreign_key": {
|
|
"reference": {
|
|
"resource": "accounts",
|
|
"schema": "AccountRead",
|
|
"label": "name"
|
|
}
|
|
}
|
|
})
|
|
|
|
class AccountCreate(AccountWrite):
|
|
pass
|
|
|
|
class AccountUpdate(AccountWrite):
|
|
pass
|
|
|
|
class CategoryRead(AccountBaseId):
|
|
pass
|
|
|
|
class CategoryWrite(BaseAccountWrite):
|
|
type: CategoryFamily = Field()
|
|
|
|
class CategoryCreate(CategoryWrite):
|
|
pass
|
|
|
|
class CategoryUpdate(CategoryWrite):
|
|
pass
|