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):
|
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
|
||||||
|
|||||||
@ -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">
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user