diff --git a/compensation/admin.py b/compensation/admin.py index 656b5240..a902e1bc 100644 --- a/compensation/admin.py +++ b/compensation/admin.py @@ -1,6 +1,7 @@ from django.contrib import admin -from compensation.models import Compensation, CompensationAction, CompensationState, CompensationControl, Payment +from compensation.models import Compensation, CompensationAction, CompensationState, CompensationControl, Payment, \ + EcoAccountWithdraw, EcoAccount class CompensationControlAdmin(admin.ModelAdmin): @@ -34,9 +35,23 @@ class CompensationActionAdmin(admin.ModelAdmin): class CompensationAdmin(admin.ModelAdmin): list_display = [ "id", + "identifier", + "title", "created_on", + "created_by", ] + +class EcoAccountAdmin(admin.ModelAdmin): + list_display = [ + "id", + "identifier", + "title", + "created_on", + "created_by", + ] + + class PaymentAdmin(admin.ModelAdmin): list_display = [ "id", @@ -47,8 +62,21 @@ class PaymentAdmin(admin.ModelAdmin): ] +class EcoAccountWithdrawAdmin(admin.ModelAdmin): + list_display = [ + "id", + "account", + "intervention", + "amount", + "created_by", + "created_on", + ] + + admin.site.register(Compensation, CompensationAdmin) admin.site.register(Payment, PaymentAdmin) admin.site.register(CompensationAction, CompensationActionAdmin) admin.site.register(CompensationState, CompensationStateAdmin) admin.site.register(CompensationControl, CompensationControlAdmin) +admin.site.register(EcoAccount, EcoAccountAdmin) +admin.site.register(EcoAccountWithdraw, EcoAccountWithdrawAdmin) diff --git a/compensation/models.py b/compensation/models.py index e7c439b5..0221a7b6 100644 --- a/compensation/models.py +++ b/compensation/models.py @@ -7,7 +7,7 @@ Created on: 17.11.20 """ from django.contrib.auth.models import User from django.contrib.gis.db import models -from django.core.validators import MinValueValidator +from django.core.validators import MinValueValidator, MaxValueValidator from django.utils import timezone from django.utils.timezone import now @@ -152,3 +152,40 @@ class EcoAccount(Compensation): """ # Users having access on this object users = models.ManyToManyField(User) + + def __str__(self): + return "{}".format(self.identifier) + + +class EcoAccountWithdraw(BaseResource): + """ + A withdraw object for eco accounts + """ + account = models.ForeignKey( + EcoAccount, + on_delete=models.SET_NULL, + null=True, + blank=True, + help_text="Withdrawn from", + related_name="eco_withdraws", + ) + amount = models.FloatField( + null=True, + blank=True, + help_text="Amount withdrawn (percentage)", + validators=[ + MinValueValidator(limit_value=0.00), + MaxValueValidator(limit_value=100), + ] + ) + intervention = models.ForeignKey( + Intervention, + on_delete=models.CASCADE, + null=True, + blank=True, + help_text="Withdrawn for", + related_name="eco_withdraws", + ) + + def __str__(self): + return "{} of {}".format(self.amount, self.account) diff --git a/compensation/urls.py b/compensation/urls.py index c51d026f..f77e1a41 100644 --- a/compensation/urls.py +++ b/compensation/urls.py @@ -30,4 +30,8 @@ urlpatterns = [ path('acc/', account_open_view, name='acc-open'), path('acc//edit', account_edit_view, name='acc-edit'), path('acc//remove', account_remove_view, name='acc-remove'), + + # Eco-account withdraws + path('acc//remove/', withdraw_remove_view, name='withdraw-remove'), + ] \ No newline at end of file diff --git a/compensation/views.py b/compensation/views.py index 12f9ba19..88f9b929 100644 --- a/compensation/views.py +++ b/compensation/views.py @@ -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": diff --git a/intervention/templates/intervention/detail/includes/compensations.html b/intervention/templates/intervention/detail/includes/compensations.html new file mode 100644 index 00000000..3703ac0d --- /dev/null +++ b/intervention/templates/intervention/detail/includes/compensations.html @@ -0,0 +1,49 @@ +{% load i18n l10n fontawesome_5 %} + \ No newline at end of file diff --git a/intervention/templates/intervention/detail/includes/documents.html b/intervention/templates/intervention/detail/includes/documents.html new file mode 100644 index 00000000..18c66ea9 --- /dev/null +++ b/intervention/templates/intervention/detail/includes/documents.html @@ -0,0 +1,55 @@ +{% load i18n l10n fontawesome_5 %} + \ No newline at end of file diff --git a/intervention/templates/intervention/detail/includes/eco-account-withdraws.html b/intervention/templates/intervention/detail/includes/eco-account-withdraws.html new file mode 100644 index 00000000..5de071e7 --- /dev/null +++ b/intervention/templates/intervention/detail/includes/eco-account-withdraws.html @@ -0,0 +1,57 @@ +{% load i18n l10n fontawesome_5 %} + \ No newline at end of file diff --git a/intervention/templates/intervention/detail/includes/payments.html b/intervention/templates/intervention/detail/includes/payments.html new file mode 100644 index 00000000..146f7cb7 --- /dev/null +++ b/intervention/templates/intervention/detail/includes/payments.html @@ -0,0 +1,59 @@ +{% load i18n l10n fontawesome_5 %} + diff --git a/intervention/templates/intervention/detail/related-documents.html b/intervention/templates/intervention/detail/related-documents.html deleted file mode 100644 index 4a246df0..00000000 --- a/intervention/templates/intervention/detail/related-documents.html +++ /dev/null @@ -1,59 +0,0 @@ -{% load i18n l10n fontawesome_5 %} - \ No newline at end of file diff --git a/intervention/templates/intervention/detail/related-objects.html b/intervention/templates/intervention/detail/related-objects.html deleted file mode 100644 index bca9f45e..00000000 --- a/intervention/templates/intervention/detail/related-objects.html +++ /dev/null @@ -1,113 +0,0 @@ -{% load i18n l10n fontawesome_5 %} - diff --git a/intervention/templates/intervention/detail/view.html b/intervention/templates/intervention/detail/view.html index ae4006a1..f7540b0e 100644 --- a/intervention/templates/intervention/detail/view.html +++ b/intervention/templates/intervention/detail/view.html @@ -146,8 +146,22 @@
- {% include 'intervention/detail/related-objects.html' %} - {% include 'intervention/detail/related-documents.html' %} +
+
+ {% include 'intervention/detail/includes/compensations.html' %} +
+
+ {% include 'intervention/detail/includes/payments.html' %} +
+
+
+
+ {% include 'intervention/detail/includes/eco-account-withdraws.html' %} +
+
+ {% include 'intervention/detail/includes/documents.html' %} +
+
{% with 'btn-modal' as btn_class %} diff --git a/intervention/views.py b/intervention/views.py index 9dd360e4..473cb2f4 100644 --- a/intervention/views.py +++ b/intervention/views.py @@ -10,6 +10,7 @@ from intervention.tables import InterventionTable from konova.contexts import BaseContext from konova.decorators import * from konova.forms import RemoveForm, SimpleGeomForm, NewDocumentForm +from konova.utils.message_templates import FORM_INVALID @login_required @@ -98,7 +99,7 @@ def new_document_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": diff --git a/konova/utils/message_templates.py b/konova/utils/message_templates.py new file mode 100644 index 00000000..ca701dcf --- /dev/null +++ b/konova/utils/message_templates.py @@ -0,0 +1,11 @@ +""" +Author: Michel Peltriaux +Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany +Contact: michel.peltriaux@sgdnord.rlp.de +Created on: 02.08.21 + +""" +from django.utils.translation import gettext_lazy as _ + + +FORM_INVALID = _("There was an error on this form.") diff --git a/konova/views.py b/konova/views.py index e857d092..28ad4f93 100644 --- a/konova/views.py +++ b/konova/views.py @@ -18,6 +18,7 @@ from intervention.models import Intervention from konova.contexts import BaseContext from konova.forms import RemoveModalForm from konova.models import Document +from konova.utils.message_templates import FORM_INVALID from news.models import ServerMessage from konova.settings import SSO_SERVER_BASE @@ -150,7 +151,7 @@ def remove_document_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": diff --git a/locale/de/LC_MESSAGES/django.mo b/locale/de/LC_MESSAGES/django.mo index 8419c790..90c3fce3 100644 Binary files a/locale/de/LC_MESSAGES/django.mo and b/locale/de/LC_MESSAGES/django.mo differ diff --git a/locale/de/LC_MESSAGES/django.po b/locale/de/LC_MESSAGES/django.po index ebd3d084..a140667d 100644 --- a/locale/de/LC_MESSAGES/django.po +++ b/locale/de/LC_MESSAGES/django.po @@ -13,7 +13,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2021-07-30 15:00+0200\n" +"POT-Creation-Date: 2021-08-02 09:52+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -24,16 +24,16 @@ msgstr "" "Plural-Forms: nplurals=2; plural=(n != 1);\n" #: compensation/forms.py:26 -#: intervention/templates/intervention/detail/related-objects.html:78 +#: intervention/templates/intervention/detail/includes/eco-account-withdraws.html:31 msgid "Amount" -msgstr "Betrag" +msgstr "Menge" #: compensation/forms.py:28 msgid "Amount in Euro" msgstr "Betrag in Euro" #: compensation/forms.py:31 -#: intervention/templates/intervention/detail/related-objects.html:81 +#: intervention/templates/intervention/detail/includes/payments.html:29 msgid "Due on" msgstr "Fällig am" @@ -59,14 +59,14 @@ msgstr "Neue Ersatzzahlung zu Eingriff '{}' hinzufügen" #: compensation/tables.py:24 compensation/tables.py:164 #: intervention/forms.py:26 intervention/tables.py:23 -#: intervention/templates/intervention/detail/related-objects.html:30 +#: intervention/templates/intervention/detail/includes/compensations.html:28 msgid "Identifier" msgstr "Kennung" #: compensation/tables.py:29 compensation/tables.py:169 #: intervention/forms.py:33 intervention/tables.py:28 -#: intervention/templates/intervention/detail/related-documents.html:28 -#: intervention/templates/intervention/detail/related-objects.html:33 +#: intervention/templates/intervention/detail/includes/compensations.html:31 +#: intervention/templates/intervention/detail/includes/documents.html:26 #: intervention/templates/intervention/detail/view.html:60 konova/forms.py:181 msgid "Title" msgstr "Bezeichnung" @@ -90,7 +90,7 @@ msgid "Last edit" msgstr "Zuletzt bearbeitet" #: compensation/tables.py:61 -#: intervention/templates/intervention/detail/related-objects.html:10 +#: intervention/templates/intervention/detail/includes/compensations.html:8 msgid "Compensations" msgstr "Kompensationen" @@ -253,8 +253,7 @@ msgstr "Freigabelink" #: intervention/forms.py:241 msgid "Send this link to users who you want to have writing access on the data" -msgstr "" -"Andere Nutzer erhalten über diesen Link Zugriff auf die Daten" +msgstr "Andere Nutzer erhalten über diesen Link Zugriff auf die Daten" #: intervention/forms.py:250 msgid "Shared with" @@ -283,46 +282,60 @@ msgstr "Eingriffe" msgid "Intervention" msgstr "Eingriff" -#: intervention/templates/intervention/detail/related-documents.html:10 +#: intervention/templates/intervention/detail/includes/compensations.html:13 +#: intervention/templates/intervention/detail/includes/eco-account-withdraws.html:13 +msgid "Add new compensation" +msgstr "Neue Kompensation hinzufügen" + +#: intervention/templates/intervention/detail/includes/documents.html:8 msgid "Documents" msgstr "Dokumente" -#: intervention/templates/intervention/detail/related-documents.html:15 +#: intervention/templates/intervention/detail/includes/documents.html:13 #: konova/forms.py:222 msgid "Add new document" msgstr "Neues Dokument hinzufügen" -#: intervention/templates/intervention/detail/related-documents.html:31 +#: intervention/templates/intervention/detail/includes/documents.html:29 #: konova/forms.py:209 msgid "Comment" msgstr "Kommentar" -#: intervention/templates/intervention/detail/related-documents.html:34 -#: intervention/templates/intervention/detail/related-objects.html:87 +#: intervention/templates/intervention/detail/includes/documents.html:32 +#: intervention/templates/intervention/detail/includes/payments.html:35 msgid "Action" msgstr "Aktionen" -#: intervention/templates/intervention/detail/related-documents.html:48 +#: intervention/templates/intervention/detail/includes/documents.html:46 msgid "Remove document" msgstr "Dokument löschen" -#: intervention/templates/intervention/detail/related-objects.html:15 -msgid "Add new compensation" -msgstr "Neue Kompensation hinzufügen" +#: intervention/templates/intervention/detail/includes/eco-account-withdraws.html:8 +msgid "Eco Account Withdraws" +msgstr "Ökokonto Abbuchungen" -#: intervention/templates/intervention/detail/related-objects.html:60 +#: intervention/templates/intervention/detail/includes/eco-account-withdraws.html:28 +msgid "Account Identifier" +msgstr "Ökokonto Kennung" + +#: intervention/templates/intervention/detail/includes/payments.html:8 msgid "Payments" msgstr "Ersatzzahlungen" -#: intervention/templates/intervention/detail/related-objects.html:65 +#: intervention/templates/intervention/detail/includes/payments.html:13 msgid "Add new payment" msgstr "Neue Zahlung hinzufügen" -#: intervention/templates/intervention/detail/related-objects.html:84 +#: intervention/templates/intervention/detail/includes/payments.html:26 +msgctxt "money" +msgid "Amount" +msgstr "Betrag" + +#: intervention/templates/intervention/detail/includes/payments.html:32 msgid "Transfer comment" msgstr "Verwendungszweck" -#: intervention/templates/intervention/detail/related-objects.html:102 +#: intervention/templates/intervention/detail/includes/payments.html:50 msgid "Remove payment" msgstr "Zahlung entfernen" @@ -473,20 +486,20 @@ msgstr "Sie sind dabei {} {} zu löschen" #: konova/forms.py:164 msgid "Are you sure?" -msgstr "" +msgstr "Sind Sie sicher?" #: konova/forms.py:188 msgid "When has this file been created? Important for photos." -msgstr "" +msgstr "Wann wurde diese Datei erstellt oder das Foto aufgenommen?" #: konova/forms.py:198 #: venv/lib/python3.7/site-packages/django/db/models/fields/files.py:231 msgid "File" -msgstr "" +msgstr "Datei" #: konova/forms.py:200 msgid "Must be smaller than 15 Mb" -msgstr "" +msgstr "Muss kleiner als 15 Mb sein" #: konova/forms.py:211 msgid "Additional comment on this file"