#86 Log detail enhancements
* restructures removing of related data into separate sub-delete forms for easier logic handling
This commit is contained in:
@@ -7,7 +7,7 @@ Created on: 27.09.21
|
||||
"""
|
||||
from dal import autocomplete
|
||||
|
||||
from konova.utils.message_templates import DEDUCTION_ADDED, REVOCATION_ADDED
|
||||
from konova.utils.message_templates import DEDUCTION_ADDED, REVOCATION_ADDED, DEDUCTION_REMOVED
|
||||
from user.models import User, UserActionLogEntry
|
||||
from django.db import transaction
|
||||
from django import forms
|
||||
@@ -16,7 +16,7 @@ from django.utils.translation import gettext_lazy as _
|
||||
from compensation.models import EcoAccount, EcoAccountDeduction
|
||||
from intervention.inputs import TextToClipboardInput
|
||||
from intervention.models import Intervention, InterventionDocument
|
||||
from konova.forms import BaseModalForm, NewDocumentForm
|
||||
from konova.forms import BaseModalForm, NewDocumentForm, RemoveModalForm
|
||||
from konova.utils.general import format_german_float
|
||||
from konova.utils.user_checks import is_default_group_only
|
||||
|
||||
@@ -172,6 +172,23 @@ class NewRevocationModalForm(BaseModalForm):
|
||||
return revocation
|
||||
|
||||
|
||||
class RevocationRemoveModalForm(RemoveModalForm):
|
||||
""" Removing modal form for Revocation
|
||||
|
||||
Can be used for anything, where removing shall be confirmed by the user a second time.
|
||||
|
||||
"""
|
||||
revocation = None
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
revocation = kwargs.pop("revocation", None)
|
||||
self.revocation = revocation
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
def save(self):
|
||||
self.instance.remove_revocation(self)
|
||||
|
||||
|
||||
class CheckModalForm(BaseModalForm):
|
||||
""" The modal form for running a check on interventions and their compensations
|
||||
|
||||
@@ -390,5 +407,25 @@ class NewDeductionModalForm(BaseModalForm):
|
||||
return deduction
|
||||
|
||||
|
||||
class DeductionRemoveModalForm(RemoveModalForm):
|
||||
""" Removing modal form for EcoAccountDeduction
|
||||
|
||||
Can be used for anything, where removing shall be confirmed by the user a second time.
|
||||
|
||||
"""
|
||||
deduction = None
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
deduction = kwargs.pop("deduction", None)
|
||||
self.deduction = deduction
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
def save(self):
|
||||
with transaction.atomic():
|
||||
self.deduction.intervention.mark_as_edited(self.user, edit_comment=DEDUCTION_REMOVED)
|
||||
self.deduction.account.mark_as_edited(self.user, edit_comment=DEDUCTION_REMOVED)
|
||||
self.deduction.delete()
|
||||
|
||||
|
||||
class NewInterventionDocumentForm(NewDocumentForm):
|
||||
document_model = InterventionDocument
|
||||
|
||||
@@ -16,7 +16,6 @@ from django.db import models, transaction
|
||||
from django.db.models import QuerySet
|
||||
from django.http import HttpRequest
|
||||
|
||||
from compensation.models import EcoAccountDeduction
|
||||
from intervention.managers import InterventionManager
|
||||
from intervention.models.legal import Legal
|
||||
from intervention.models.responsibility import Responsibility
|
||||
@@ -26,7 +25,8 @@ from konova.models import generate_document_file_upload_path, AbstractDocument,
|
||||
ShareableObjectMixin, \
|
||||
RecordableObjectMixin, CheckableObjectMixin, GeoReferencedMixin
|
||||
from konova.settings import LANIS_LINK_TEMPLATE, LANIS_ZOOM_LUT, DEFAULT_SRID_RLP
|
||||
from konova.utils.message_templates import DATA_UNSHARED_EXPLANATION, DEDUCTION_ADDED, DOCUMENT_REMOVED_TEMPLATE
|
||||
from konova.utils.message_templates import DATA_UNSHARED_EXPLANATION, DOCUMENT_REMOVED_TEMPLATE, \
|
||||
PAYMENT_REMOVED, PAYMENT_ADDED, REVOCATION_REMOVED
|
||||
from user.models import UserActionLogEntry
|
||||
|
||||
|
||||
@@ -196,6 +196,7 @@ class Intervention(BaseObject, ShareableObjectMixin, RecordableObjectMixin, Chec
|
||||
comment=form_data.get("comment", None),
|
||||
intervention=self,
|
||||
)
|
||||
self.mark_as_edited(user, form.request, edit_comment=PAYMENT_ADDED)
|
||||
return pay
|
||||
|
||||
def add_revocation(self, form):
|
||||
@@ -229,6 +230,21 @@ class Intervention(BaseObject, ShareableObjectMixin, RecordableObjectMixin, Chec
|
||||
)
|
||||
return revocation
|
||||
|
||||
def remove_revocation(self, form):
|
||||
""" Removes a revocation from the intervention
|
||||
|
||||
Args:
|
||||
form (RevocationRemoveModalForm): The form holding all relevant data
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
revocation = form.revocation
|
||||
user = form.user
|
||||
with transaction.atomic():
|
||||
revocation.delete()
|
||||
self.mark_as_edited(user, request=form.request, edit_comment=REVOCATION_REMOVED)
|
||||
|
||||
def mark_as_edited(self, performing_user: User, request: HttpRequest = None, edit_comment: str = None, reset_recorded: bool = True):
|
||||
""" In case the object or a related object changed, internal processes need to be started, such as
|
||||
unrecord and uncheck
|
||||
@@ -242,7 +258,7 @@ class Intervention(BaseObject, ShareableObjectMixin, RecordableObjectMixin, Chec
|
||||
Returns:
|
||||
|
||||
"""
|
||||
action = super().mark_as_edited(performing_user, edit_comment)
|
||||
action = super().mark_as_edited(performing_user, edit_comment=edit_comment)
|
||||
if reset_recorded:
|
||||
self.unrecord(performing_user, request)
|
||||
if self.checked:
|
||||
@@ -289,6 +305,21 @@ class Intervention(BaseObject, ShareableObjectMixin, RecordableObjectMixin, Chec
|
||||
"""
|
||||
return reverse("intervention:share", args=(self.id, self.access_token))
|
||||
|
||||
def remove_payment(self, form):
|
||||
""" Removes a Payment from the intervention
|
||||
|
||||
Args:
|
||||
form (PaymentRemoveModalForm): The form holding all relevant data
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
payment = form.payment
|
||||
user = form.user
|
||||
with transaction.atomic():
|
||||
payment.delete()
|
||||
self.mark_as_edited(user, request=form.request, edit_comment=PAYMENT_REMOVED)
|
||||
|
||||
|
||||
class InterventionDocument(AbstractDocument):
|
||||
"""
|
||||
|
||||
@@ -23,7 +23,7 @@ class Revocation(BaseResource):
|
||||
legal = models.ForeignKey("Legal", null=False, blank=False, on_delete=models.CASCADE, help_text="Refers to 'Widerspruch am'", related_name="revocations")
|
||||
comment = models.TextField(null=True, blank=True)
|
||||
|
||||
def delete(self, user=None, *args, **kwargs):
|
||||
def delete(self, *args, **kwargs):
|
||||
# Make sure related objects are being removed as well
|
||||
try:
|
||||
self.document.delete(*args, **kwargs)
|
||||
@@ -31,9 +31,6 @@ class Revocation(BaseResource):
|
||||
# No file to delete
|
||||
pass
|
||||
|
||||
if user is not None:
|
||||
self.legal.intervention.mark_as_edited(user, edit_comment=REVOCATION_REMOVED)
|
||||
|
||||
super().delete()
|
||||
|
||||
@property
|
||||
|
||||
@@ -56,7 +56,7 @@
|
||||
</td>
|
||||
<td class="align-middle">
|
||||
{% if is_default_member and has_access %}
|
||||
<button data-form-url="{% url 'compensation:pay:remove' pay.id %}" class="btn btn-default btn-modal float-right" title="{% trans 'Remove payment' %}">
|
||||
<button data-form-url="{% url 'compensation:pay:remove' obj.id pay.id %}" class="btn btn-default btn-modal float-right" title="{% trans 'Remove payment' %}">
|
||||
{% fa5_icon 'trash' %}
|
||||
</button>
|
||||
{% endif %}
|
||||
|
||||
@@ -65,7 +65,7 @@
|
||||
</td>
|
||||
<td class="align-middle">
|
||||
{% if is_default_member and has_access %}
|
||||
<button data-form-url="{% url 'intervention:remove-revocation' rev.id %}" class="btn btn-default btn-modal float-right" title="{% trans 'Remove revocation' %}">
|
||||
<button data-form-url="{% url 'intervention:remove-revocation' obj.id rev.id %}" class="btn btn-default btn-modal float-right" title="{% trans 'Remove revocation' %}">
|
||||
{% fa5_icon 'trash' %}
|
||||
</button>
|
||||
{% endif %}
|
||||
|
||||
@@ -262,7 +262,7 @@ class InterventionWorkflowTestCase(BaseWorkflowTestCase):
|
||||
pre_payment_logs_count = self.intervention.log.count()
|
||||
|
||||
# Create removing url for the payment
|
||||
remove_url = reverse("compensation:pay:remove", args=(payment.id,))
|
||||
remove_url = reverse("compensation:pay:remove", args=(self.intervention.id, payment.id,))
|
||||
post_data = {
|
||||
"confirm": True,
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ urlpatterns = [
|
||||
path('<id>/report', report_view, name='report'),
|
||||
|
||||
# Compensations
|
||||
path('<id>/remove/<comp_id>', remove_compensation_view, name='remove-compensation'),
|
||||
path('<id>/compensation/<comp_id>/remove', remove_compensation_view, name='remove-compensation'),
|
||||
|
||||
# Documents
|
||||
path('<id>/document/new/', new_document_view, name='new-doc'),
|
||||
@@ -37,10 +37,10 @@ urlpatterns = [
|
||||
|
||||
# Deductions
|
||||
path('<id>/deduction/new', new_deduction_view, name='new-deduction'),
|
||||
path('<id>/remove/<deduction_id>', remove_deduction_view, name='remove-deduction'),
|
||||
path('<id>/deduction/<deduction_id>/remove', remove_deduction_view, name='remove-deduction'),
|
||||
|
||||
# Revocation routes
|
||||
path('<id>/revocation/new', new_revocation_view, name='new-revocation'),
|
||||
path('revocation/<id>/remove', remove_revocation_view, name='remove-revocation'),
|
||||
path('<id>/revocation/<revocation_id>/remove', remove_revocation_view, name='remove-revocation'),
|
||||
path('revocation/<doc_id>', get_revocation_view, name='get-doc-revocation'),
|
||||
]
|
||||
@@ -6,7 +6,8 @@ from django.shortcuts import render
|
||||
|
||||
from intervention.forms.forms import NewInterventionForm, EditInterventionForm
|
||||
from intervention.forms.modalForms import ShareModalForm, NewRevocationModalForm, \
|
||||
CheckModalForm, NewDeductionModalForm, NewInterventionDocumentForm
|
||||
CheckModalForm, NewDeductionModalForm, NewInterventionDocumentForm, DeductionRemoveModalForm, \
|
||||
RevocationRemoveModalForm
|
||||
from intervention.models import Intervention, Revocation, InterventionDocument, RevocationDocument
|
||||
from intervention.tables import InterventionTable
|
||||
from konova.contexts import BaseContext
|
||||
@@ -340,7 +341,7 @@ def remove_view(request: HttpRequest, id: str):
|
||||
|
||||
@login_required
|
||||
@default_group_required
|
||||
def remove_revocation_view(request: HttpRequest, id: str):
|
||||
def remove_revocation_view(request: HttpRequest, id: str, revocation_id: str):
|
||||
""" Renders a remove view for a revocation
|
||||
|
||||
Args:
|
||||
@@ -350,13 +351,14 @@ def remove_revocation_view(request: HttpRequest, id: str):
|
||||
Returns:
|
||||
|
||||
"""
|
||||
obj = Revocation.objects.get(id=id)
|
||||
intervention = get_object_or_404(Intervention, id=id)
|
||||
revocation = get_object_or_404(Revocation, id=revocation_id)
|
||||
|
||||
form = RemoveModalForm(request.POST or None, instance=obj, request=request)
|
||||
form = RevocationRemoveModalForm(request.POST or None, instance=intervention, revocation=revocation, request=request)
|
||||
return form.process_request(
|
||||
request,
|
||||
REVOCATION_REMOVED,
|
||||
redirect_url=reverse("intervention:detail", args=(obj.intervention.id,)) + "#related_data"
|
||||
redirect_url=reverse("intervention:detail", args=(intervention.id,)) + "#related_data"
|
||||
)
|
||||
|
||||
|
||||
@@ -533,7 +535,7 @@ def remove_deduction_view(request: HttpRequest, id: str, deduction_id: str):
|
||||
except ObjectDoesNotExist:
|
||||
raise Http404("Unknown deduction")
|
||||
|
||||
form = RemoveModalForm(request.POST or None, instance=eco_deduction, request=request)
|
||||
form = DeductionRemoveModalForm(request.POST or None, instance=intervention, deduction=eco_deduction, request=request)
|
||||
return form.process_request(
|
||||
request=request,
|
||||
msg_success=DEDUCTION_REMOVED,
|
||||
|
||||
Reference in New Issue
Block a user