dev #7
@ -90,7 +90,7 @@ class CategoryForm(forms.ModelForm):
|
|||||||
class GoalForm(forms.ModelForm):
|
class GoalForm(forms.ModelForm):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Goal
|
model = Goal
|
||||||
fields = ['name', 'target_amount', 'category']
|
fields = ['name', 'target_amount', 'category', "show_on_home"]
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
user = kwargs.pop('user')
|
user = kwargs.pop('user')
|
||||||
|
|||||||
@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 5.2.10 on 2026-05-05 13:26
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('expenses', '0008_goal'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='goal',
|
||||||
|
name='show_on_home',
|
||||||
|
field=models.BooleanField(default=False),
|
||||||
|
),
|
||||||
|
]
|
||||||
@ -248,6 +248,7 @@ class Goal(models.Model):
|
|||||||
target_amount = models.DecimalField(max_digits=12, decimal_places=2)
|
target_amount = models.DecimalField(max_digits=12, decimal_places=2)
|
||||||
category = models.ForeignKey("Category", on_delete=models.CASCADE)
|
category = models.ForeignKey("Category", on_delete=models.CASCADE)
|
||||||
created_at = models.DateTimeField(auto_now_add=True)
|
created_at = models.DateTimeField(auto_now_add=True)
|
||||||
|
show_on_home = models.BooleanField(default=False)
|
||||||
|
|
||||||
def progress(self):
|
def progress(self):
|
||||||
"""
|
"""
|
||||||
|
|||||||
@ -391,3 +391,15 @@ tbody tr:hover {
|
|||||||
.progress-fill.high {
|
.progress-fill.high {
|
||||||
background: #2ecc71;
|
background: #2ecc71;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.goals-widget {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
|
||||||
|
gap: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.goal-card {
|
||||||
|
padding: 10px;
|
||||||
|
border-radius: 8px;
|
||||||
|
background: #f9f9f9;
|
||||||
|
}
|
||||||
@ -1,5 +1,7 @@
|
|||||||
{% extends "expenses/base.html" %}
|
{% extends "expenses/base.html" %}
|
||||||
|
|
||||||
|
{% load l10n %}
|
||||||
|
|
||||||
{% block title %}Dashboard{% endblock %}
|
{% block title %}Dashboard{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
@ -214,6 +216,39 @@
|
|||||||
</section>
|
</section>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
<!-- ========================= -->
|
||||||
|
<!-- Goals -->
|
||||||
|
<!-- ========================= -->
|
||||||
|
|
||||||
|
<h3>Objetivos</h3>
|
||||||
|
{% if goals %}
|
||||||
|
<div class="goals-widget">
|
||||||
|
{% for goal in goals %}
|
||||||
|
<div class="goal-card">
|
||||||
|
<strong>{{ goal.name }}</strong>
|
||||||
|
|
||||||
|
<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>
|
||||||
|
|
||||||
|
<span class="progress-label">
|
||||||
|
{{ goal.progress|floatformat:1 }}€ / {{ goal.target_amount|floatformat:1 }}€ ({{ goal.percentage|floatformat:1 }}%)
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
{% else %}
|
||||||
|
<p>No hay objetivos.</p>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
<!-- ========================= -->
|
||||||
|
<!-- Categories -->
|
||||||
|
<!-- ========================= -->
|
||||||
<table>
|
<table>
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
|
|||||||
@ -1,5 +1,7 @@
|
|||||||
{% extends "expenses/base.html" %}
|
{% extends "expenses/base.html" %}
|
||||||
|
|
||||||
|
{% load l10n %}
|
||||||
|
|
||||||
{% block title %}Home{% endblock %}
|
{% block title %}Home{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
@ -60,4 +62,30 @@
|
|||||||
|
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
<h3>Objetivos</h3>
|
||||||
|
{% if goals %}
|
||||||
|
<div class="goals-widget">
|
||||||
|
{% for goal in goals %}
|
||||||
|
<div class="goal-card">
|
||||||
|
<strong>{{ goal.name }}</strong>
|
||||||
|
|
||||||
|
<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>
|
||||||
|
|
||||||
|
<span class="progress-label">
|
||||||
|
{{ goal.progress|floatformat:1 }}€ / {{ goal.target_amount|floatformat:1 }}€ ({{ goal.percentage|floatformat:1 }}%)
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
{% else %}
|
||||||
|
<p>No tienes objetivos aún.</p>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|||||||
@ -93,6 +93,8 @@ def home(request):
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
goals = Goal.objects.filter(owner=request.user, show_on_home=True)
|
||||||
|
|
||||||
return render(
|
return render(
|
||||||
request,
|
request,
|
||||||
"expenses/home.html",
|
"expenses/home.html",
|
||||||
@ -104,6 +106,7 @@ def home(request):
|
|||||||
"kpi_categories": kpi_categories,
|
"kpi_categories": kpi_categories,
|
||||||
"mini_chart_labels": [x["label"] for x in mini_data],
|
"mini_chart_labels": [x["label"] for x in mini_data],
|
||||||
"mini_chart_data": [x["total"] for x in mini_data],
|
"mini_chart_data": [x["total"] for x in mini_data],
|
||||||
|
"goals": goals,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -497,6 +500,9 @@ def dashboard(request):
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Goals
|
||||||
|
goals = Goal.objects.filter(owner=request.user)
|
||||||
|
|
||||||
# Send the data to the dashboard
|
# Send the data to the dashboard
|
||||||
return render(
|
return render(
|
||||||
request,
|
request,
|
||||||
@ -527,6 +533,7 @@ def dashboard(request):
|
|||||||
"kpi_balance": kpi_balance,
|
"kpi_balance": kpi_balance,
|
||||||
"accounts_charts": accounts_charts,
|
"accounts_charts": accounts_charts,
|
||||||
"period": period,
|
"period": period,
|
||||||
|
"goals": goals,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user