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:
@@ -14,6 +14,7 @@ from compensation.forms.mixins import CompensationResponsibleFormMixin, PikCompe
|
||||
from compensation.models import EcoAccount
|
||||
from intervention.models import Handler, Responsibility, Legal
|
||||
from konova.forms import SimpleGeomForm
|
||||
from konova.forms.modals import RemoveModalForm
|
||||
from user.models import User, UserActionLogEntry
|
||||
|
||||
|
||||
@@ -210,3 +211,16 @@ class EditEcoAccountForm(NewEcoAccountForm):
|
||||
# Add the log entry to the main objects log list
|
||||
self.instance.log.add(action)
|
||||
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
|
||||
|
||||
@@ -13,13 +13,12 @@ from django.shortcuts import get_object_or_404, redirect, render
|
||||
from django.urls import reverse
|
||||
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.tables.eco_account import EcoAccountTable
|
||||
from konova.contexts import BaseContext
|
||||
from konova.decorators import shared_access_required, default_group_required, any_group_check, login_required_modal
|
||||
from konova.forms import SimpleGeomForm
|
||||
from konova.forms.modals import RemoveModalForm
|
||||
from konova.settings import ETS_GROUP, DEFAULT_GROUP, ZB_GROUP
|
||||
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, \
|
||||
@@ -260,7 +259,7 @@ def remove_view(request: HttpRequest, id: str):
|
||||
messages.info(request, CANCEL_ACC_RECORDED_OR_DEDUCTED)
|
||||
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(
|
||||
request=request,
|
||||
msg_success=_("Eco-account removed"),
|
||||
|
||||
Reference in New Issue
Block a user