Fixes account deletion with deductions

* adds a warning on removing an eco account if there are still deductions
    * this way a user needs to get rid of these deductions first
This commit is contained in:
mpeltriaux 2022-10-11 16:47:16 +02:00
parent bce271ceaa
commit 87b01e8fdd
4 changed files with 78 additions and 50 deletions

View File

@ -14,6 +14,7 @@ from compensation.forms.mixins import CompensationResponsibleFormMixin, PikCompe
from compensation.models import EcoAccount from compensation.models import EcoAccount
from intervention.models import Handler, Responsibility, Legal from intervention.models import Handler, Responsibility, Legal
from konova.forms import SimpleGeomForm from konova.forms import SimpleGeomForm
from konova.forms.modals import RemoveModalForm
from user.models import User, UserActionLogEntry from user.models import User, UserActionLogEntry
@ -210,3 +211,16 @@ class EditEcoAccountForm(NewEcoAccountForm):
# Add the log entry to the main objects log list # Add the log entry to the main objects log list
self.instance.log.add(action) self.instance.log.add(action)
return self.instance return self.instance
class RemoveEcoAccountModalForm(RemoveModalForm):
def is_valid(self):
super_valid = super().is_valid()
has_deductions = self.instance.deductions.exists()
if has_deductions:
self.add_error(
"confirm",
_("The account can not be removed, since there are still deductions.")
)
return super_valid and not has_deductions

View File

@ -13,13 +13,12 @@ from django.shortcuts import get_object_or_404, redirect, render
from django.urls import reverse from django.urls import reverse
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from compensation.forms.eco_account import EditEcoAccountForm, NewEcoAccountForm from compensation.forms.eco_account import EditEcoAccountForm, NewEcoAccountForm, RemoveEcoAccountModalForm
from compensation.models import EcoAccount from compensation.models import EcoAccount
from compensation.tables.eco_account import EcoAccountTable from compensation.tables.eco_account import EcoAccountTable
from konova.contexts import BaseContext from konova.contexts import BaseContext
from konova.decorators import shared_access_required, default_group_required, any_group_check, login_required_modal from konova.decorators import shared_access_required, default_group_required, any_group_check, login_required_modal
from konova.forms import SimpleGeomForm from konova.forms import SimpleGeomForm
from konova.forms.modals import RemoveModalForm
from konova.settings import ETS_GROUP, DEFAULT_GROUP, ZB_GROUP from konova.settings import ETS_GROUP, DEFAULT_GROUP, ZB_GROUP
from konova.sub_settings.context_settings import TAB_TITLE_IDENTIFIER from konova.sub_settings.context_settings import TAB_TITLE_IDENTIFIER
from konova.utils.message_templates import CANCEL_ACC_RECORDED_OR_DEDUCTED, RECORDED_BLOCKS_EDIT, FORM_INVALID, \ from konova.utils.message_templates import CANCEL_ACC_RECORDED_OR_DEDUCTED, RECORDED_BLOCKS_EDIT, FORM_INVALID, \
@ -260,7 +259,7 @@ def remove_view(request: HttpRequest, id: str):
messages.info(request, CANCEL_ACC_RECORDED_OR_DEDUCTED) messages.info(request, CANCEL_ACC_RECORDED_OR_DEDUCTED)
return redirect("compensation:acc:detail", id=id) return redirect("compensation:acc:detail", id=id)
form = RemoveModalForm(request.POST or None, instance=acc, request=request) form = RemoveEcoAccountModalForm(request.POST or None, instance=acc, request=request)
return form.process_request( return form.process_request(
request=request, request=request,
msg_success=_("Eco-account removed"), msg_success=_("Eco-account removed"),

Binary file not shown.

View File

@ -43,7 +43,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PACKAGE VERSION\n" "Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2022-08-25 10:57+0200\n" "POT-Creation-Date: 2022-10-11 16:39+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
@ -446,37 +446,41 @@ msgstr "Neue Kompensation"
msgid "Edit compensation" msgid "Edit compensation"
msgstr "Bearbeite Kompensation" msgstr "Bearbeite Kompensation"
#: compensation/forms/eco_account.py:29 compensation/utils/quality.py:95 #: compensation/forms/eco_account.py:30 compensation/utils/quality.py:95
msgid "Available Surface" msgid "Available Surface"
msgstr "Verfügbare Fläche" msgstr "Verfügbare Fläche"
#: compensation/forms/eco_account.py:32 #: compensation/forms/eco_account.py:33
msgid "The amount that can be used for deductions" msgid "The amount that can be used for deductions"
msgstr "Die für Abbuchungen zur Verfügung stehende Menge" msgstr "Die für Abbuchungen zur Verfügung stehende Menge"
#: compensation/forms/eco_account.py:41 #: compensation/forms/eco_account.py:42
#: compensation/templates/compensation/detail/eco_account/view.html:67 #: compensation/templates/compensation/detail/eco_account/view.html:67
#: compensation/utils/quality.py:83 #: compensation/utils/quality.py:83
msgid "Agreement date" msgid "Agreement date"
msgstr "Vereinbarungsdatum" msgstr "Vereinbarungsdatum"
#: compensation/forms/eco_account.py:43 #: compensation/forms/eco_account.py:44
msgid "When did the parties agree on this?" msgid "When did the parties agree on this?"
msgstr "Wann wurde dieses Ökokonto offiziell vereinbart?" msgstr "Wann wurde dieses Ökokonto offiziell vereinbart?"
#: compensation/forms/eco_account.py:69 #: compensation/forms/eco_account.py:70
#: compensation/views/eco_account/eco_account.py:94 #: compensation/views/eco_account/eco_account.py:94
msgid "New Eco-Account" msgid "New Eco-Account"
msgstr "Neues Ökokonto" msgstr "Neues Ökokonto"
#: compensation/forms/eco_account.py:78 #: compensation/forms/eco_account.py:79
msgid "Eco-Account XY; Location ABC" msgid "Eco-Account XY; Location ABC"
msgstr "Ökokonto XY; Flur ABC" msgstr "Ökokonto XY; Flur ABC"
#: compensation/forms/eco_account.py:140 #: compensation/forms/eco_account.py:141
msgid "Edit Eco-Account" msgid "Edit Eco-Account"
msgstr "Ökokonto bearbeiten" msgstr "Ökokonto bearbeiten"
#: compensation/forms/eco_account.py:224
msgid "The account can not be removed, since there are still deductions."
msgstr "Das Ökokonto kann nicht entfernt werden, da hierzu noch Abbuchungen vorliegen."
#: compensation/forms/mixins.py:37 #: compensation/forms/mixins.py:37
#: compensation/templates/compensation/detail/eco_account/view.html:63 #: compensation/templates/compensation/detail/eco_account/view.html:63
#: compensation/templates/compensation/report/eco_account/report.html:20 #: compensation/templates/compensation/report/eco_account/report.html:20
@ -734,14 +738,14 @@ msgstr ""
msgid "Pieces" msgid "Pieces"
msgstr "Stück" msgstr "Stück"
#: compensation/models/eco_account.py:56 #: compensation/models/eco_account.py:62
msgid "" msgid ""
"Deductable surface can not be larger than existing surfaces in after states" "Deductable surface can not be larger than existing surfaces in after states"
msgstr "" msgstr ""
"Die abbuchbare Fläche darf die Gesamtfläche der Zielzustände nicht " "Die abbuchbare Fläche darf die Gesamtfläche der Zielzustände nicht "
"überschreiten" "überschreiten"
#: compensation/models/eco_account.py:63 #: compensation/models/eco_account.py:69
msgid "" msgid ""
"Deductable surface can not be smaller than the sum of already existing " "Deductable surface can not be smaller than the sum of already existing "
"deductions. Please contact the responsible users for the deductions!" "deductions. Please contact the responsible users for the deductions!"
@ -781,19 +785,19 @@ msgid "Not recorded yet"
msgstr "Noch nicht verzeichnet" msgstr "Noch nicht verzeichnet"
#: compensation/tables/compensation.py:166 #: compensation/tables/compensation.py:166
#: compensation/tables/eco_account.py:150 ema/tables.py:133 #: compensation/tables/eco_account.py:153 ema/tables.py:133
#: intervention/tables.py:164 #: intervention/tables.py:164
msgid "Recorded on {} by {}" msgid "Recorded on {} by {}"
msgstr "Am {} von {} verzeichnet worden" msgstr "Am {} von {} verzeichnet worden"
#: compensation/tables/compensation.py:186 #: compensation/tables/compensation.py:186
#: compensation/tables/eco_account.py:172 ema/tables.py:154 #: compensation/tables/eco_account.py:175 ema/tables.py:154
#: intervention/tables.py:185 #: intervention/tables.py:185
msgid "Full access granted" msgid "Full access granted"
msgstr "Für Sie freigegeben - Datensatz kann bearbeitet werden" msgstr "Für Sie freigegeben - Datensatz kann bearbeitet werden"
#: compensation/tables/compensation.py:186 #: compensation/tables/compensation.py:186
#: compensation/tables/eco_account.py:172 ema/tables.py:154 #: compensation/tables/eco_account.py:175 ema/tables.py:154
#: intervention/tables.py:185 #: intervention/tables.py:185
msgid "Access not granted" msgid "Access not granted"
msgstr "Nicht freigegeben - Datensatz nur lesbar" msgstr "Nicht freigegeben - Datensatz nur lesbar"
@ -808,7 +812,7 @@ msgstr "Verfügbar"
msgid "Eco Accounts" msgid "Eco Accounts"
msgstr "Ökokonten" msgstr "Ökokonten"
#: compensation/tables/eco_account.py:147 #: compensation/tables/eco_account.py:150
msgid "Not recorded yet. Can not be used for deductions, yet." msgid "Not recorded yet. Can not be used for deductions, yet."
msgstr "" msgstr ""
"Noch nicht verzeichnet. Kann noch nicht für Abbuchungen genutzt werden." "Noch nicht verzeichnet. Kann noch nicht für Abbuchungen genutzt werden."
@ -876,6 +880,34 @@ msgstr "Keine Zusatzmerkmale"
msgid "Remove action" msgid "Remove action"
msgstr "Maßnahme entfernen" msgstr "Maßnahme entfernen"
#: compensation/templates/compensation/detail/compensation/includes/actions.html:79
#: compensation/templates/compensation/detail/compensation/includes/states-after.html:73
#: compensation/templates/compensation/detail/compensation/includes/states-before.html:73
#: compensation/templates/compensation/detail/eco_account/includes/actions.html:78
#: compensation/templates/compensation/detail/eco_account/includes/states-after.html:73
#: compensation/templates/compensation/detail/eco_account/includes/states-before.html:73
#: compensation/templates/compensation/detail/eco_account/view.html:58
#: compensation/templates/compensation/detail/eco_account/view.html:62
#: compensation/templates/compensation/detail/eco_account/view.html:66
#: compensation/templates/compensation/detail/eco_account/view.html:70
#: ema/templates/ema/detail/includes/actions.html:76
#: ema/templates/ema/detail/includes/states-after.html:71
#: ema/templates/ema/detail/includes/states-before.html:71
#: ema/templates/ema/detail/view.html:48 ema/templates/ema/detail/view.html:52
#: ema/templates/ema/detail/view.html:56
#: intervention/templates/intervention/detail/view.html:30
#: intervention/templates/intervention/detail/view.html:34
#: intervention/templates/intervention/detail/view.html:38
#: intervention/templates/intervention/detail/view.html:47
#: intervention/templates/intervention/detail/view.html:51
#: intervention/templates/intervention/detail/view.html:55
#: intervention/templates/intervention/detail/view.html:59
#: intervention/templates/intervention/detail/view.html:63
#: intervention/templates/intervention/detail/view.html:100
#: intervention/templates/intervention/detail/view.html:104
msgid "Missing"
msgstr "Fehlend"
#: compensation/templates/compensation/detail/compensation/includes/controls.html:5 #: compensation/templates/compensation/detail/compensation/includes/controls.html:5
#: compensation/templates/compensation/detail/eco_account/includes/controls.html:5 #: compensation/templates/compensation/detail/eco_account/includes/controls.html:5
#: ema/templates/ema/detail/includes/controls.html:5 #: ema/templates/ema/detail/includes/controls.html:5
@ -1186,7 +1218,7 @@ msgid "Recorded on"
msgstr "Verzeichnet am" msgstr "Verzeichnet am"
#: compensation/templates/compensation/detail/eco_account/includes/deductions.html:65 #: compensation/templates/compensation/detail/eco_account/includes/deductions.html:65
#: intervention/forms/modals/deduction.py:173 #: intervention/forms/modals/deduction.py:177
#: intervention/templates/intervention/detail/includes/deductions.html:60 #: intervention/templates/intervention/detail/includes/deductions.html:60
msgid "Edit Deduction" msgid "Edit Deduction"
msgstr "Abbuchung bearbeiten" msgstr "Abbuchung bearbeiten"
@ -1200,25 +1232,6 @@ msgstr "Abbuchung entfernen"
msgid "No surface deductable" msgid "No surface deductable"
msgstr "Keine Flächenmenge für Abbuchungen eingegeben. Bitte bearbeiten." msgstr "Keine Flächenmenge für Abbuchungen eingegeben. Bitte bearbeiten."
#: compensation/templates/compensation/detail/eco_account/view.html:58
#: compensation/templates/compensation/detail/eco_account/view.html:62
#: compensation/templates/compensation/detail/eco_account/view.html:66
#: compensation/templates/compensation/detail/eco_account/view.html:70
#: ema/templates/ema/detail/view.html:48 ema/templates/ema/detail/view.html:52
#: ema/templates/ema/detail/view.html:56
#: intervention/templates/intervention/detail/view.html:30
#: intervention/templates/intervention/detail/view.html:34
#: intervention/templates/intervention/detail/view.html:38
#: intervention/templates/intervention/detail/view.html:47
#: intervention/templates/intervention/detail/view.html:51
#: intervention/templates/intervention/detail/view.html:55
#: intervention/templates/intervention/detail/view.html:59
#: intervention/templates/intervention/detail/view.html:63
#: intervention/templates/intervention/detail/view.html:100
#: intervention/templates/intervention/detail/view.html:104
msgid "Missing"
msgstr "Fehlend"
#: compensation/templates/compensation/detail/eco_account/view.html:71 #: compensation/templates/compensation/detail/eco_account/view.html:71
#: ema/templates/ema/detail/view.html:57 #: ema/templates/ema/detail/view.html:57
msgid "Action handler" msgid "Action handler"
@ -1297,7 +1310,7 @@ msgstr "Ökokonto {} hinzugefügt"
msgid "Eco-Account {} edited" msgid "Eco-Account {} edited"
msgstr "Ökokonto {} bearbeitet" msgstr "Ökokonto {} bearbeitet"
#: compensation/views/eco_account/eco_account.py:263 #: compensation/views/eco_account/eco_account.py:265
msgid "Eco-account removed" msgid "Eco-account removed"
msgstr "Ökokonto entfernt" msgstr "Ökokonto entfernt"
@ -1341,7 +1354,7 @@ msgstr "EMA {} hinzugefügt"
msgid "EMA {} edited" msgid "EMA {} edited"
msgstr "EMA {} bearbeitet" msgstr "EMA {} bearbeitet"
#: ema/views/ema.py:234 #: ema/views/ema.py:235
msgid "EMA removed" msgid "EMA removed"
msgstr "EMA entfernt" msgstr "EMA entfernt"
@ -1639,19 +1652,19 @@ msgstr "Eingriff {} hinzugefügt"
msgid "Intervention {} edited" msgid "Intervention {} edited"
msgstr "Eingriff {} bearbeitet" msgstr "Eingriff {} bearbeitet"
#: intervention/views/intervention.py:249 #: intervention/views/intervention.py:250
msgid "{} removed" msgid "{} removed"
msgstr "{} entfernt" msgstr "{} entfernt"
#: konova/decorators.py:33 #: konova/decorators.py:30
msgid "You need to be staff to perform this action!" msgid "You need to be staff to perform this action!"
msgstr "Hierfür müssen Sie Mitarbeiter sein!" msgstr "Hierfür müssen Sie Mitarbeiter sein!"
#: konova/decorators.py:48 #: konova/decorators.py:45
msgid "You need to be administrator to perform this action!" msgid "You need to be administrator to perform this action!"
msgstr "Hierfür müssen Sie Administrator sein!" msgstr "Hierfür müssen Sie Administrator sein!"
#: konova/decorators.py:66 #: konova/decorators.py:63
msgid "" msgid ""
"+++ Attention: You are not part of any group. You won't be able to create, " "+++ Attention: You are not part of any group. You won't be able to create, "
"edit or do anything. Please contact an administrator. +++" "edit or do anything. Please contact an administrator. +++"
@ -2663,7 +2676,9 @@ msgstr "Keine Geometrie vorhanden"
#: templates/modal/modal_session_timed_out.html:3 #: templates/modal/modal_session_timed_out.html:3
msgid "Your session has timed out. Please reload the page to login." msgid "Your session has timed out. Please reload the page to login."
msgstr "Ihre Sitzung ist aufgrund von Inaktivität abgelaufen. Laden Sie die Seite erneut, um sich wieder einzuloggen." msgstr ""
"Ihre Sitzung ist aufgrund von Inaktivität abgelaufen. Laden Sie die Seite "
"erneut, um sich wieder einzuloggen."
#: templates/navbars/navbar.html:4 #: templates/navbars/navbar.html:4
msgid "Kompensationsverzeichnis Service Portal" msgid "Kompensationsverzeichnis Service Portal"
@ -2902,7 +2917,7 @@ msgid "Manage teams"
msgstr "" msgstr ""
#: user/templates/user/index.html:61 user/templates/user/team/index.html:19 #: user/templates/user/index.html:61 user/templates/user/team/index.html:19
#: user/views.py:169 #: user/views.py:171
msgid "Teams" msgid "Teams"
msgstr "" msgstr ""
@ -2974,23 +2989,23 @@ msgstr "Neuer Token generiert. Administratoren sind informiert."
msgid "User API token" msgid "User API token"
msgstr "API Nutzer Token" msgstr "API Nutzer Token"
#: user/views.py:180 #: user/views.py:183
msgid "New team added" msgid "New team added"
msgstr "Neues Team hinzugefügt" msgstr "Neues Team hinzugefügt"
#: user/views.py:194 #: user/views.py:198
msgid "Team edited" msgid "Team edited"
msgstr "Team bearbeitet" msgstr "Team bearbeitet"
#: user/views.py:208 #: user/views.py:213
msgid "Team removed" msgid "Team removed"
msgstr "Team gelöscht" msgstr "Team gelöscht"
#: user/views.py:222 #: user/views.py:228
msgid "You are not a member of this team" msgid "You are not a member of this team"
msgstr "Sie sind kein Mitglied dieses Teams" msgstr "Sie sind kein Mitglied dieses Teams"
#: user/views.py:229 #: user/views.py:235
msgid "Left Team" msgid "Left Team"
msgstr "Team verlassen" msgstr "Team verlassen"