Fixed bugs 2 #15

Merged
jkuijperm merged 13 commits from dev into main 2026-07-24 09:38:43 +00:00
2 changed files with 29 additions and 16 deletions
Showing only changes of commit 06e61ed1bf - Show all commits

View File

@ -151,19 +151,33 @@ class Account(models.Model):
def monthly_net(self, year=None): def monthly_net(self, year=None):
year = year or date.today().year year = year or date.today().year
data = [] incomes = (
self.incomes.filter(date__year=year)
.annotate(month=ExtractMonth("date"))
.values("month")
.annotate(total=Sum("amount"))
)
for month in range(1, 13): expenses = (
income = self.incomes.filter(date__year=year, date__month=month).aggregate( self.expenses.filter(date__year=year)
total=Sum("amount") .annotate(month=ExtractMonth("date"))
)["total"] or Decimal("0") .values("month")
expense = self.expenses.filter( .annotate(total=Sum("amount"))
date__year=year, date__month=month )
).aggregate(total=Sum("amount"))["total"] or Decimal("0")
data.append({"month": month, "net": float(income - expense)}) income_map = {i["month"]: Decimal(str(i["total"] or 0)) for i in incomes}
expenses_map = {e["month"]: Decimal(str(e["total"] or 0)) for e in expenses}
return data return [
{
"month": month,
"net": float(
income_map.get(month, Decimal("0"))
- expenses_map.get(month, Decimal("0"))
),
}
for month in range(1, 13)
]
def __str__(self): def __str__(self):
return self.name return self.name

View File

@ -68,14 +68,13 @@
{% for goal in goals %} {% for goal in goals %}
<div class="goal-card"> <div class="goal-card">
<strong>{{ goal.name }}</strong> <strong>{{ goal.name }}</strong>
{% if goal.is_exceeded %}
<span class="badge badge-inactive">Excedido</span>
{% endif %}
<div class="progress-bar"> <div class="progress-bar">
<div class="progress-fill <div class="progress-fill {{ goal.progress_state }}"
{% if goal.percentage < 50 %} low style="width: {{ goal.bar_width|unlocalize }}%"></div>
{% elif goal.percentage < 80 %} medium
{% else %} high
{% endif %}"
style="width: {{ goal.percentage|unlocalize }}%"></div>
</div> </div>
<span class="progress-label"> <span class="progress-label">