From a4be703713d059d1904236a972f72985b8fbba4c Mon Sep 17 00:00:00 2001 From: ewandor Date: Mon, 3 Feb 2025 22:04:06 +0100 Subject: [PATCH] Adding Equity Account Family --- api/app/account/models.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/api/app/account/models.py b/api/app/account/models.py index fa0b7fe..ce8a2d0 100644 --- a/api/app/account/models.py +++ b/api/app/account/models.py @@ -17,7 +17,7 @@ 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, unique=True) + path: str = Field(index=True) class Account(AccountBaseId, table=True): parent_account: Optional["Account"] = Relationship( @@ -104,6 +104,15 @@ class Account(AccountBaseId, table=True): return account_db + @classmethod + def create_equity_account(cls, session): + account_db = Account(name="Equity", family="Equity", type="Equity", path="/Equity/") + session.add(account_db) + session.commit() + session.refresh(account_db) + + return account_db + @classmethod def list(cls, filters): return filters.sort(filters.filter(select(Account))) @@ -111,7 +120,7 @@ class Account(AccountBaseId, table=True): @classmethod def list_accounts(cls, filters): return cls.list(filters).where( - Account.type.not_in([v.value for v in CategoryType]) + Account.family.in_(["Asset", "Liability"]) ) @classmethod @@ -125,7 +134,7 @@ class Account(AccountBaseId, table=True): @classmethod def list_categories(cls, filters): return cls.list(filters).where( - Account.type.in_([v.value for v in CategoryType]) + Account.type.in_(["Expense", "Income"]) ) @classmethod @@ -175,11 +184,12 @@ class AccountType(Enum): Currency = "Currency" # < Denotes a currency trading 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 Income = "Income" # < Denotes an income account Expense = "Expense" # < Denotes an expense account + Equity = "Equity" # < Denotes an equity account e.g. opening/closing balance + class Asset(Enum): Asset = "Asset" Checkings = "Checkings"