def record_value_on_equity(equity: Equity, year: int, month: int, value: float) -> ValueSnapshot: valueSnapshot = ValueSnapshot() valueSnapshot.year = year valueSnapshot.month = month valueSnapshot.value = value equity = Equity.objects(id=equity.id).first() updated = False for snap in equity.snapshots: if (snap.year == year) and (snap.month == month): snap.value = value updated = True if not updated: equity.snapshots.append(valueSnapshot) equity.save() return valueSnapshot
def query_equities(query, raw_return=True, accountIds: List[str] = None) -> List[Equity]: if query == "": equities = Equity.objects() else: equities = Equity.objects().filter(__raw__=query) if accountIds is not None: account_query = Q(account_id__in=accountIds).to_query(Equity) equities = equities.filter(__raw__=account_query) equities = equities.order_by('name') if raw_return: return equities.as_pymongo() else: ret_equities = [] for l in equities.order_by('name'): ret_equities.append(l) return ret_equities
def enter_if_not_exists(name: str, description: str, accountId: str, equityClass: EquityClass, equityType: [AssetType, LiabiltyType], equityTimeHorizon: EquityTimeHorizon, equityStatus: EquityStatus, equityContingency: EquityContingency, interestRate: float = 0.0) -> Equity: existing = Equity.objects(name=name) if len(existing) > 0: return None else: return enter_equity(name, description, accountId, equityClass, equityType, equityTimeHorizon, equityStatus, equityContingency, interestRate)
def clear_equities(): Equity.drop_collection()
def equities_by_account(account_id: str) -> Equity: return Equity.objects()\ .filter(account_id=account_id)\ .first()
def equity_by_account_and_name(account_id: str, equity_name: str) -> Equity: return Equity.objects()\ .filter(account_id=account_id)\ .filter(name=equity_name)\ .first()
def enter_equity(name: str, description: str, accountId: str, equityClass: EquityClass, equityType: [AssetType, LiabiltyType], equityTimeHorizon: EquityTimeHorizon, equityStatus: EquityStatus, equityContingency: EquityContingency, interestRate: float = 0.0) -> Equity: equity = Equity() equity.name = name equity.description = description equity.account_id = accountId equity.equityClass = equityClass.name equity.equityType = equityType.name equity.equityTimeHorizon = equityTimeHorizon.name equity.equityStatus = equityStatus.name equity.equityContingency = equityContingency.name equity.interestRate = interestRate equity.save() return equity