diff --git a/app/apps/transactions/urls.py b/app/apps/transactions/urls.py index d483711..eedcbdc 100644 --- a/app/apps/transactions/urls.py +++ b/app/apps/transactions/urls.py @@ -82,6 +82,16 @@ urlpatterns = [ views.installment_plans_list, name="installment_plans_list", ), + path( + "installment-plans/list/active/", + views.active_installment_plans_list, + name="active_installment_plans_list", + ), + path( + "installment-plans/list/finished/", + views.finished_installment_plans_list, + name="finished_installment_plans_list", + ), path( "installment-plans/add/", views.installment_plan_add, diff --git a/app/apps/transactions/views/installment_plans.py b/app/apps/transactions/views/installment_plans.py index 4df92fd..92ce871 100644 --- a/app/apps/transactions/views/installment_plans.py +++ b/app/apps/transactions/views/installment_plans.py @@ -25,12 +25,41 @@ def installment_plans_index(request): @login_required @require_http_methods(["GET"]) def installment_plans_list(request): - installment_plans = InstallmentPlan.objects.all().order_by("-end_date") - return render( request, "installment_plans/fragments/list.html", - {"installment_plans": installment_plans}, + ) + + +@only_htmx +@login_required +@require_http_methods(["GET"]) +def active_installment_plans_list(request): + today = timezone.localdate(timezone.now()) + installment_plans = InstallmentPlan.objects.filter(end_date__gte=today).order_by( + "-end_date" + ) + + return render( + request, + "installment_plans/fragments/table.html", + {"installment_plans": installment_plans, "active": True}, + ) + + +@only_htmx +@login_required +@require_http_methods(["GET"]) +def finished_installment_plans_list(request): + today = timezone.localdate(timezone.now()) + installment_plans = InstallmentPlan.objects.filter(end_date__lt=today).order_by( + "-end_date" + ) + + return render( + request, + "installment_plans/fragments/table.html", + {"installment_plans": installment_plans, "active": False}, ) diff --git a/app/templates/installment_plans/fragments/list.html b/app/templates/installment_plans/fragments/list.html index 06bb3b6..2890590 100644 --- a/app/templates/installment_plans/fragments/list.html +++ b/app/templates/installment_plans/fragments/list.html @@ -8,70 +8,25 @@ data-bs-toggle="tooltip" data-bs-title="{% translate "Add" %}" hx-get="{% url 'installment_plan_add' %}" - hx-target="#generic-offcanvas" - _=""> + hx-target="#generic-offcanvas"> {% endspaceless %} -
- - - - - - - - - {% for installment_plan in installment_plans %} - - - - - {% endfor %} - -
{% translate 'Name' %}
-
- - - - - - - -
-
{{ installment_plan.description }}
+
+
+ +
+ +
+
diff --git a/app/templates/installment_plans/fragments/table.html b/app/templates/installment_plans/fragments/table.html new file mode 100644 index 0000000..eeefc70 --- /dev/null +++ b/app/templates/installment_plans/fragments/table.html @@ -0,0 +1,69 @@ +{% load currency_display %} +{% load i18n %} +{% if active %} +
+{% else %} +
+{% endif %} +
+ + + + + + + + + {% for installment_plan in installment_plans %} + + + + + {% endfor %} + +
{% translate 'Name' %}
+
+ + + + + + + +
+
{{ installment_plan.description }}
+
+
diff --git a/app/templates/installment_plans/pages/index.html b/app/templates/installment_plans/pages/index.html index 59b9bc6..4e96dda 100644 --- a/app/templates/installment_plans/pages/index.html +++ b/app/templates/installment_plans/pages/index.html @@ -4,5 +4,5 @@ {% block title %}{% translate 'Installment Plans' %}{% endblock %} {% block content %} -
+
{% endblock %}