-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.py
More file actions
128 lines (109 loc) · 3.15 KB
/
Copy pathmodels.py
File metadata and controls
128 lines (109 loc) · 3.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
"""
Data models for Mopex Expense Manager.
"""
import datetime
from dataclasses import dataclass, field
from typing import Optional
DEFAULT_CURRENCIES = {
"INR": "₹",
"USD": "$",
"EUR": "€",
"GBP": "£",
"JPY": "¥",
"CAD": "CA$",
"AUD": "A$",
"CHF": "CHF",
"CNY": "¥",
"BRL": "R$",
}
DEFAULT_CATEGORIES = {
"expense": [
"Food & Dining",
"Housing & Rent",
"Utilities & Bills",
"Transportation",
"Shopping",
"Entertainment",
"Healthcare",
"Education",
"Travel",
"Misc Expense",
],
"income": [
"Salary & Wages",
"Freelance / Business",
"Investments",
"Gifts & Grants",
"Refunds",
"Misc Income",
]
}
GOAL_ICONS = ["🎯", "🏠", "✈️", "🚗", "📱", "💻", "💍", "🎓", "🏋️", "💰", "🎁", "🌱"]
MOOD_OPTIONS = {
"great": "😄 Great",
"good": "🙂 Good",
"neutral": "😐 Neutral",
"stressed": "😰 Stressed",
"bad": "😞 Bad",
}
RECUR_INTERVALS = ["daily", "weekly", "monthly"]
@dataclass
class Budget:
id: Optional[int] = None
title: str = "Monthly Expenses"
total_budget: float = 0.0
currency: str = "INR"
currency_symbol: str = "₹"
user_name: str = "User"
created_at: str = field(default_factory=lambda: datetime.date.today().isoformat())
is_active: bool = True
alert_yellow_pct: float = 75.0
alert_red_pct: float = 100.0
def formatted_budget(self) -> str:
return f"{self.currency_symbol}{self.total_budget:,.2f}"
@dataclass
class Transaction:
id: Optional[int] = None
budget_id: int = 1
title: str = ""
amount: float = 0.0
type: str = "expense" # 'income' or 'expense'
category: str = "Misc Expense"
date: str = field(default_factory=lambda: datetime.date.today().isoformat())
notes: str = ""
is_recurring: bool = False
recur_interval: str = "" # 'daily', 'weekly', 'monthly'
def formatted_amount(self, symbol: str = "₹") -> str:
prefix = "+" if self.type == "income" else "-"
return f"{prefix}{symbol}{abs(self.amount):,.2f}"
@dataclass
class Goal:
id: Optional[int] = None
budget_id: int = 1
title: str = ""
target_amount: float = 0.0
saved_amount: float = 0.0
deadline: str = ""
description: str = ""
icon: str = "🎯"
created_at: str = field(default_factory=lambda: datetime.date.today().isoformat())
@property
def progress_pct(self) -> float:
if self.target_amount <= 0:
return 0.0
return min(self.saved_amount / self.target_amount * 100, 100.0)
@property
def remaining(self) -> float:
return max(self.target_amount - self.saved_amount, 0.0)
@property
def is_achieved(self) -> bool:
return self.saved_amount >= self.target_amount
@dataclass
class JournalNote:
id: Optional[int] = None
budget_id: int = 1
date: str = field(default_factory=lambda: datetime.date.today().isoformat())
title: str = ""
content: str = ""
mood: str = "neutral"
created_at: str = field(default_factory=lambda: datetime.date.today().isoformat())