Minor changes
This commit is contained in:
parent
c7ba7a970f
commit
06e61ed1bf
@ -151,19 +151,33 @@ class Account(models.Model):
|
||||
|
||||
def monthly_net(self, year=None):
|
||||
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):
|
||||
income = self.incomes.filter(date__year=year, date__month=month).aggregate(
|
||||
total=Sum("amount")
|
||||
)["total"] or Decimal("0")
|
||||
expense = self.expenses.filter(
|
||||
date__year=year, date__month=month
|
||||
).aggregate(total=Sum("amount"))["total"] or Decimal("0")
|
||||
expenses = (
|
||||
self.expenses.filter(date__year=year)
|
||||
.annotate(month=ExtractMonth("date"))
|
||||
.values("month")
|
||||
.annotate(total=Sum("amount"))
|
||||
)
|
||||
|
||||
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):
|
||||
return self.name
|
||||
|
||||
@ -68,14 +68,13 @@
|
||||
{% for goal in goals %}
|
||||
<div class="goal-card">
|
||||
<strong>{{ goal.name }}</strong>
|
||||
{% if goal.is_exceeded %}
|
||||
<span class="badge badge-inactive">Excedido</span>
|
||||
{% endif %}
|
||||
|
||||
<div class="progress-bar">
|
||||
<div class="progress-fill
|
||||
{% if goal.percentage < 50 %} low
|
||||
{% elif goal.percentage < 80 %} medium
|
||||
{% else %} high
|
||||
{% endif %}"
|
||||
style="width: {{ goal.percentage|unlocalize }}%"></div>
|
||||
<div class="progress-fill {{ goal.progress_state }}"
|
||||
style="width: {{ goal.bar_width|unlocalize }}%"></div>
|
||||
</div>
|
||||
|
||||
<span class="progress-label">
|
||||
|
||||
Loading…
Reference in New Issue
Block a user