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
|
||||
|
||||
Reference in New Issue
Block a user