#35 Sanity command

* refactors "toggling" of recorded/checked state
* introduces mark_as_edited() for RecordableObjectMixin
This commit is contained in:
2021-11-17 12:09:49 +01:00
parent f62dd76d94
commit 4583a9f826
11 changed files with 80 additions and 59 deletions

View File

@@ -284,6 +284,8 @@ class EditCompensationForm(NewCompensationForm):
self.instance.save()
self.instance.log.add(action)
intervention.mark_as_edited(user)
return self.instance

View File

@@ -271,6 +271,11 @@ class Compensation(AbstractCompensation, CEFMixin, CoherenceMixin):
)
return docs
def add_new_action(self, form) -> CompensationAction:
super().add_new_action(form)
self.intervention.set_as_edited(form.user)
class CompensationDocument(AbstractDocument):
"""
Specializes document upload for revocations with certain path

View File

@@ -7,6 +7,7 @@ Created on: 16.11.21
"""
import shutil
from django.contrib.auth.models import User
from django.core.exceptions import ValidationError
from django.core.validators import MinValueValidator
from django.db import models, transaction

View File

@@ -274,7 +274,7 @@ class EcoAccountWorkflowTestCase(BaseWorkflowTestCase):
# Now mock the eco account as it would be recorded (with invalid data)
# Make sure the deductible surface is high enough for the request
self.eco_account.toggle_recorded(self.superuser)
self.eco_account.set_recorded(self.superuser)
self.eco_account.refresh_from_db()
self.eco_account.deductable_surface = test_surface + 1.00
self.eco_account.save()

View File

@@ -15,7 +15,8 @@ from konova.decorators import *
from konova.forms import RemoveModalForm, SimpleGeomForm
from konova.utils.documents import get_document, remove_document
from konova.utils.generators import generate_qr_code
from konova.utils.message_templates import FORM_INVALID, IDENTIFIER_REPLACED, DATA_UNSHARED_EXPLANATION
from konova.utils.message_templates import FORM_INVALID, IDENTIFIER_REPLACED, DATA_UNSHARED_EXPLANATION, \
CHECKED_RECORDED_RESET
from konova.utils.user_checks import in_group
@@ -130,8 +131,15 @@ def edit_view(request: HttpRequest, id: str):
geom_form = SimpleGeomForm(request.POST or None, read_only=False, instance=comp)
if request.method == "POST":
if data_form.is_valid() and geom_form.is_valid():
# Preserve state of intervention recorded/checked to determine whether the user must be informed or not
# about a change of the recorded/checked state
intervention_recorded = comp.intervention.recorded is not None
intervention_checked = comp.intervention.checked is not None
# The data form takes the geom form for processing, as well as the performing user
comp = data_form.save(request.user, geom_form)
if intervention_recorded or intervention_checked:
messages.info(request, CHECKED_RECORDED_RESET)
messages.success(request, _("Compensation {} edited").format(comp.identifier))
return redirect("compensation:detail", id=comp.id)
else: