# 86 Proper log detail
* adds support for payment adding/deleting to intervention log * adds support for deduction adding/deleting to intervention/ecoaccount log * improves code snippets * drops add_deduction() methods for ecoaccount and intervention in favor of simpler creation in NewDeductionModalForm * adds messages * adds/updates translations
This commit is contained in:
@@ -7,6 +7,8 @@ Created on: 02.12.20
|
||||
"""
|
||||
from dal import autocomplete
|
||||
from django import forms
|
||||
|
||||
from konova.utils.message_templates import EDITED_GENERAL_DATA
|
||||
from user.models import User
|
||||
from django.db import transaction
|
||||
from django.urls import reverse, reverse_lazy
|
||||
@@ -333,7 +335,7 @@ class EditInterventionForm(NewInterventionForm):
|
||||
self.instance.responsible.conservation_file_number = conservation_file_number
|
||||
self.instance.responsible.save()
|
||||
|
||||
user_action = UserActionLogEntry.get_edited_action(user)
|
||||
user_action = self.instance.mark_as_edited(user, edit_comment=EDITED_GENERAL_DATA)
|
||||
|
||||
geometry = geom_form.save(user_action)
|
||||
self.instance.geometry = geometry
|
||||
@@ -347,8 +349,5 @@ class EditInterventionForm(NewInterventionForm):
|
||||
self.instance.modified = user_action
|
||||
self.instance.save()
|
||||
|
||||
# Uncheck and unrecord intervention due to changed data
|
||||
self.instance.mark_as_edited(user)
|
||||
|
||||
return self.instance
|
||||
|
||||
|
||||
@@ -6,13 +6,14 @@ Created on: 27.09.21
|
||||
|
||||
"""
|
||||
from dal import autocomplete
|
||||
from user.models import User
|
||||
|
||||
from konova.utils.message_templates import DEDUCTION_ADDED
|
||||
from user.models import User, UserActionLogEntry
|
||||
from django.db import transaction
|
||||
from django import forms
|
||||
from django.urls import reverse
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from compensation.models import EcoAccount
|
||||
from compensation.models import EcoAccount, EcoAccountDeduction
|
||||
from intervention.inputs import TextToClipboardInput
|
||||
from intervention.models import Intervention, InterventionDocument
|
||||
from konova.forms import BaseModalForm, NewDocumentForm
|
||||
@@ -366,9 +367,26 @@ class NewDeductionModalForm(BaseModalForm):
|
||||
)
|
||||
return is_valid_surface and super_result
|
||||
|
||||
def __create_deduction(self):
|
||||
""" Creates the deduction
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
with transaction.atomic():
|
||||
user_action_create = UserActionLogEntry.get_created_action(self.user)
|
||||
deduction = EcoAccountDeduction.objects.create(
|
||||
intervention=self.cleaned_data["intervention"],
|
||||
account=self.cleaned_data["account"],
|
||||
surface=self.cleaned_data["surface"],
|
||||
created=user_action_create,
|
||||
)
|
||||
return deduction
|
||||
|
||||
def save(self):
|
||||
deduction = self.instance.add_deduction(self)
|
||||
self.instance.mark_as_edited(self.user, self.request, reset_recorded=False)
|
||||
deduction = self.__create_deduction()
|
||||
self.cleaned_data["intervention"].mark_as_edited(self.user, edit_comment=DEDUCTION_ADDED)
|
||||
self.cleaned_data["account"].mark_as_edited(self.user, edit_comment=DEDUCTION_ADDED, reset_recorded=False)
|
||||
return deduction
|
||||
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ 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
|
||||
from konova.utils.message_templates import DATA_UNSHARED_EXPLANATION, DEDUCTION_ADDED
|
||||
from user.models import UserActionLogEntry
|
||||
|
||||
|
||||
@@ -229,28 +229,6 @@ class Intervention(BaseObject, ShareableObjectMixin, RecordableObjectMixin, Chec
|
||||
)
|
||||
return revocation
|
||||
|
||||
def add_deduction(self, form):
|
||||
""" Adds a new deduction to the intervention
|
||||
|
||||
Args:
|
||||
form (NewDeductionModalForm): The form holding the data
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
form_data = form.cleaned_data
|
||||
user = form.user
|
||||
|
||||
with transaction.atomic():
|
||||
user_action_create = UserActionLogEntry.get_created_action(user)
|
||||
deduction = EcoAccountDeduction.objects.create(
|
||||
intervention=self,
|
||||
account=form_data["account"],
|
||||
surface=form_data["surface"],
|
||||
created=user_action_create,
|
||||
)
|
||||
return deduction
|
||||
|
||||
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
|
||||
@@ -264,9 +242,10 @@ class Intervention(BaseObject, ShareableObjectMixin, RecordableObjectMixin, Chec
|
||||
Returns:
|
||||
|
||||
"""
|
||||
super().mark_as_edited(performing_user, request, edit_comment, reset_recorded)
|
||||
action = super().mark_as_edited(performing_user, request, edit_comment, reset_recorded)
|
||||
if self.checked:
|
||||
self.set_unchecked()
|
||||
return action
|
||||
|
||||
def set_status_messages(self, request: HttpRequest):
|
||||
""" Setter for different information that need to be rendered
|
||||
|
||||
@@ -57,7 +57,7 @@
|
||||
<td class="align-middle">{{ deduction.created.timestamp|default_if_none:""|naturalday}}</td>
|
||||
<td>
|
||||
{% if is_default_member and has_access %}
|
||||
<button data-form-url="{% url 'compensation:acc:remove-deduction' deduction.account.id deduction.id %}" class="btn btn-default btn-modal float-right" title="{% trans 'Remove Deduction' %}">
|
||||
<button data-form-url="{% url 'intervention:remove-deduction' obj.id deduction.id %}" class="btn btn-default btn-modal float-right" title="{% trans 'Remove Deduction' %}">
|
||||
{% fa5_icon 'trash' %}
|
||||
</button>
|
||||
{% endif %}
|
||||
|
||||
@@ -9,7 +9,8 @@ from django.urls import path
|
||||
|
||||
from intervention.views import index_view, new_view, detail_view, edit_view, remove_view, new_document_view, share_view, \
|
||||
create_share_view, remove_revocation_view, new_revocation_view, check_view, log_view, new_deduction_view, \
|
||||
record_view, remove_document_view, get_document_view, get_revocation_view, new_id_view, report_view
|
||||
record_view, remove_document_view, get_document_view, get_revocation_view, new_id_view, report_view, \
|
||||
remove_deduction_view
|
||||
|
||||
app_name = "intervention"
|
||||
urlpatterns = [
|
||||
@@ -33,6 +34,7 @@ urlpatterns = [
|
||||
|
||||
# Deductions
|
||||
path('<id>/deduction/new', new_deduction_view, name='new-deduction'),
|
||||
path('<id>/remove/<deduction_id>', remove_deduction_view, name='remove-deduction'),
|
||||
|
||||
# Revocation routes
|
||||
path('<id>/revocation/new', new_revocation_view, name='new-revocation'),
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.core.exceptions import ObjectDoesNotExist
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.http import HttpRequest, JsonResponse
|
||||
from django.http import HttpRequest, JsonResponse, Http404
|
||||
from django.shortcuts import render
|
||||
|
||||
from intervention.forms.forms import NewInterventionForm, EditInterventionForm
|
||||
@@ -15,7 +16,7 @@ from konova.sub_settings.context_settings import TAB_TITLE_IDENTIFIER
|
||||
from konova.utils.documents import remove_document, get_document
|
||||
from konova.utils.generators import generate_qr_code
|
||||
from konova.utils.message_templates import INTERVENTION_INVALID, FORM_INVALID, IDENTIFIER_REPLACED, \
|
||||
CHECKED_RECORDED_RESET
|
||||
CHECKED_RECORDED_RESET, DEDUCTION_REMOVED, DEDUCTION_ADDED
|
||||
from konova.utils.user_checks import in_group
|
||||
|
||||
|
||||
@@ -506,11 +507,39 @@ def new_deduction_view(request: HttpRequest, id: str):
|
||||
form = NewDeductionModalForm(request.POST or None, instance=intervention, request=request)
|
||||
return form.process_request(
|
||||
request,
|
||||
msg_success=_("Deduction added"),
|
||||
msg_success=DEDUCTION_ADDED,
|
||||
redirect_url=reverse("intervention:detail", args=(id,)) + "#related_data",
|
||||
)
|
||||
|
||||
|
||||
@login_required
|
||||
@default_group_required
|
||||
@shared_access_required(Intervention, "id")
|
||||
def remove_deduction_view(request: HttpRequest, id: str, deduction_id: str):
|
||||
""" Renders a modal view for removing deductions
|
||||
|
||||
Args:
|
||||
request (HttpRequest): The incoming request
|
||||
id (str): The intervention's id
|
||||
deduction_id (str): The deduction's id
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
intervention = get_object_or_404(Intervention, id=id)
|
||||
try:
|
||||
eco_deduction = intervention.deductions.get(id=deduction_id)
|
||||
except ObjectDoesNotExist:
|
||||
raise Http404("Unknown deduction")
|
||||
|
||||
form = RemoveModalForm(request.POST or None, instance=eco_deduction, request=request)
|
||||
return form.process_request(
|
||||
request=request,
|
||||
msg_success=DEDUCTION_REMOVED,
|
||||
redirect_url=reverse("intervention:detail", args=(id,)) + "#related_data"
|
||||
)
|
||||
|
||||
|
||||
@login_required
|
||||
@conservation_office_group_required
|
||||
@shared_access_required(Intervention, "id")
|
||||
|
||||
Reference in New Issue
Block a user