Fixed some typos and created the pages html for account
This commit is contained in:
parent
907323db7c
commit
5f5dd87859
@ -53,7 +53,7 @@ class Account(models.Model):
|
|||||||
or Decimal('0')
|
or Decimal('0')
|
||||||
)
|
)
|
||||||
income_total = (
|
income_total = (
|
||||||
self.incomes.aggregate(total=Sum('income'))['total']
|
self.incomes.aggregate(total=Sum('amount'))['total']
|
||||||
or Decimal('0')
|
or Decimal('0')
|
||||||
)
|
)
|
||||||
return self.initial_balance + income_total - expenses_total
|
return self.initial_balance + income_total - expenses_total
|
||||||
@ -136,5 +136,3 @@ class Income(models.Model):
|
|||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f'{self.name} - {self.amount}'
|
return f'{self.name} - {self.amount}'
|
||||||
|
|
||||||
|
|
||||||
@ -0,0 +1,24 @@
|
|||||||
|
{% load static %}
|
||||||
|
<!DOCTYPE>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Eliminar</title>
|
||||||
|
<link rel="stylesheet" href="{% static 'expenses/css/base.css' %}">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<h1>Eliminar cuenta</h1>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
¿Seguro que quieres eliminar la cuenta
|
||||||
|
<strong>{{ account.name }}</strong>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<form method="post">
|
||||||
|
{% csrf_token %}
|
||||||
|
<button type="submit">Sí, eliminar</button>
|
||||||
|
<a href="{% url 'account_list' %}">Cancelar</a>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@ -0,0 +1,27 @@
|
|||||||
|
{% load static %}
|
||||||
|
<!DOCTYPE>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Cuenta</title>
|
||||||
|
<link rel="stylesheet" href="{% static 'expenses/css/base.css' %}">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<h1>
|
||||||
|
{% if form.instance.pk %}
|
||||||
|
Editar cuenta
|
||||||
|
{% else %}
|
||||||
|
Nueva cuenta
|
||||||
|
{% endif %}
|
||||||
|
</h1>
|
||||||
|
|
||||||
|
<form method="post">
|
||||||
|
{% csrf_token %}
|
||||||
|
{{ form.as_p }}
|
||||||
|
|
||||||
|
<button type="submit">Guardar</button>
|
||||||
|
<a href="{% url 'account_list' %}">Cancelar</a>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@ -0,0 +1,44 @@
|
|||||||
|
{% load static %}
|
||||||
|
<!DOCTYPE>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Cuentas</title>
|
||||||
|
<link rel="stylesheet" href="{% static 'expenses/css/base.css' %}">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<h1>Mis cuentas</h1>
|
||||||
|
|
||||||
|
<a href="{% url 'account_create' %}">➕ Nueva cuenta</a>
|
||||||
|
|
||||||
|
<table>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Nombre</th>
|
||||||
|
<th>Saldo inicial</th>
|
||||||
|
<th>Saldo actual</th>
|
||||||
|
<th>Activa</th>
|
||||||
|
<th></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{% for account in accounts %}
|
||||||
|
<tr>
|
||||||
|
<td>{{ account.name }}</td>
|
||||||
|
<td>{{ account.initial_balance }}</td>
|
||||||
|
<td>{{ account.current_balance|floatformat:2 }}</td>
|
||||||
|
<td>{{ account.active }}</td>
|
||||||
|
<td>
|
||||||
|
<a href="{% url 'account_edit' account.id %}">Editar</a>
|
||||||
|
<a href="{% url 'account_delete' account.id %}">Eliminar</a>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% empty %}
|
||||||
|
<tr>
|
||||||
|
<td colspan="5">No hay cuentas</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@ -12,4 +12,8 @@ urlpatterns = [
|
|||||||
path('tags/new/', views.tag_create, name='tag_create'),
|
path('tags/new/', views.tag_create, name='tag_create'),
|
||||||
path('tags/<int:pk>/edit/', views.tag_edit, name='tag_edit'),
|
path('tags/<int:pk>/edit/', views.tag_edit, name='tag_edit'),
|
||||||
path('tags/<int:pk>/delete/', views.tag_delete, name='tag_delete'),
|
path('tags/<int:pk>/delete/', views.tag_delete, name='tag_delete'),
|
||||||
|
path('accounts/', views.account_list, name='account_list'),
|
||||||
|
path('accounts/new/', views.account_create, name='account_create'),
|
||||||
|
path('accounts/<int:pk>/edit/', views.account_edit, name='account_edit'),
|
||||||
|
path('accounts/<int:pk>/delete/', views.account_delete, name='account_delete'),
|
||||||
]
|
]
|
||||||
@ -1,7 +1,7 @@
|
|||||||
from datetime import date
|
from datetime import date
|
||||||
from operator import truediv
|
from operator import truediv
|
||||||
from .forms import ExpenseForm, IncomeForm, TagForm
|
|
||||||
from .models import Account, Category, Expense, Tag
|
from .models import Account, Category, Expense, Tag
|
||||||
|
from .forms import ExpenseForm, IncomeForm, TagForm, AccountForm
|
||||||
# from dateutli.relativedelta import relativedelta
|
# from dateutli.relativedelta import relativedelta
|
||||||
|
|
||||||
from django.db.models import Sum
|
from django.db.models import Sum
|
||||||
@ -296,7 +296,7 @@ def dashboard(request):
|
|||||||
kpi_balance = selected_account_obj.current_balance()
|
kpi_balance = selected_account_obj.current_balance()
|
||||||
else:
|
else:
|
||||||
kpi_balance = (
|
kpi_balance = (
|
||||||
Accounts.objects.filter(owner.request.user, active=True)
|
Account.objects.filter(owner=request.user, active=True)
|
||||||
.aggregate(total=Sum('initial_balance'))['total'] or 0
|
.aggregate(total=Sum('initial_balance'))['total'] or 0
|
||||||
) - (
|
) - (
|
||||||
expenses.aggregate(total=Sum('amount'))['total'] or 0
|
expenses.aggregate(total=Sum('amount'))['total'] or 0
|
||||||
@ -587,7 +587,7 @@ def account_list(request):
|
|||||||
return render(
|
return render(
|
||||||
request,
|
request,
|
||||||
'expenses/account_list.html',
|
'expenses/account_list.html',
|
||||||
{'account': accounts}
|
{'accounts': accounts}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -609,6 +609,42 @@ def account_create(request):
|
|||||||
{'form': form}
|
{'form': form}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
def account_edit(request, pk):
|
||||||
|
account = get_object_or_404(
|
||||||
|
Account,
|
||||||
|
pk=pk,
|
||||||
|
owner=request.user
|
||||||
|
)
|
||||||
|
|
||||||
|
if request.method == 'POST':
|
||||||
|
form = AccountForm(request.POST, instance=account)
|
||||||
|
if form.is_valid():
|
||||||
|
form.save()
|
||||||
|
return redirect('account_list')
|
||||||
|
else:
|
||||||
|
form = AccountForm(instance=account)
|
||||||
|
|
||||||
|
return render(
|
||||||
|
request,
|
||||||
|
'expenses/account_form.html',
|
||||||
|
{'form': form}
|
||||||
|
)
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
def account_delete(request, pk):
|
||||||
|
account = get_object_or_404(Account, pk=pk, owner=request.user)
|
||||||
|
|
||||||
|
if request.method == 'POST':
|
||||||
|
account.active = False
|
||||||
|
account.save()
|
||||||
|
return redirect('account_list')
|
||||||
|
|
||||||
|
return render(
|
||||||
|
request,
|
||||||
|
'expenses/account_confirm_delete.html',
|
||||||
|
{'account':account}
|
||||||
|
)
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def income_create(request):
|
def income_create(request):
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user