Eco Accounts

* adds related eco account withdraw detail view to intervention detail view
* adds new route for removing withdraws using RemoveModalForm
* adds EcoAccountWithdraw model
* adds admin interfaces for EcoAccount and EcoAccountWithdraw
* adds message_templates.py to konova/utils for reusable messages
* splits related-documents.html and related-objects.html into separate templates for each related object type: compensations.html, documents.html, eco-account-withdraws.html and payments.html
* adds translations
This commit is contained in:
mipel
2021-08-02 10:14:34 +02:00
parent 221f7dfb79
commit 98de05089e
16 changed files with 412 additions and 209 deletions
+50 -4
View File
@@ -1,5 +1,6 @@
from django.contrib.auth.decorators import login_required
from django.http import HttpRequest
from django.core.exceptions import ObjectDoesNotExist
from django.http import HttpRequest, Http404
from django.shortcuts import render, get_object_or_404
from django.utils.translation import gettext_lazy as _
@@ -10,6 +11,7 @@ from intervention.models import Intervention
from konova.contexts import BaseContext
from konova.decorators import *
from konova.forms import RemoveModalForm
from konova.utils.message_templates import FORM_INVALID
@login_required
@@ -139,7 +141,7 @@ def new_payment_view(request: HttpRequest, intervention_id: str):
else:
messages.info(
request,
_("There was an error on this form.")
FORM_INVALID
)
return redirect(request.META.get("HTTP_REFERER", "home"))
elif request.method == "GET":
@@ -154,7 +156,7 @@ def new_payment_view(request: HttpRequest, intervention_id: str):
@login_required
def payment_remove_view(request: HttpRequest, id: str):
""" Renders a modal view for adding new payments
""" Renders a modal view for removing payments
Args:
request (HttpRequest): The incoming request
@@ -177,7 +179,51 @@ def payment_remove_view(request: HttpRequest, id: str):
else:
messages.info(
request,
_("There was an error on this form.")
FORM_INVALID
)
return redirect(request.META.get("HTTP_REFERER", "home"))
elif request.method == "GET":
context = {
"form": form,
}
context = BaseContext(request, context).context
return render(request, template, context)
else:
raise NotImplementedError
@login_required
def withdraw_remove_view(request: HttpRequest, id: str, withdraw_id: str):
""" Renders a modal view for removing withdraws
Args:
request (HttpRequest): The incoming request
id (str): The eco account's id
withdraw_id (str): The withdraw's id
Returns:
"""
acc = get_object_or_404(EcoAccount, id=id)
try:
eco_withdraw = acc.eco_withdraws.get(id=withdraw_id)
except ObjectDoesNotExist:
raise Http404("Unknown withdraw")
form = RemoveModalForm(request.POST or None, instance=eco_withdraw, user=request.user)
template = form.template
if request.method == "POST":
if form.is_valid():
form.save()
messages.success(
request,
_("Withdraw removed")
)
return redirect(request.META.get("HTTP_REFERER", "home"))
else:
messages.info(
request,
FORM_INVALID
)
return redirect(request.META.get("HTTP_REFERER", "home"))
elif request.method == "GET":